Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more output options #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion src/cli.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ usage = '''
'''

switches = [
['--js', 'compile template to js function']
['-j', '--js', 'compile template to js function (template + embedded renderer)']
['-b', '--bare', 'use with -j to compile template to js (template only)' ]
['-c', '--core', 'use with -j to compile renderer to js (renderer only)' ]
['-n', '--namespace [name]', 'global object holding the templates (default: "templates")']
['-w', '--watch', 'watch templates for changes, and recompile']
['-o', '--output [dir]', 'set the directory for compiled html']
Expand Down
30 changes: 17 additions & 13 deletions src/coffeekup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -302,24 +302,28 @@ coffeekup.compile = (template, options = {}) ->
for t in coffeekup.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);};"

# Main function assembly.
code = tag_functions + hardcoded_locals + skeleton
# # Main function assembly.
code = ""

code += "__ck.doctypes = #{JSON.stringify coffeekup.doctypes};"
code += "__ck.coffeescript_helpers = #{JSON.stringify coffeescript_helpers};"
code += "__ck.self_closing = #{JSON.stringify coffeekup.self_closing};"

# If `locals` is set, wrap the template inside a `with` block. This is the
# most flexible but slower approach to specifying local variables.
code += 'with(data.locals){' if options.locals
code += "(#{template}).call(data);"
code += '}' if options.locals
code += "return __ck.buffer.join('');"
# If bare is used, the main mechanism is stripped from template
unless options.bare && !options.core
code += tag_functions + hardcoded_locals + skeleton
code += "__ck.doctypes = #{JSON.stringify coffeekup.doctypes};"
code += "__ck.coffeescript_helpers = #{JSON.stringify coffeescript_helpers};"
code += "__ck.self_closing = #{JSON.stringify coffeekup.self_closing};"

unless options.core && !options.bare
# If `locals` is set, wrap the template inside a `with` block. This is the
# most flexible but slower approach to specifying local variables.
code += 'with(data.locals){' if options.locals
code += "(#{template}).call(data);"
code += '}' if options.locals
code += "return __ck.buffer.join('');"

new Function('data', code)

Expand Down