diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a21d6eb --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.jade text eol=lf +*.html text eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore index bf491f1..80fd45c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ attic node_modules .c9/ temp +.idea/ +*.iml +*.js.map diff --git a/.travis.yml b/.travis.yml index 55837a1..4064c1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: node_js node_js: - - "0.10" + - "v5.1.1" diff --git a/lib/html2jade.coffee b/lib/html2jade.coffee index 0b37b4c..a70b640 100755 --- a/lib/html2jade.coffee +++ b/lib/html2jade.coffee @@ -207,6 +207,8 @@ class Converter @writer = @options.writer ? new Writer(@options) document: (document, output) -> + + if document.doctype? doctype = document.doctype docTypeName = undefined @@ -219,6 +221,10 @@ class Converter else if doctype.name? and doctype.name.toLowerCase() is 'html' docTypeName = 'html' if docTypeName? + output.writeln 'mixin bbr()' + output.writeln ' | ' + output.writeln ' |
' + output.writeln '' output.writeln 'doctype ' + docTypeName if document.documentElement @@ -250,6 +256,8 @@ class Converter else if tagName is 'conditional' output.writeln '//' + node.getAttribute('condition') @children node, output + else if tagName is 'br' + output.writeln '+bbr()' else if ['pre'].indexOf(tagName) isnt -1 # HACK: workaround jade's wonky PRE handling output.writeln tagHead + tagAttr + '.' diff --git a/lib/html2jade.js b/lib/html2jade.js index 831f045..c02a674 100644 --- a/lib/html2jade.js +++ b/lib/html2jade.js @@ -1,8 +1,8 @@ -// Generated by CoffeeScript 1.6.3 +// Generated by CoffeeScript 1.10.0 (function() { var Converter, Ent, FS, Output, Parser, Path, StreamOutput, StringOutput, Writer, applyOptions, doNotEncode, entOptions, isNode, isValidJadeClassName, isValidJadeId, nspaces, publicIdDocTypeNames, scope, systemIdDocTypeNames, useTabs, validJadeClassRegExp, validJadeIdRegExp, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; isNode = false; @@ -36,8 +36,8 @@ validJadeClassRegExp = /^[\w\-]+$/; Parser = (function() { - function Parser(options) { - this.options = options != null ? options : {}; + function Parser(options1) { + this.options = options1 != null ? options1 : {}; if (isNode) { this.jsdom = require('jsdom-little'); } @@ -78,12 +78,12 @@ Writer = (function() { function Writer(options) { - var _ref, _ref1, _ref2; + var ref, ref1, ref2; if (options == null) { options = {}; } - this.wrapLength = (_ref = options.wrapLength) != null ? _ref : 80; - this.scalate = (_ref1 = options.scalate) != null ? _ref1 : false; + this.wrapLength = (ref = options.wrapLength) != null ? ref : 80; + this.scalate = (ref1 = options.scalate) != null ? ref1 : false; this.attrSep = this.scalate || options.noattrcomma ? ' ' : ', '; if (options.double) { this.attrQuote = '"'; @@ -93,7 +93,7 @@ this.nonAttrQuote = '"'; } this.attrQuoteEscaped = "\\" + this.attrQuote; - this.noEmptyPipe = (_ref2 = options.noemptypipe) != null ? _ref2 : false; + this.noEmptyPipe = (ref2 = options.noemptypipe) != null ? ref2 : false; } Writer.prototype.tagHead = function(node) { @@ -115,7 +115,7 @@ }; Writer.prototype.tagAttr = function(node, indents) { - var attr, attrName, attrValue, attrs, invalidClassNames, result, _i, _len; + var attr, attrName, attrValue, attrs, invalidClassNames, j, len, result; if (indents == null) { indents = ''; } @@ -124,8 +124,8 @@ return ''; } else { result = []; - for (_i = 0, _len = attrs.length; _i < _len; _i++) { - attr = attrs[_i]; + for (j = 0, len = attrs.length; j < len; j++) { + attr = attrs[j]; if (attr && attr.nodeName) { attrName = attr.nodeName; attrValue = attr.nodeValue; @@ -164,8 +164,8 @@ }; Writer.prototype.tagText = function(node) { - var data, _ref; - if (((_ref = node.firstChild) != null ? _ref.nodeType : void 0) !== 3) { + var data, ref; + if (((ref = node.firstChild) != null ? ref.nodeType : void 0) !== 3) { return null; } else if (node.firstChild !== node.lastChild) { return null; @@ -180,60 +180,61 @@ }; Writer.prototype.forEachChild = function(parent, cb) { - var child, _results; + var child, results; if (parent) { child = parent.firstChild; - _results = []; + results = []; while (child) { cb(child); - _results.push(child = child.nextSibling); + results.push(child = child.nextSibling); } - return _results; + return results; } }; Writer.prototype.writeTextContent = function(node, output, options) { - var _this = this; output.enter(); - this.forEachChild(node, function(child) { - return _this.writeText(child, output, options); - }); + this.forEachChild(node, (function(_this) { + return function(child) { + return _this.writeText(child, output, options); + }; + })(this)); return output.leave(); }; Writer.prototype.writeText = function(node, output, options) { - var data, lines, - _this = this; + var data, lines; if (node.nodeType === 3) { data = node.data || ''; if (data.length > 0) { lines = data.split(/\r|\n/); - return lines.forEach(function(line) { - return _this.writeTextLine(node, line, output, options); - }); + return lines.forEach((function(_this) { + return function(line) { + return _this.writeTextLine(node, line, output, options); + }; + })(this)); } } }; Writer.prototype.writeTextLine = function(node, line, output, options) { - var encodeEntityRef, escapeBackslash, lines, pipe, prefix, trim, wrap, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, - _this = this; + var encodeEntityRef, escapeBackslash, lines, pipe, prefix, ref, ref1, ref2, ref3, ref4, ref5, ref6, trim, wrap; if (options == null) { options = {}; } - pipe = (_ref = options.pipe) != null ? _ref : true; - trim = (_ref1 = options.trim) != null ? _ref1 : false; - wrap = (_ref2 = options.wrap) != null ? _ref2 : true; - encodeEntityRef = (_ref3 = options.encodeEntityRef) != null ? _ref3 : false; - escapeBackslash = (_ref4 = options.escapeBackslash) != null ? _ref4 : false; + pipe = (ref = options.pipe) != null ? ref : true; + trim = (ref1 = options.trim) != null ? ref1 : false; + wrap = (ref2 = options.wrap) != null ? ref2 : true; + encodeEntityRef = (ref3 = options.encodeEntityRef) != null ? ref3 : false; + escapeBackslash = (ref4 = options.escapeBackslash) != null ? ref4 : false; if (pipe && this.noEmptyPipe && line.trim().length === 0) { return; } prefix = pipe ? '| ' : ''; - if ((node != null ? (_ref5 = node.previousSibling) != null ? _ref5.nodeType : void 0 : void 0) !== 1) { + if ((node != null ? (ref5 = node.previousSibling) != null ? ref5.nodeType : void 0 : void 0) !== 1) { line = line.trimLeft(); } - if ((node != null ? (_ref6 = node.nextSibling) != null ? _ref6.nodeType : void 0 : void 0) !== 1) { + if ((node != null ? (ref6 = node.nextSibling) != null ? ref6.nodeType : void 0 : void 0) !== 1) { line = line.trimRight(); } if (line) { @@ -250,9 +251,11 @@ if (lines.length === 1) { return output.writeln(prefix + line); } else { - return lines.forEach(function(line) { - return _this.writeTextLine(node, line, output, options); - }); + return lines.forEach((function(_this) { + return function(line) { + return _this.writeTextLine(node, line, output, options); + }; + })(this)); } } } @@ -309,11 +312,11 @@ }; Converter = (function() { - function Converter(options) { - var _ref, _ref1; - this.options = options != null ? options : {}; - this.scalate = (_ref = this.options.scalate) != null ? _ref : false; - this.writer = (_ref1 = this.options.writer) != null ? _ref1 : new Writer(this.options); + function Converter(options1) { + var ref, ref1; + this.options = options1 != null ? options1 : {}; + this.scalate = (ref = this.options.scalate) != null ? ref : false; + this.writer = (ref1 = this.options.writer) != null ? ref1 : new Writer(this.options); } Converter.prototype.document = function(document, output) { @@ -331,6 +334,10 @@ docTypeName = 'html'; } if (docTypeName != null) { + output.writeln('mixin bbr()'); + output.writeln(' | '); + output.writeln(' |
'); + output.writeln(''); output.writeln('doctype ' + docTypeName); } } @@ -345,8 +352,7 @@ }; Converter.prototype.element = function(node, output) { - var firstline, tagAttr, tagHead, tagName, tagText, - _this = this; + var firstline, tagAttr, tagHead, tagName, tagText; if (!(node != null ? node.tagName : void 0)) { return; } @@ -369,28 +375,32 @@ } else if (tagName === 'conditional') { output.writeln('//' + node.getAttribute('condition')); return this.children(node, output); + } else if (tagName === 'br') { + return output.writeln('+bbr()'); } else if (['pre'].indexOf(tagName) !== -1) { output.writeln(tagHead + tagAttr + '.'); output.enter(); firstline = true; - this.writer.forEachChild(node, function(child) { - var data; - if (child.nodeType === 3) { - data = child.data; - if ((data != null) && data.length > 0) { - if (firstline) { - if (data.search(/\r\n|\r|\n/) === 0) { - data = data.replace(/\r\n|\r|\n/, ''); + this.writer.forEachChild(node, (function(_this) { + return function(child) { + var data; + if (child.nodeType === 3) { + data = child.data; + if ((data != null) && data.length > 0) { + if (firstline) { + if (data.search(/\r\n|\r|\n/) === 0) { + data = data.replace(/\r\n|\r|\n/, ''); + } + data = '\\n' + data; + firstline = false; } - data = '\\n' + data; - firstline = false; + data = data.replace(/\t/g, '\\t'); + data = data.replace(/\r\n|\r|\n/g, '\n' + output.indents); + return output.write(data); } - data = data.replace(/\t/g, '\\t'); - data = data.replace(/\r\n|\r|\n/g, '\n' + output.indents); - return output.write(data); } - } - }); + }; + })(this)); output.writeln(); return output.leave(); } else if (this.options.bodyless && (tagName === 'html' || tagName === 'body')) { @@ -408,35 +418,36 @@ }; Converter.prototype.children = function(parent, output, indent) { - var _this = this; if (indent == null) { indent = true; } if (indent) { output.enter(); } - this.writer.forEachChild(parent, function(child) { - var nodeType; - nodeType = child.nodeType; - if (nodeType === 1) { - return _this.element(child, output); - } else if (nodeType === 3) { - if (parent._nodeName === 'code') { - return _this.text(child, output, { - encodeEntityRef: true, - pipe: true - }); - } else { - return _this.text(child, output, doNotEncode ? { - encodeEntityRef: false - } : { - encodeEntityRef: true - }); + this.writer.forEachChild(parent, (function(_this) { + return function(child) { + var nodeType; + nodeType = child.nodeType; + if (nodeType === 1) { + return _this.element(child, output); + } else if (nodeType === 3) { + if (parent._nodeName === 'code') { + return _this.text(child, output, { + encodeEntityRef: true, + pipe: true + }); + } else { + return _this.text(child, output, doNotEncode ? { + encodeEntityRef: false + } : { + encodeEntityRef: true + }); + } + } else if (nodeType === 8) { + return _this.comment(child, output); } - } else if (nodeType === 8) { - return _this.comment(child, output); - } - }); + }; + })(this)); if (indent) { return output.leave(); } @@ -448,8 +459,7 @@ }; Converter.prototype.comment = function(node, output) { - var condition, data, lines, - _this = this; + var condition, data, lines; condition = node.data.match(/\s*\[(if\s+[^\]]+)\]/); if (!condition) { data = node.data || ''; @@ -459,13 +469,15 @@ output.writeln('//'); output.enter(); lines = data.split(/\r|\n/); - lines.forEach(function(line) { - return _this.writer.writeTextLine(node, line, output, { - pipe: false, - trim: true, - wrap: false - }); - }); + lines.forEach((function(_this) { + return function(line) { + return _this.writer.writeTextLine(node, line, output, { + pipe: false, + trim: true, + wrap: false + }); + }; + })(this)); return output.leave(); } } else { @@ -533,15 +545,15 @@ } Output.prototype.enter = function() { - var i, _i, _results; + var i, j, ref, results; if (useTabs) { return this.indents += '\t'; } else { - _results = []; - for (i = _i = 1; 1 <= nspaces ? _i <= nspaces : _i >= nspaces; i = 1 <= nspaces ? ++_i : --_i) { - _results.push(this.indents += ' '); + results = []; + for (i = j = 1, ref = nspaces; 1 <= ref ? j <= ref : j >= ref; i = 1 <= ref ? ++j : --j) { + results.push(this.indents += ' '); } - return _results; + return results; } }; @@ -569,8 +581,8 @@ })(); - StringOutput = (function(_super) { - __extends(StringOutput, _super); + StringOutput = (function(superClass) { + extend(StringOutput, superClass); function StringOutput() { StringOutput.__super__.constructor.apply(this, arguments); @@ -616,8 +628,8 @@ })(Output); - StreamOutput = (function(_super) { - __extends(StreamOutput, _super); + StreamOutput = (function(superClass) { + extend(StreamOutput, superClass); function StreamOutput(stream) { this.stream = stream; @@ -713,11 +725,11 @@ options.parser = new Parser(options); } return options.parser.parse(html, function(errors, window) { - var output, _ref; + var output, ref; if (errors != null ? errors.length : void 0) { return errors; } else { - output = (_ref = options.output) != null ? _ref : new StringOutput(); + output = (ref = options.output) != null ? ref : new StringOutput(); if (options.converter == null) { options.converter = new Converter(options); } @@ -730,12 +742,12 @@ }; scope.convertDocument = function(document, options, cb) { - var output, _ref; + var output, ref; if (options == null) { options = {}; } applyOptions(options); - output = (_ref = options.output) != null ? _ref : new StringOutput(); + output = (ref = options.output) != null ? ref : new StringOutput(); if (options.converter == null) { options.converter = new Converter(options); } @@ -746,3 +758,5 @@ }; }).call(this); + +//# sourceMappingURL=html2jade.js.map diff --git a/package.json b/package.json index 4132355..a0367f8 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "devDependencies": { "async": "*", "mocha": "*", - "coffee-script": "~1.6.3" + "coffee-script": "~1.10.0" }, "engines": { "node": ">= 0.4.0" diff --git a/test/data/breakline.html b/test/data/breakline.html new file mode 100644 index 0000000..8b8af19 --- /dev/null +++ b/test/data/breakline.html @@ -0,0 +1,9 @@ + + + + +

Hi

+
+

Done

+ + \ No newline at end of file diff --git a/test/data/breakline.jade b/test/data/breakline.jade new file mode 100644 index 0000000..35cd5e0 --- /dev/null +++ b/test/data/breakline.jade @@ -0,0 +1,14 @@ +mixin bbr() + | + |
+ +doctype html +html + head + | + body + p Hi + | + +bbr() + | + p Done diff --git a/test/data/conditional2.jade b/test/data/conditional2.jade index 53fa109..5eb210c 100644 --- a/test/data/conditional2.jade +++ b/test/data/conditional2.jade @@ -1,3 +1,7 @@ +mixin bbr() + | + |
+ doctype html // paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ //if lt IE 7 @@ -119,17 +123,17 @@ html.no-js(lang='en') ul.disc li a(href='http://foundation.zurb.com/docs') Foundation Documentation - br + +bbr() | Everything you need to know about using the framework. | li a(href='http://github.com/zurb/foundation') Foundation on Github - br + +bbr() | Latest code, issue reports, feature requests and more. | li a(href='http://twitter.com/foundationzurb') @foundationzurb - br + +bbr() | Ping us on Twitter if you have questions. If you build something with this we'd love to see it (and send you a totally boss sticker). // Included JS Files script(src='vendor/assets/javascripts/foundation/jquery.js') diff --git a/test/data/conditional3.jade b/test/data/conditional3.jade index 9acd89c..e03ac91 100644 --- a/test/data/conditional3.jade +++ b/test/data/conditional3.jade @@ -1,3 +1,7 @@ +mixin bbr() + | + |
+ doctype html //if lt IE 7 html.no-js.lt-ie9.lt-ie8.lt-ie7 diff --git a/test/data/html5boilerplate.html b/test/data/html5boilerplate.html old mode 100755 new mode 100644 diff --git a/test/data/html5boilerplate.jade b/test/data/html5boilerplate.jade index 1d01242..f412869 100644 --- a/test/data/html5boilerplate.jade +++ b/test/data/html5boilerplate.jade @@ -1,3 +1,7 @@ +mixin bbr() + | + |
+ doctype html //if lt IE 7 html.no-js.ie6.oldie(lang='en') diff --git a/test/data/pre1.jade b/test/data/pre1.jade index bc63f3f..cb44d49 100644 --- a/test/data/pre1.jade +++ b/test/data/pre1.jade @@ -1,3 +1,7 @@ +mixin bbr() + | + |
+ doctype html html head diff --git a/test/data/pre2.jade b/test/data/pre2.jade index 9300ff9..b4bf01d 100644 --- a/test/data/pre2.jade +++ b/test/data/pre2.jade @@ -1,3 +1,7 @@ +mixin bbr() + | + |
+ doctype html html head diff --git a/test/data/pre3.jade b/test/data/pre3.jade index edaa5d1..50e7a00 100644 --- a/test/data/pre3.jade +++ b/test/data/pre3.jade @@ -1,3 +1,7 @@ +mixin bbr() + | + |
+ doctype html html head diff --git a/test/data/test.jade b/test/data/test.jade index 9300ff9..b4bf01d 100644 --- a/test/data/test.jade +++ b/test/data/test.jade @@ -1,3 +1,7 @@ +mixin bbr() + | + |
+ doctype html html head diff --git a/test/mocha.opts b/test/mocha.opts index 5ab5cf2..5deed1c 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,4 +1,5 @@ --reporter spec --ui bdd --timeout 20000 +--require coffee-script/register --compilers coffee:coffee-script