_Declaration.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Generated by CoffeeScript 1.9.3
  2. var _Declaration;
  3. module.exports = _Declaration = (function() {
  4. var self;
  5. self = _Declaration;
  6. _Declaration.importantClauseRx = /(\s\!important)$/;
  7. _Declaration.setOnto = function(declarations, prop, val) {
  8. var dec;
  9. if (!(dec = declarations[prop])) {
  10. return declarations[prop] = new this(prop, val);
  11. } else {
  12. return dec.set(val);
  13. }
  14. };
  15. _Declaration.sanitizeValue = function(val) {
  16. return String(val).trim().replace(/[\s]+/g, ' ');
  17. };
  18. _Declaration.inheritAllowed = false;
  19. function _Declaration(prop1, val) {
  20. this.prop = prop1;
  21. this.important = false;
  22. this.set(val);
  23. }
  24. _Declaration.prototype.get = function() {
  25. return this._get();
  26. };
  27. _Declaration.prototype._get = function() {
  28. return this.val;
  29. };
  30. _Declaration.prototype._pickImportantClause = function(val) {
  31. if (self.importantClauseRx.test(String(val))) {
  32. this.important = true;
  33. return val.replace(self.importantClauseRx, '');
  34. } else {
  35. this.important = false;
  36. return val;
  37. }
  38. };
  39. _Declaration.prototype.set = function(val) {
  40. val = self.sanitizeValue(val);
  41. val = this._pickImportantClause(val);
  42. val = val.trim();
  43. if (this._handleNullOrInherit(val)) {
  44. return this;
  45. }
  46. this._set(val);
  47. return this;
  48. };
  49. _Declaration.prototype._set = function(val) {
  50. return this.val = val;
  51. };
  52. _Declaration.prototype._handleNullOrInherit = function(val) {
  53. if (val === '') {
  54. this.val = '';
  55. return true;
  56. }
  57. if (val === 'inherit') {
  58. if (this.constructor.inheritAllowed) {
  59. this.val = 'inherit';
  60. } else {
  61. throw Error("Inherit is not allowed for `" + this.prop + "`");
  62. }
  63. return true;
  64. } else {
  65. return false;
  66. }
  67. };
  68. return _Declaration;
  69. })();