Permalink
Browse files

resolve conflicts

  • Loading branch information...
2 parents b427ed8 + 07ffa72 commit 7e652b7ec7afdb98319dcb1d1012d7f3ce5eb2b6 @flosse flosse committed Feb 24, 2012
Showing with 44 additions and 33 deletions.
  1. +0 −2 benchmark.coffee
  2. +44 −31 src/coffeecup.coffee
View
@@ -191,7 +191,6 @@ benchmark = (title, code) ->
code()
log "#{title}: #{new Date - start} ms"
-
benchmark 'coffeecup (precompiled)', -> coffeecup_compiled_template data
benchmark 'coffeecup (precompiled, optimized)', -> coffeecup_optimized_template data
benchmark 'Jade (precompiled)', -> jade_compiled_template data
@@ -213,4 +212,3 @@ benchmark 'coffeecup (string, cache off)', -> coffeecup.render coffeecup_string_
#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
-
View
@@ -1,10 +1,10 @@
# **CoffeeCup** lets you to write HTML templates in 100% pure
# [CoffeeScript](http://coffeescript.org).
-#
+#
# You can run it on [node.js](http://nodejs.org) or the browser, or compile your
# templates down to self-contained javascript functions, that will take in data
# and options and return generated HTML on any JS runtime.
-#
+#
# The concept is directly stolen from the amazing
# [Markaby](http://markaby.rubyforge.org/) by Tim Fletcher and why the lucky
# stiff.
@@ -67,6 +67,19 @@ elements =
select small span strong style sub summary sup table tbody td textarea tfoot
th thead time title tr u ul video'
+ # Support for SVG 1.1 tags
+ svg: 'a altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion
+ animateTransform circle clipPath color-profile cursor defs desc ellipse
+ feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix
+ feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB
+ feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology
+ feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence
+ filter font font-face font-face-format font-face-name font-face-src
+ font-face-uri foreignObject g glyph glyphRef hkern image line linearGradient
+ marker mask metadata missing-glyph mpath path pattern polygon polyline
+ radialGradient rect script set stop style svg switch symbol text textPath
+ title tref tspan use view vkern'
+
# Valid self-closing HTML 5 elements.
void: 'area base br col command embed hr img input keygen link meta param
source track wbr'
@@ -88,14 +101,15 @@ merge_elements = (args...) ->
# Public/customizable list of possible elements.
# For each name in this list that is also present in the input template code,
# a function with the same name will be added to the compiled template.
-coffeecup.tags = merge_elements 'regular', 'obsolete', 'void', 'obsolete_void'
+coffeekup.tags = merge_elements 'regular', 'obsolete', 'void', 'obsolete_void',
+ 'svg'
# Public/customizable list of elements that should be rendered self-closed.
coffeecup.self_closing = merge_elements 'void', 'obsolete_void'
# This is the basic material from which compiled templates will be formed.
# It will be manipulated in its string form at the `coffeecup.compile` function
-# to generate the final template function.
+# to generate the final template function.
skeleton = (data = {}) ->
# Whether to generate formatted HTML with indentation and line breaks, or
# just the natural "faux-minified" output.
@@ -108,7 +122,7 @@ skeleton = (data = {}) ->
# Internal coffeecup stuff.
__ck =
buffer: []
-
+
esc: (txt) ->
if data.autoescape then h(txt) else String(txt)
@@ -126,15 +140,15 @@ skeleton = (data = {}) ->
render_idclass: (str) ->
classes = []
-
+
for i in str.split '.'
if '#' in i
id = i.replace '#', ''
else
classes.push i unless i is ''
-
+
text " id=\"#{id}\"" if id
-
+
if classes.length > 0
text " class=\""
for c in classes
@@ -146,7 +160,7 @@ skeleton = (data = {}) ->
for k, v of obj
# `true` is rendered as `selected="selected"`.
v = k if typeof v is 'boolean' and v
-
+
# Functions are rendered in an executable form.
v = "(#{v}).call(this);" if typeof v is 'function'
@@ -176,22 +190,22 @@ skeleton = (data = {}) ->
render_tag: (name, idclass, attrs, contents) ->
@indent()
-
+
text "<#{name}"
@render_idclass(idclass) if idclass
@render_attrs(attrs) if attrs
-
+
if name in @self_closing
text ' />'
text '\n' if data.format
else
text '>'
-
+
@render_contents(contents)
text "</#{name}>"
text '\n' if data.format
-
+
null
tag = (name, args...) ->
@@ -227,19 +241,19 @@ skeleton = (data = {}) ->
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
-
+
doctype = (type = 'default') ->
text __ck.doctypes[type]
text '\n' if data.format
-
+
text = (txt) ->
__ck.buffer.push String(txt)
null
comment = (cmt) ->
text "<!--#{cmt}-->"
text '\n' if data.format
-
+
coffeescript = (param) ->
switch typeof param
# `coffeescript -> alert 'hi'` becomes:
@@ -255,11 +269,11 @@ skeleton = (data = {}) ->
when 'object'
param.type = 'text/coffeescript'
script param
-
+
# Conditional IE comments.
ie = (condition, contents) ->
__ck.indent()
-
+
text "<!--[if #{condition}]>"
__ck.render_contents(contents)
text "<![endif]-->"
@@ -286,9 +300,9 @@ coffeecup.compile = (template, options = {}) ->
# If an object `hardcode` is provided, insert the stringified value
# of each variable directly in the function body. This is a less flexible but
- # faster alternative to the standard method of using `with` (see below).
+ # faster alternative to the standard method of using `with` (see below).
hardcoded_locals = ''
-
+
if options.hardcode
for k, v of options.hardcode
if typeof v is 'function'
@@ -305,11 +319,11 @@ coffeecup.compile = (template, options = {}) ->
# all hundred-odd tags wasting space in the compiled function.
tag_functions = ''
tags_used = []
-
+
for t in coffeecup.tags
if template.indexOf(t) > -1 or hardcoded_locals.indexOf(t) > -1
tags_used.push t
-
+
tag_functions += "var #{tags_used.join ','};"
for t in tags_used
tag_functions += "#{t} = function(){return __ck.tag('#{t}', arguments);};"
@@ -327,16 +341,16 @@ coffeecup.compile = (template, options = {}) ->
code += "(#{template}).call(data);"
code += '}' if options.locals
code += "return __ck.buffer.join('');"
-
+
new Function('data', code)
cache = {}
# Template in, HTML out. Accepts functions or strings as does `coffeecup.compile`.
-#
+#
# Accepts an option `cache`, by default `false`. If set to `false` templates will
# be recompiled each time.
-#
+#
# `options` is just a convenience parameter to pass options separately from the
# data, but the two will be merged and passed down to the compiler (which uses
# `locals` and `hardcode`), and the template (which understands `locals`, `format`
@@ -359,25 +373,24 @@ unless window?
# Legacy adapters for when coffeecup expected data in the `context` attribute.
simple: coffeecup.render
meryl: coffeecup.render
-
+
express:
TemplateError: class extends Error
constructor: (@message) ->
Error.call this, @message
Error.captureStackTrace this, arguments.callee
name: 'TemplateError'
-
- compile: (template, data) ->
+
+ compile: (template, data) ->
# Allows `partial 'foo'` instead of `text @partial 'foo'`.
data.hardcode ?= {}
data.hardcode.partial = ->
text @partial.apply @, arguments
-
+
TemplateError = @TemplateError
try tpl = coffeecup.compile(template, data)
catch e then throw new TemplateError "Error compiling #{data.filename}: #{e.message}"
-
+
return ->
try tpl arguments...
catch e then throw new TemplateError "Error rendering #{data.filename}: #{e.message}"
-

0 comments on commit 7e652b7

Please sign in to comment.