Skip to content

Commit

Permalink
really questionable fix for an edge precompiler bug, and another reas…
Browse files Browse the repository at this point in the history
…on why I'm reluctant to adopt coffeescript
  • Loading branch information
Jeff Escalante committed Jun 25, 2013
1 parent a872c55 commit 4ada547
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions lib/precompiler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(){
Expand All @@ -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 !== '' }`

This comment has been minimized.

Copy link
@samccone

samccone Jun 25, 2013

Collaborator
nulls = (val) -> val? and val.length
joinClasses = `function joinClasses(val) { return Array.isArray(val) ? val.map(joinClasses).filter(nulls).join(' ') : val; }`

This comment has been minimized.

Copy link
@samccone

samccone Jun 25, 2013

Collaborator
joinClasses = (val) -> if Array.isArray(val) then val.map(joinClasses).filter(nulls).join(' ') else val

This comment has been minimized.

Copy link
@jescalan

jescalan Jun 25, 2013

Owner

nope.

This comment has been minimized.

Copy link
@notslang

notslang Jun 25, 2013

Collaborator
buf = [
       jade.runtime.attrs.toString().replace(/exports\./g,'')
       jade.runtime.escape.toString()
       'function nulls(val) { return val != null && val !== "" }'
       'function joinClasses(val) { return Array.isArray(val) ? val.map(joinClasses).filter(nulls).join(" ") : val; }'
]

This comment has been minimized.

Copy link
@jescalan

jescalan Jun 25, 2013

Owner

Works, but I don't see it as an improvement to code clarity.

I think the long term fix for this is to browserify all of runtime.js and just include that...

This comment has been minimized.

Copy link
@notslang

notslang Jun 25, 2013

Collaborator

or submit a fix to Jade


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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 4ada547

Please sign in to comment.