From 4ada547c7ec8d41eb90647b13a0d310a1d2b7690 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Mon, 24 Jun 2013 22:13:14 -0400 Subject: [PATCH] really questionable fix for an edge precompiler bug, and another reason why I'm reluctant to adopt coffeescript --- lib/precompiler.coffee | 26 +++++++++++++++++--------- package.json | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/precompiler.coffee b/lib/precompiler.coffee index 9c9da851..567d5c5a 100644 --- a/lib/precompiler.coffee +++ b/lib/precompiler.coffee @@ -38,12 +38,12 @@ module.exports = -> class Precompiler - + # deals with setting up the variables for options # @param {Object} options = {} an object holding all the options to be # passed to the compiler. 'templates' must be specified. # @constructor - + constructor: (options = {}) -> defaults = include_helpers: true @@ -54,11 +54,11 @@ class Precompiler _.extend @, defaults, options - + # loop through all the templates specified, compile them, and add a wrapper # @return {String} the source of a JS object which holds all the templates # @public - + compile: -> buf = [""" (function(){ @@ -72,27 +72,35 @@ class Precompiler buf.push '})();' return buf.join '' - + # compile individual templates # @param {String} template the full filename & path of the template to be compiled # @return {String} source of the template function # @private - + compileTemplate: (template) -> templateNamespace = path.basename(template, '.jade').replace(/\//g, '.') # Replaces '/' with '.' data = fs.readFileSync(template, 'utf8') data = jade.compile(data, { compileDebug: @debug || false, inline: @inline || false, client: true }) return "#{@namespace}.#{templateNamespace} = #{data};\n" - + # Gets Jade's helpers and combines them into string # @return {String} source of Jade's helpers # @private - + helpers: -> + + # jade has a few extra helpers that aren't exported + # we should probably figure out a way to pull all of runtime.js + nulls = `function nulls(val) { return val != null && val !== '' }` + joinClasses = `function joinClasses(val) { return Array.isArray(val) ? val.map(joinClasses).filter(nulls).join(' ') : val; }` + buf = [ jade.runtime.attrs.toString().replace(/exports\./g,''), - jade.runtime.escape.toString() + jade.runtime.escape.toString(), + nulls.toString(), + joinClasses.toString() ] buf.push jade.runtime.rethrow.toString() if @debug diff --git a/package.json b/package.json index a96b1b9b..e3d6d528 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "roots", - "version": "2.0.0", + "version": "2.0.1", "description": "roots is a toolbox for building simple, beautiful, and efficient products for the web", "keywords": [ "front-end",