Permalink
Browse files

v0.2.2 (coffeescript 1.0 compatibility).

  • Loading branch information...
1 parent c514d9b commit b260befd8f617463f263364134328ebd6ff72b20 @mauricemach mauricemach committed Jan 4, 2011
Showing with 31 additions and 234 deletions.
  1. +2 −0 .gitignore
  2. +5 −1 README.md
  3. +9 −2 bin/coffeekup.coffee
  4. +2 −2 examples/browser/creme/coffee-script.js
  5. +10 −6 lib/coffeekup.coffee
  6. +0 −220 lib/coffeekup.js
  7. +3 −3 package.json
View
@@ -1 +1,3 @@
+.DS_Store
material/
+lib/coffeekup.js
View
@@ -159,6 +159,10 @@ See [/examples](http://github.com/mauricemach/coffeekup/tree/master/examples) fo
## Change Log:
+**v0.2.2** (2011-01-05):
+
+ - Updated to CoffeeScript 1.0.0 and node 0.2.6/0.3.3.
+
**v0.2.1** (2010-11-09):
- Updated to CoffeeScript 0.9.5 and node 0.2.5/0.3.1.
@@ -175,4 +179,4 @@ See [/examples](http://github.com/mauricemach/coffeekup/tree/master/examples) fo
## Compatibility
-Latest version tested with node 0.2.5/0.3.1 and CoffeeScript 0.9.5.
+Latest version tested with node 0.2.6/0.3.3 and CoffeeScript 1.0.0.
View
@@ -6,6 +6,13 @@ path = require 'path'
puts = console.log
OptionParser = require('coffee-script/optparse').OptionParser
+# On coffee-script@0.9.6, argv looks like [filename],
+# On coffee-script@1.0.0, argv looks like ["node", "path/to/coffee", filename]
+if process.argv[0] is 'node' and process.argv.length >= 2
+ argv = process.argv[2..]
+else
+ argv = process.argv[0..]
+
render = (input_path) ->
fs.readFile input_path, (err, contents) ->
throw err if err
@@ -36,11 +43,11 @@ switches = [
]
parser = new OptionParser switches, usage
-options = parser.parse process.argv
+options = parser.parse argv
args = options.arguments
delete options.arguments
-puts parser.help() if options.help or process.argv.length is 0
+puts parser.help() if options.help or argv.length is 0
puts coffeekup.version if options.version
if options.utils
options.locals ?= {}
View
@@ -5,7 +5,7 @@ else
coffeekup = exports
coffee = require 'coffee-script'
-coffeekup.version = '0.2.1'
+coffeekup.version = '0.2.2'
skeleton = (ck_options) ->
ck_options ?= {}
@@ -101,14 +101,18 @@ skeleton = (ck_options) ->
support = '''
var __slice = Array.prototype.slice;
var __hasProp = Object.prototype.hasOwnProperty;
- var __indexOf = Array.prototype.indexOf || function(item) {
- for (var i = 0, l = this.length; i < l; i++) {if (this[i] === item) return i;}; return -1;};
- var __bind = function(fn, me){return function(){return fn.apply(me, arguments);};};
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
var __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; }
- ctor.prototype = parent.prototype; child.prototype = new ctor;
- child.__super__ = parent.prototype; return child;
+ ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype;
+ return child;
+ };
+ var __indexOf = Array.prototype.indexOf || function(item) {
+ for (var i = 0, l = this.length; i < l; i++) {
+ if (this[i] === item) return i;
+ }
+ return -1;
};
'''
View
@@ -1,220 +0,0 @@
-(function() {
- var cache, coffee, coffeekup, skeleton, support, tags;
- var __hasProp = Object.prototype.hasOwnProperty, __indexOf = Array.prototype.indexOf || function(item) {
- for (var i = 0, l = this.length; i < l; i++) {
- if (this[i] === item) return i;
- }
- return -1;
- };
- 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.2.1';
- 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, _ref, _ref2, _ref3, _ref4;
- ck_options != null ? ck_options : ck_options = {};
- (_ref = ck_options.context) != null ? _ref : ck_options.context = {};
- (_ref2 = ck_options.locals) != null ? _ref2 : ck_options.locals = {};
- (_ref3 = ck_options.format) != null ? _ref3 : ck_options.format = false;
- (_ref4 = ck_options.autoescape) != null ? _ref4 : ck_options.autoescape = false;
- ck_buffer = [];
- ck_render_attrs = function(obj) {
- var k, str, v;
- str = '';
- for (k in obj) {
- if (!__hasProp.call(obj, k)) continue;
- v = obj[k];
- str += " " + k + "=\"" + (ck_esc(v)) + "\"";
- }
- return str;
- };
- ck_doctypes = {
- '5': '<!DOCTYPE html>',
- 'xml': '<?xml version="1.0" encoding="utf-8" ?>',
- 'default': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
- 'transitional': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
- 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
- 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
- '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
- 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
- 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'
- };
- ck_self_closing = ['area', 'base', 'basefont', 'br', 'hr', 'img', 'input', 'link', 'meta'];
- ck_esc = function(txt) {
- if (ck_options.autoescape) {
- return h(txt);
- } else {
- return String(txt);
- }
- };
- ck_tabs = 0;
- ck_repeat = function(string, count) {
- return Array(count + 1).join(string);
- };
- ck_indent = function() {
- if (ck_options.format) {
- return text(ck_repeat(' ', ck_tabs));
- }
- };
- h = function(txt) {
- return String(txt).replace(/&(?!\w+;)/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
- };
- doctype = function(type) {
- type != null ? type : type = 5;
- text(ck_doctypes[type]);
- if (ck_options.format) {
- return text('\n');
- }
- };
- text = function(txt) {
- ck_buffer.push(String(txt));
- return null;
- };
- comment = function(cmt) {
- text("<!--" + cmt + "-->");
- if (ck_options.format) {
- return text('\n');
- }
- };
- tag = function() {
- var name;
- name = arguments[0];
- delete arguments[0];
- return ck_tag(name, arguments);
- };
- ck_tag = function(name, opts) {
- var o, result, _i, _j, _len, _len2;
- ck_indent();
- text("<" + name);
- for (_i = 0, _len = opts.length; _i < _len; _i++) {
- o = opts[_i];
- if (typeof o === 'object') {
- text(ck_render_attrs(o));
- }
- }
- if (__indexOf.call(ck_self_closing, name) >= 0) {
- text(' />');
- if (ck_options.format) {
- text('\n');
- }
- } else {
- text('>');
- for (_j = 0, _len2 = opts.length; _j < _len2; _j++) {
- o = opts[_j];
- switch (typeof o) {
- case 'string':
- case 'number':
- text(ck_esc(o));
- break;
- case 'function':
- if (ck_options.format) {
- text('\n');
- }
- ck_tabs++;
- result = o.call(ck_options.context);
- if (typeof result === 'string') {
- ck_indent();
- text(ck_esc(result));
- if (ck_options.format) {
- text('\n');
- }
- }
- ck_tabs--;
- ck_indent();
- }
- }
- text("</" + name + ">");
- if (ck_options.format) {
- text('\n');
- }
- }
- return null;
- };
- coffeescript = function(code) {
- return script(";(" + code + ")();");
- };
- return null;
- };
- support = 'var __slice = Array.prototype.slice;\nvar __hasProp = Object.prototype.hasOwnProperty;\nvar __indexOf = Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) {if (this[i] === item) return i;}; return -1;};\nvar __bind = function(fn, me){return function(){return fn.apply(me, arguments);};};\nvar __extends = function(child, parent) {\n for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype; child.prototype = new ctor;\n child.__super__ = parent.prototype; return child;\n};';
- skeleton = String(skeleton).replace(/function\s*\(ck_options\)\s*\{/, '').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 code, k, t, tags_here, v, _i, _j, _len, _len2, _ref, _ref2;
- options != null ? options : options = {};
- (_ref = options.locals) != null ? _ref : options.locals = {};
- if (typeof template === 'function') {
- template = String(template);
- } else if (typeof template === 'string' && (coffee != null)) {
- template = coffee.compile(template, {
- bare: true
- });
- template = "function(){" + template + "}";
- }
- tags_here = [];
- for (_i = 0, _len = tags.length; _i < _len; _i++) {
- t = tags[_i];
- if (template.indexOf(t) > -1) {
- tags_here.push(t);
- }
- }
- code = skeleton + ("var " + (tags_here.join(',')) + ";");
- for (_j = 0, _len2 = tags_here.length; _j < _len2; _j++) {
- t = tags_here[_j];
- code += "" + t + " = function(){return ck_tag('" + t + "', arguments)};";
- }
- _ref2 = options.locals;
- for (k in _ref2) {
- if (!__hasProp.call(_ref2, k)) continue;
- v = _ref2[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 tpl, _ref, _ref2, _ref3;
- options != null ? options : options = {};
- (_ref = options.context) != null ? _ref : options.context = {};
- (_ref2 = options.locals) != null ? _ref2 : options.locals = {};
- (_ref3 = options.cache) != null ? _ref3 : options.cache = true;
- if (options.locals.body != null) {
- options.context.body = options.locals.body;
- delete options.locals.body;
- }
- if (options.cache && (cache[template] != 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;
- }
-}).call(this);
View
@@ -1,16 +1,16 @@
{
"name": "coffeekup",
"description": "Markup as CoffeeScript.",
- "version": "0.2.1",
+ "version": "0.2.2",
"author": "Maurice Machado <maurice@bitbending.com>",
"contributors": [
{"name": "Maurice Machado", "email": "maurice@bitbending.com"},
{"name": "Vladimir Dronnikov", "email": "dronnikov@gmail.com"}
],
"repository": {"type": "git", "url": "http://github.com/mauricemach/coffeekup.git"},
- "dependencies": {"coffee-script": ">= 0.9.5"},
+ "dependencies": {"coffee-script": ">= 1.0.0"},
"keywords": ["template", "view", "coffeescript"],
"bin": {"coffeekup": "./bin/coffeekup.coffee"},
"directories": {"lib": "./lib"},
- "engines": {"node": ">= 0.2.5"}
+ "engines": {"node": ">= 0.2.6"}
}

0 comments on commit b260bef

Please sign in to comment.