From d1a5b0245602a09fcddb7425d03fb856631606a9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 6 Jun 2012 17:50:34 +1000 Subject: [PATCH 1/4] Updated build file and stopped meaningless newlines printing in templates --- .DS_Store | Bin 0 -> 6148 bytes Cakefile | 6 +-- lib/.DS_Store | Bin 0 -> 6148 bytes lib/command.js | 83 ++++++++++++++++++++++++++++------------ lib/compiler.js | 1 + lib/index.js | 5 ++- lib/preprocessor.js | 11 +++++- lib/scanner.js | 13 +++++-- lib/util.js | 7 +++- src/command.coffee | 4 +- src/preprocessor.coffee | 4 +- src/util.coffee | 1 + 12 files changed, 96 insertions(+), 39 deletions(-) create mode 100644 .DS_Store create mode 100644 lib/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..717524024b956aef439dccc6c662174e19926820 GIT binary patch literal 6148 zcmeHKL2uJA6n<_4OJRs!kl+?^;!suXm?#Ghp|prefY3T=2Zlz{lr<2Ns!8dgDg<%h zFYq(?A)FEarhLyfQB7dPyhZEqgzhjEb1 zyU8pL(&vM5G9QG&$oHl%q@Q`&EbV$z+4IcH#^{m$UXn!c4>Wr}46^ZI{l;R^-s-d) z&erywWy4u?I<1DYef#cmS+i@k`e*yv&E~yFd*1T>hy0_QDGBUy(ynOy1)ty?ujAcd z8b?Wdgf`|^p;btJNrfNiVHGM`1A0X$RTUr>8Waeo+bHJo~biXPXpL zg4`L=A-$E}jI)i>QXJ=7F>ZqV93n$KIs(5*uaSL8Ij?2@t;gB4`=`7X{7!oRR5lwlAO2cxD)*fKlN5 zD8T!JgTm-)%oWP51C_i204+32gD*e+fetqSU5&Xyw7`T41*%Y?uNXq#9fS%;zpMGV zLKRLz{xZhVzby0(Md+)Ca3r0CtI*U&0i!@sfvS3}^ZDQZ{r$ffWS)!yMuBssfUtUl zUKdN!XX}Z@@mcGjyhLGRUanAvpwh>&boeN~jv@_x4m&_sW3CV_F!LcGWiXXd;IAt1 E6PwWi8UO$Q literal 0 HcmV?d00001 diff --git a/Cakefile b/Cakefile index 89b1af6..0f8c0e8 100644 --- a/Cakefile +++ b/Cakefile @@ -60,7 +60,7 @@ task "dist", "Generate dist/eco.js", -> "strscan": read "node_modules/strscan/lib/strscan.js" "coffee-script": stub "CoffeeScript" - package = for name, source of modules + pkg = for name, source of modules """ '#{name}': function(module, require, exports) { #{source} @@ -89,12 +89,12 @@ task "dist", "Generate dist/eco.js", -> } }; })({ - #{package.join ',\n'} + #{pkg.join ',\n'} })('eco'); """ try - fs.mkdirSync "#{__dirname}/dist", 0755 + fs.mkdirSync "#{__dirname}/dist", 0o0755 catch err fs.writeFileSync "#{__dirname}/dist/eco.js", "#{header}\n#{source}" diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7af7ec70ac0ebdcd13db199a78df0b92070f229a GIT binary patch literal 6148 zcmeHK!A`tc)&Z@jkV?|xd2N7Hh|eq9`Q)T^}#TR_iq=6Jyr1>V!F*RsB9Ssg~}3Muf}6fY08 z_zTSWd!CH2JP&cNsgjnq~*zQ0rQ4)pdp?KCC8N#SQhWm?7&mZAdT> z3k*b#u(rrU&V{aw_Y%rSSY60(OP zDV3N~#g7=0(&^7UE_bXFrgVrOKEy{BKcR??&gW+q4#^XS4F-aNT?S6lZD05Q+r#Jo z-K4k+27-Zq#elSjkHY~=^1XGhINfVA>JwE( " + outfile); return proceed(); }); diff --git a/lib/compiler.js b/lib/compiler.js index 0eff0e5..7f624eb 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -1,3 +1,4 @@ +// Generated by CoffeeScript 1.3.3 (function() { var CoffeeScript, indent, precompile, preprocess; diff --git a/lib/index.js b/lib/index.js index bca5ac8..4a6fa8e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,4 @@ +// Generated by CoffeeScript 1.3.3 (function() { var compile, eco, precompile, preprocess, _ref; @@ -6,9 +7,9 @@ preprocess = require("./preprocessor").preprocess; module.exports = eco = function(source) { - var _base, _ref2; + var _base, _ref1; if (eco.cache) { - return (_ref2 = (_base = eco.cache)[source]) != null ? _ref2 : _base[source] = compile(source); + return (_ref1 = (_base = eco.cache)[source]) != null ? _ref1 : _base[source] = compile(source); } else { return compile(source); } diff --git a/lib/preprocessor.js b/lib/preprocessor.js index 5a33c64..6e0c558 100644 --- a/lib/preprocessor.js +++ b/lib/preprocessor.js @@ -1,3 +1,4 @@ +// Generated by CoffeeScript 1.3.3 (function() { var Preprocessor, Scanner, util; @@ -38,7 +39,11 @@ Preprocessor.prototype.printString = function(string) { if (string.length) { - return this.record("__out.push " + (util.inspectString(string))); + string = util.trim(string); + string = util.inspectString(string); + if (string.length && string !== "\n") { + return this.record("__out.push " + string); + } } }; @@ -71,7 +76,9 @@ Preprocessor.prototype.dedent = function() { this.level--; - if (this.level < 0) this.fail("unexpected dedent"); + if (this.level < 0) { + this.fail("unexpected dedent"); + } if (this.captures[0] === this.level) { this.captures.shift(); return this.dedent(); diff --git a/lib/scanner.js b/lib/scanner.js index cd7258d..2e06bfd 100644 --- a/lib/scanner.js +++ b/lib/scanner.js @@ -1,3 +1,4 @@ +// Generated by CoffeeScript 1.3.3 (function() { var Scanner, StringScanner, trim; @@ -100,10 +101,16 @@ } else if (this.tail) { this.mode = "data"; code = trim(this.flush()); - if (this.arrow) code += " " + this.arrow; - if (this.isDedentable(code)) callback(["dedent"]); + if (this.arrow) { + code += " " + this.arrow; + } + if (this.isDedentable(code)) { + callback(["dedent"]); + } callback(["recordCode", code]); - if (this.directive) return callback(["indent", this.arrow]); + if (this.directive) { + return callback(["indent", this.arrow]); + } } }; diff --git a/lib/util.js b/lib/util.js index 80fed3e..47a7cf5 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,3 +1,4 @@ +// Generated by CoffeeScript 1.3.3 (function() { var repeat, specialCharacters; @@ -22,7 +23,7 @@ }; exports.trim = function(string) { - return string.replace(/^\s+/, "").replace(/\s+$/, ""); + return string.replace(/^\s+/, "").replace(/\s+$/, "").replace(/\s+/g, " "); }; specialCharacters = { @@ -42,7 +43,9 @@ return specialCharacters[character]; } else { code = character.charCodeAt(0).toString(16); - if (code.length === 1) code = "0" + code; + if (code.length === 1) { + code = "0" + code; + } return "\\u00" + code; } }); diff --git a/src/command.coffee b/src/command.coffee index 7c44283..93fd065 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -22,8 +22,8 @@ printUsage = -> process.exit 1 printVersion = -> - package = JSON.parse fs.readFileSync __dirname + "/../package.json", "utf8" - console.error "Eco version #{package.version}" + pkg = JSON.parse fs.readFileSync __dirname + "/../pkg.json", "utf8" + console.error "Eco version #{pkg.version}" process.exit 0 preprocessArgs = (args) -> diff --git a/src/preprocessor.coffee b/src/preprocessor.coffee index f698dd1..c986e22 100644 --- a/src/preprocessor.coffee +++ b/src/preprocessor.coffee @@ -25,7 +25,9 @@ module.exports = class Preprocessor printString: (string) -> if string.length - @record "__out.push #{util.inspectString string}" + string = util.trim string + string = util.inspectString string + @record "__out.push #{string}" if string.length and string != "\n" beginCode: (options) -> @options = options diff --git a/src/util.coffee b/src/util.coffee index 9f40cf6..81e0f7a 100644 --- a/src/util.coffee +++ b/src/util.coffee @@ -10,6 +10,7 @@ exports.trim = (string) -> string .replace(/^\s+/, "") .replace(/\s+$/, "") + .replace(/\s+/g, " ") specialCharacters = '\\': '\\\\' From 7b98e26a23344fd4dc0f0a008ff187cfcf18f53c Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 7 Jun 2012 10:19:39 +1000 Subject: [PATCH 2/4] =?UTF-8?q?Further=20updates=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/util.js | 2 +- package.json | 2 +- src/preprocessor.coffee | 2 +- src/util.coffee | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/util.js b/lib/util.js index 47a7cf5..9142b70 100644 --- a/lib/util.js +++ b/lib/util.js @@ -23,7 +23,7 @@ }; exports.trim = function(string) { - return string.replace(/^\s+/, "").replace(/\s+$/, "").replace(/\s+/g, " "); + return string.replace(/^\s+/, "").replace(/\s+$/, "").replace(/\s{2,}/gm, " ").replace(/\\n/gm, ""); }; specialCharacters = { diff --git a/package.json b/package.json index e8730af..5a7c454 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "eco" , "description": "Embedded CoffeeScript templates" , "author": "Sam Stephenson" -, "version": "1.1.0-rc-3" +, "version": "1.1.1-beta" , "licenses": [ { "type": "MIT" , "url": "https://github.com/sstephenson/eco/raw/master/LICENSE" diff --git a/src/preprocessor.coffee b/src/preprocessor.coffee index c986e22..08540b0 100644 --- a/src/preprocessor.coffee +++ b/src/preprocessor.coffee @@ -3,7 +3,7 @@ util = require "./util" module.exports = class Preprocessor @preprocess: (source) -> - preprocessor = new Preprocessor source + preprocessor = new Preprocessor source#.replace(/\s{2,}/gm, "") preprocessor.preprocess() constructor: (source) -> diff --git a/src/util.coffee b/src/util.coffee index 81e0f7a..c692c3a 100644 --- a/src/util.coffee +++ b/src/util.coffee @@ -10,7 +10,9 @@ exports.trim = (string) -> string .replace(/^\s+/, "") .replace(/\s+$/, "") - .replace(/\s+/g, " ") + .replace(/\s{2,}/gm, " ") + .replace(/\\n/gm,"") + .replace(/<\!--[^\-]+-->/g, "") specialCharacters = '\\': '\\\\' From 844fc13b96bc8443633a4396505217f831cc8e61 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 7 Jun 2012 10:35:19 +1000 Subject: [PATCH 3/4] Updated read me to catalog changes made --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index ed96add..0617eee 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,22 @@ +# Improved web performance and size + +I am currently working on a web application using eco templates for both the server +and client. The plan is to pre-compile the templates using brunch and load keep them +in the main build file. I just had a looked at the minified output and I was horrified at +what eco had done. + +* It pushes many meaningless lines to the output array, +* preserves multiple recurrent white-spaces when just one white space would be appropriate, +* and leaves html comments in... for fun? + +So in light of this I modified the preprocessor and utilities slightly and corrected these +issues. + +Later I would like to modify eco further so that it didn't build a copy of its base functions +into every template it rendered and instead shared some code brought in through a require. +This would reduce the framework agnosticism presently enjoyed by eco, so I am going to have to +think about it a little more... + Eco: Embedded CoffeeScript templates ==================================== From fa44284ce5e38276820d37890161d2d2909bdbd7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 7 Jun 2012 11:40:19 +1000 Subject: [PATCH 4/4] Increased number of cases when a single white space may apply --- src/util.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.coffee b/src/util.coffee index c692c3a..1947b4a 100644 --- a/src/util.coffee +++ b/src/util.coffee @@ -10,7 +10,7 @@ exports.trim = (string) -> string .replace(/^\s+/, "") .replace(/\s+$/, "") - .replace(/\s{2,}/gm, " ") + .replace(/\s+/gm, " ") .replace(/\\n/gm,"") .replace(/<\!--[^\-]+-->/g, "")