Skip to content

Commit

Permalink
Updated examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricemach committed Nov 9, 2010
1 parent 5399b60 commit 09ecf4f
Show file tree
Hide file tree
Showing 22 changed files with 240 additions and 207 deletions.
10 changes: 2 additions & 8 deletions Cakefile
@@ -1,15 +1,9 @@
exec = require('child_process').exec
benchmark = require './benchmark'
test = require './test'

task 'build', ->
exec 'coffee -c lib/coffeekup.coffee', (err) ->
puts err if err
exec 'cp lib/coffeekup.js examples/browser', (err) ->
puts err if err

task 'test', ->
test.run()
task 'test', -> require('./test').run()

task 'benchmark', ->
benchmark.run()
task 'benchmark', -> require('./benchmark').run()
8 changes: 0 additions & 8 deletions examples/browser/coffeekup-min.js

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions examples/browser/creme/coffeekup.js
Expand Up @@ -13,29 +13,28 @@
<script type="text/coffeescript">
stooges = ['moe', 'larry', 'curly']

$(document).ready ->
$().ready ->
stringy = """
h2 'Crème (string)'
h2 'Template as string'
ul ->
for guy in @stooges
li guy
"""

codey = ->
h2 'Crème (code)'
h2 'Template as a function'

ul ->
for guy in @stooges
li guy

$('body').append CoffeeKup.render(stringy, context: {stooges: stooges})

$('body').append CoffeeKup.render(codey, context: {stooges: stooges})
</script>
</head>
<body>
<h1>Client-side CoffeeKup (Crème)</h1>
<p>Delicious syntax directly on the client-side, but lots of fat from including the CoffeeScript compiler.</p>
<h1>Client-side CoffeeKup (crème)</h1>
<p>Doing everything on the client. Lots of flexibility but a fatty download.</p>
</body>
</html>
26 changes: 0 additions & 26 deletions examples/browser/decaf.html

This file was deleted.

10 changes: 0 additions & 10 deletions examples/browser/decaf.js

This file was deleted.

11 changes: 11 additions & 0 deletions examples/browser/decaf/Cakefile
@@ -0,0 +1,11 @@
exec = require('child_process').exec
fs = require 'fs'
coffekup = require 'coffeekup'

task 'build', ->
fs.readFile 'template.coffee', 'utf-8', (err, data) ->
puts err if err
compiled = coffekup.compile data
str = String(compiled).replace 'function anonymous', 'function template'
fs.writeFile 'template.js', str, (err) ->
puts err if err
22 changes: 22 additions & 0 deletions examples/browser/decaf/index.html
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Client-side CoffeeKup (decaf)</title>

<!-- jQuery is NOT required, used here for convenience -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script src="template.js"></script>

<script>
$().ready(function(){
$('body').append(template({context: {stooges: ['moe', 'larry', 'curly']}}));
});
</script>
</head>
<body>
<h1>Client-side CoffeeKup (decaf)</h1>
<p>Consuming a template from a non-CoffeeScript app.</p>
</body>
</html>
@@ -1,5 +1,3 @@
h2 'Decaf'

ul ->
for guy in @stooges
li guy
110 changes: 14 additions & 96 deletions examples/browser/coffeekup.js → examples/browser/decaf/template.js
@@ -1,16 +1,8 @@
(function() {
var cache, coffee, coffeekup, skeleton, support, tags;
var __hasProp = Object.prototype.hasOwnProperty;
if (typeof window !== "undefined" && window !== null) {
coffeekup = (window.CoffeeKup = {});
coffee = (typeof CoffeeScript !== "undefined" && CoffeeScript !== null) ? CoffeeScript : null;
} else {
coffeekup = exports;
coffee = require('coffee-script');
}
coffeekup.version = '0.1.7';
skeleton = function(ck_options) {
var ck_buffer, ck_doctypes, ck_esc, ck_indent, ck_render_attrs, ck_repeat, ck_self_closing, ck_tabs, ck_tag, coffeescript, comment, doctype, h, tag, text;
function template(ck_options) {
var __slice = Array.prototype.slice;
var __hasProp = Object.prototype.hasOwnProperty;
var __bind = function(func, context) {return function(){ return func.apply(context, arguments); };};
var ck_buffer, ck_doctypes, ck_esc, ck_indent, ck_render_attrs, ck_repeat, ck_self_closing, ck_tabs, ck_tag, coffeescript, comment, doctype, h, tag, text, a,i,li,p,s,th,u,ul;
ck_options = (typeof ck_options !== "undefined" && ck_options !== null) ? ck_options : {};
ck_options.context = (typeof ck_options.context !== "undefined" && ck_options.context !== null) ? ck_options.context : {};
ck_options.locals = (typeof ck_options.locals !== "undefined" && ck_options.locals !== null) ? ck_options.locals : {};
Expand Down Expand Up @@ -132,87 +124,13 @@
coffeescript = function(code) {
return script(";(" + (code) + ")();");
};
return null;
};
support = 'var __slice = Array.prototype.slice;\nvar __hasProp = Object.prototype.hasOwnProperty;\nvar __bind = function(func, context) {return function(){ return func.apply(context, arguments); };};';
skeleton = String(skeleton).replace('function (ck_options) {', '').replace(/return null;\s*\}$/, '');
skeleton = support + skeleton;
tags = 'a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdo|big|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|command|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|i|iframe|img|input|ins|keygen|kbd|label|legend|li|link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|small|source|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|tt|u|ul|video|xmp'.split('|');
coffeekup.compile = function(template, options) {
var _i, _len, _ref, code, k, t, tags_here, v;
options = (typeof options !== "undefined" && options !== null) ? options : {};
options.locals = (typeof options.locals !== "undefined" && options.locals !== null) ? options.locals : {};
if (typeof template === 'function') {
template = String(template);
} else if (typeof template === 'string' && (typeof coffee !== "undefined" && coffee !== null)) {
template = coffee.compile(template, {
'noWrap': 'noWrap'
});
template = ("function(){" + (template) + "}");
}
tags_here = [];
_ref = tags;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
t = _ref[_i];
if (template.indexOf(t) > -1) {
tags_here.push(t);
}
}
code = skeleton.replace(', text;', ", text, " + (tags_here.join(',')) + ";");
code += 'var arrayCreator = Array;';
_ref = tags_here;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
t = _ref[_i];
code += ("" + (t) + " = function(){return ck_tag('" + (t) + "', arguments)};");
}
_ref = options.locals;
for (k in _ref) {
if (!__hasProp.call(_ref, k)) continue;
v = _ref[k];
if (typeof v === 'function') {
code += ("var " + (k) + " = " + (v) + ";");
} else {
code += ("var " + (k) + " = " + (JSON.stringify(v)) + ";");
}
}
if (options.dynamic_locals) {
code += 'with(ck_options.locals){';
}
code += ("(" + (template) + ").call(ck_options.context);");
if (options.dynamic_locals) {
code += '}';
}
code += "return ck_buffer.join('');";
return new Function('ck_options', code);
};
cache = {};
coffeekup.render = function(template, options) {
var _ref, tpl;
options = (typeof options !== "undefined" && options !== null) ? options : {};
options.context = (typeof options.context !== "undefined" && options.context !== null) ? options.context : {};
options.locals = (typeof options.locals !== "undefined" && options.locals !== null) ? options.locals : {};
options.cache = (typeof options.cache !== "undefined" && options.cache !== null) ? options.cache : true;
if (typeof (_ref = options.locals.body) !== "undefined" && _ref !== null) {
options.context.body = options.locals.body;
delete options.locals.body;
}
if (options.cache && (typeof (_ref = cache[template]) !== "undefined" && _ref !== null)) {
tpl = cache[template];
} else if (options.cache) {
tpl = (cache[template] = coffeekup.compile(template, options));
} else {
tpl = coffeekup.compile(template, options);
}
return tpl(options);
};
if (!(typeof window !== "undefined" && window !== null)) {
coffeekup.adapters = {
simple: function(template, data) {
return coffeekup.render(template, {
context: data
});
}
};
coffeekup.adapters.meryl = coffeekup.adapters.simple;
var arrayCreator = Array;a = function(){return ck_tag('a', arguments)};i = function(){return ck_tag('i', arguments)};li = function(){return ck_tag('li', arguments)};p = function(){return ck_tag('p', arguments)};s = function(){return ck_tag('s', arguments)};th = function(){return ck_tag('th', arguments)};u = function(){return ck_tag('u', arguments)};ul = function(){return ck_tag('ul', arguments)};(function(){ul(function() {
var _i, _len, _ref, _result, guy;
_result = []; _ref = this.stooges;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
guy = _ref[_i];
_result.push(li(guy));
}
}).call(this);
return _result;
});}).call(ck_options.context);return ck_buffer.join('');
}
11 changes: 0 additions & 11 deletions examples/browser/regular.coffee

This file was deleted.

17 changes: 0 additions & 17 deletions examples/browser/regular.html

This file was deleted.

22 changes: 0 additions & 22 deletions examples/browser/regular.js

This file was deleted.

13 changes: 13 additions & 0 deletions examples/browser/regular/Cakefile
@@ -0,0 +1,13 @@
exec = require('child_process').exec
fs = require 'fs'
coffekup = require 'coffeekup'

task 'build', ->
fs.readFile 'template.coffee', 'utf-8', (err, data) ->
puts err if err
compiled = coffekup.compile data
str = String(compiled).replace 'function anonymous', 'function template'
fs.writeFile 'template.js', str, (err) ->
puts err if err
exec 'coffee -c index.coffee', (err) ->
puts err if err
2 changes: 2 additions & 0 deletions examples/browser/regular/index.coffee
@@ -0,0 +1,2 @@
$().ready ->
$('body').append template(context: {stooges: ['moe', 'larry', 'curly']})
17 changes: 17 additions & 0 deletions examples/browser/regular/index.html
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Client-side CoffeeKup (regular)</title>

<!-- jQuery is NOT required, used here for convenience -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script src="template.js"></script>
<script src="index.js"></script>
</head>
<body>
<h1>Client-side CoffeeKup (regular)</h1>
<p>Writing your app and templates in CoffeeScript but pre-compiling everything on the server-side.</p>
</body>
</html>
9 changes: 9 additions & 0 deletions examples/browser/regular/index.js
@@ -0,0 +1,9 @@
(function() {
$().ready(function() {
return $('body').append(template({
context: {
stooges: ['moe', 'larry', 'curly']
}
}));
});
}).call(this);
3 changes: 3 additions & 0 deletions examples/browser/regular/template.coffee
@@ -0,0 +1,3 @@
ul ->
for guy in @stooges
li guy

0 comments on commit 09ecf4f

Please sign in to comment.