Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ab4a134
Simplified executable
Oct 17, 2011
c029eba
Added basic optimised compiler
Oct 17, 2011
f22d1b4
Get exports from main script
Oct 18, 2011
f4becea
Removed function wrapper
Oct 18, 2011
f8a1739
Added hardcoded locals
Oct 18, 2011
0d53c78
Compiler can handle tag arguments other than functions and objects
Oct 18, 2011
6f2f320
Wrap compiled code in bound function to preserve scope
Oct 18, 2011
42952c0
Unwrap calls to tag functions from function wrapper when not needed
Oct 18, 2011
61adb49
Fixed function wrapper
Oct 18, 2011
bf775ed
Hardcoded locals also checked for markup tags
Oct 18, 2011
cf5fb39
Added doctype
Oct 18, 2011
53039fd
Allow for tags without content
Oct 18, 2011
c87c3ee
Removed broken jade benchmarks
Oct 18, 2011
362152a
Merge branch 'master' into optimize
Oct 18, 2011
cce76e0
Skeleton test() function takes numbers as well as strings
Oct 18, 2011
5b50c62
Code cleanup, comments
Oct 18, 2011
3ba8a58
Added escape function h() to skeleton
Oct 18, 2011
631b630
Added tag() function
Oct 18, 2011
43ee3fc
Added comment() function
Oct 18, 2011
8ac5838
Don't try to put too much in a single call to text()
Oct 18, 2011
e01a404
Refactor
Oct 19, 2011
ecb2c59
Added support for script and coffeescript functions
Oct 19, 2011
571732c
Comments for clarity
Oct 19, 2011
48700e0
Do not parse id class string for script tags
Oct 19, 2011
060acd3
Fixed coffeescript tag function
Oct 19, 2011
83f98b1
Added locals option
Oct 19, 2011
064faff
Added ie conditional comment helper
Oct 19, 2011
2d9611f
Tag functions can handle prefixed attributes
Oct 19, 2011
04cda25
Boolean true in tag attrs rendered as selected="selected"
Oct 19, 2011
000dc5e
Functions can be passed to tag attrs object
Oct 19, 2011
68cefd7
Added yield function to skeleton
Oct 19, 2011
3b58ad4
Added autoescape option
Oct 19, 2011
87fc65e
Do not escape calls to yield
Oct 20, 2011
85d1302
Escape tag contents by default
Oct 20, 2011
7267231
Escape return values of functions passed as arguments to tag functions
Oct 20, 2011
c094b0d
Escape dynamically generated html comments
Oct 20, 2011
f667ee7
ie helper allows for dynamic conditions
Oct 20, 2011
b817c05
Fixed coffeescript helper
Oct 20, 2011
147b194
Default doctype
Oct 20, 2011
83ab4a1
Tests run from command line
Oct 20, 2011
7d38b5d
Self-closing tag tweak so that test passes
Oct 20, 2011
39a48f0
Optimized compiler does not escape literal strings in the template, t…
Oct 20, 2011
196fb6f
text() function accepts arrays
Oct 20, 2011
e0b07c4
Code object can generate if blocks
Oct 20, 2011
7d2ec29
Functions passed as object attributes are prerendered as text
Oct 20, 2011
e384f60
Minor tweak to expected test result
Oct 20, 2011
064c2c5
Minor refactor
Oct 20, 2011
0b507bb
Modified ie conditional comment test: formatting not yet supported
Oct 20, 2011
8d4f3ae
Added optimize option
Oct 20, 2011
edcbd37
Created separate test suite for optimized templates
Oct 20, 2011
db169a2
Do not optimize templates when cache is off
Oct 20, 2011
af483dc
Benchmark optimized templates
Oct 20, 2011
cb44056
Escape hardcoded string literals
Oct 20, 2011
1dacf02
Fixed tests
Oct 20, 2011
d23557e
Updated package.json
Oct 20, 2011
41653d7
text() does not render arrays
Oct 20, 2011
e7e992f
Use string concatenation instead of array join
Oct 21, 2011
6ca8b69
Added precompiled eco template benchmark
Oct 22, 2011
2285f55
Bugfix: missing 'var' before skeleton variables
Oct 25, 2011
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions benchmark.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env coffee

coffeekup = require './src/coffeekup'
jade = require 'jade'
ejs = require 'ejs'
Expand Down Expand Up @@ -63,6 +65,8 @@ coffeekup_string_template = """

coffeekup_compiled_template = coffeekup.compile coffeekup_template

coffeekup_optimized_template = coffeekup.compile coffeekup_template, optimize: yes

jade_template = '''
!!! 5
html(lang="en")
Expand Down Expand Up @@ -153,6 +157,8 @@ eco_template = '''
</html>
'''

eco_compiled_template = eco.compile eco_template

haml_template = '''
!!! 5
%html{lang: "en"}
Expand Down Expand Up @@ -185,23 +191,25 @@ benchmark = (title, code) ->
code()
log "#{title}: #{new Date - start} ms"

@run = ->
benchmark 'CoffeeKup (precompiled)', -> coffeekup_compiled_template data
benchmark 'Jade (precompiled)', -> jade_compiled_template data
benchmark 'haml-js (precompiled)', -> haml_template_compiled data
benchmark 'Eco', -> eco.render eco_template, data

console.log '\n'
benchmark 'CoffeeKup (precompiled)', -> coffeekup_compiled_template data
benchmark 'CoffeeKup (precompiled, optimized)', -> coffeekup_optimized_template data
benchmark 'Jade (precompiled)', -> jade_compiled_template data
benchmark 'haml-js (precompiled)', -> haml_template_compiled data
benchmark 'Eco (precompiled)', -> eco_compiled_template data

console.log '\n'

benchmark 'CoffeeKup (function, cache on)', -> coffeekup.render coffeekup_template, data, cache: on
benchmark 'CoffeeKup (string, cache on)', -> coffeekup.render coffeekup_string_template, data, cache: on
benchmark 'Jade (cache on)', -> jade.render jade_template, locals: data, cache: on, filename: 'test'
benchmark 'ejs (cache on)', -> ejs.render ejs_template, locals: data, cache: on, filename: 'test'
benchmark 'CoffeeKup (function, cache on)', -> coffeekup.render coffeekup_template, data, cache: on
benchmark 'CoffeeKup (string, cache on)', -> coffeekup.render coffeekup_string_template, data, cache: on
#benchmark 'Jade (cache on)', -> jade.render jade_template, locals: data, cache: on, filename: 'test'
benchmark 'ejs (cache on)', -> ejs.render ejs_template, locals: data, cache: on, filename: 'test'
benchmark 'Eco', -> eco.render eco_template, data

console.log '\n'
console.log '\n'

benchmark 'CoffeeKup (function, cache off)', -> coffeekup.render coffeekup_template, data
benchmark 'CoffeeKup (string, cache off)', -> coffeekup.render coffeekup_string_template, data, cache: off
benchmark 'Jade (cache off)', -> jade.render jade_template, locals: data
benchmark 'haml-js', -> haml.render haml_template, locals: data
benchmark 'ejs (cache off)', -> ejs.render ejs_template, locals: data
benchmark 'CoffeeKup (function, cache off)', -> coffeekup.render coffeekup_template, data, cache: off
benchmark 'CoffeeKup (string, cache off)', -> coffeekup.render coffeekup_string_template, data, cache: off
#benchmark 'Jade (cache off)', -> jade.render jade_template, locals: data
benchmark 'haml-js', -> haml.render haml_template, locals: data
benchmark 'ejs (cache off)', -> ejs.render ejs_template, locals: data
8 changes: 2 additions & 6 deletions bin/coffeekup
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#!/usr/bin/env node
#!/usr/bin/env coffee

var path = require('path')
var fs = require('fs')
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib')

require(lib + '/cli').run()
require(__dirname + '/../src/cli').run()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"devDependencies": {"jade": "0.13.0", "eco": "1.1.0-rc-1", "ejs": "0.4.3", "haml": "0.4.2"},
"keywords": ["template", "view", "coffeescript"],
"bin": "./bin/coffeekup",
"main": "./lib/coffeekup",
"main": "./src/coffeekup",
"engines": {"node": ">= 0.4.7"},
"contributors": [
"Luis Pedro Coelho <lpc@cmu.edu>",
Expand Down
13 changes: 12 additions & 1 deletion src/coffeekup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ if window?
else
coffeekup = exports
coffee = require 'coffee-script'
compiler = require __dirname + '/compiler'
compiler.setup coffeekup

coffeekup.version = '0.3.1edge'

Expand Down Expand Up @@ -294,6 +296,11 @@ coffeekup.compile = (template, options = {}) ->
hardcoded_locals += "var #{k} = function(){return (#{v}).apply(data, arguments);};"
else hardcoded_locals += "var #{k} = #{JSON.stringify v};"

# If `optimize` is set on the options hash, use uglify-js to parse the
# template function's code and optimize it using static analysis.
if options.optimize and compiler?
return compiler.compile template, hardcoded_locals, options

# Add a function for each tag this template references. We don't want to have
# all hundred-odd tags wasting space in the compiled function.
tag_functions = ''
Expand Down Expand Up @@ -338,6 +345,10 @@ coffeekup.render = (template, data = {}, options = {}) ->
data[k] = v for k, v of options
data.cache ?= off

# Do not optimize templates if the cache is disabled, as it will slow
# everything down considerably.
if data.optimize and not data.cache then data.optimize = no

if data.cache and cache[template]? then tpl = cache[template]
else if data.cache then tpl = cache[template] = coffeekup.compile(template, data)
else tpl = coffeekup.compile(template, data)
Expand Down Expand Up @@ -368,4 +379,4 @@ unless window?

return ->
try tpl arguments...
catch e then throw new TemplateError "Error rendering #{data.filename}: #{e.message}"
catch e then throw new TemplateError "Error rendering #{data.filename}: #{e.message}"
Loading