ice 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/js/coffeekup.js ADDED
@@ -0,0 +1,217 @@
1
+ var window = {};
2
+ var cache, coffee, coffeekup, skeleton, support, tags;
3
+ var __hasProp = Object.prototype.hasOwnProperty;
4
+ if (typeof window !== "undefined" && window !== null) {
5
+ coffeekup = (window.CoffeeKup = {});
6
+ coffee = (typeof CoffeeScript !== "undefined" && CoffeeScript !== null) ? CoffeeScript : null;
7
+ } else {
8
+ coffeekup = exports;
9
+ coffee = require('coffee-script');
10
+ }
11
+ coffeekup.version = '0.2.0';
12
+ skeleton = function(ck_options) {
13
+ 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;
14
+ ck_options = (typeof ck_options !== "undefined" && ck_options !== null) ? ck_options : {};
15
+ ck_options.context = (typeof ck_options.context !== "undefined" && ck_options.context !== null) ? ck_options.context : {};
16
+ ck_options.locals = (typeof ck_options.locals !== "undefined" && ck_options.locals !== null) ? ck_options.locals : {};
17
+ ck_options.format = (typeof ck_options.format !== "undefined" && ck_options.format !== null) ? ck_options.format : false;
18
+ ck_options.autoescape = (typeof ck_options.autoescape !== "undefined" && ck_options.autoescape !== null) ? ck_options.autoescape : false;
19
+ ck_buffer = [];
20
+ ck_render_attrs = function(obj) {
21
+ var _ref, k, str, v;
22
+ str = '';
23
+ _ref = obj;
24
+ for (k in _ref) {
25
+ if (!__hasProp.call(_ref, k)) continue;
26
+ v = _ref[k];
27
+ str += (" " + (k) + "=\"" + (ck_esc(v)) + "\"");
28
+ }
29
+ return str;
30
+ };
31
+ ck_doctypes = {
32
+ '5': '<!DOCTYPE html>',
33
+ 'xml': '<?xml version="1.0" encoding="utf-8" ?>',
34
+ 'default': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
35
+ 'transitional': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
36
+ 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
37
+ 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
38
+ '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
39
+ 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
40
+ 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'
41
+ };
42
+ ck_self_closing = ['area', 'base', 'basefont', 'br', 'hr', 'img', 'input', 'link', 'meta'];
43
+ ck_esc = function(txt) {
44
+ return ck_options.autoescape ? h(txt) : String(txt);
45
+ };
46
+ ck_tabs = 0;
47
+ ck_repeat = function(string, count) {
48
+ return Array(count + 1).join(string);
49
+ };
50
+ ck_indent = function() {
51
+ if (ck_options.format) {
52
+ return text(ck_repeat(' ', ck_tabs));
53
+ }
54
+ };
55
+ h = function(txt) {
56
+ return String(txt).replace(/&(?!\w+;)/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
57
+ };
58
+ doctype = function(type) {
59
+ type = (typeof type !== "undefined" && type !== null) ? type : 5;
60
+ text(ck_doctypes[type]);
61
+ if (ck_options.format) {
62
+ return text('\n');
63
+ }
64
+ };
65
+ text = function(txt) {
66
+ ck_buffer.push(String(txt));
67
+ return null;
68
+ };
69
+ comment = function(cmt) {
70
+ text("<!--" + (cmt) + "-->");
71
+ if (ck_options.format) {
72
+ return text('\n');
73
+ }
74
+ };
75
+ tag = function() {
76
+ var name;
77
+ name = arguments[0];
78
+ delete arguments[0];
79
+ return ck_tag(name, arguments);
80
+ };
81
+ ck_tag = function(name, opts) {
82
+ var _i, _len, _ref, o, result;
83
+ ck_indent();
84
+ text("<" + (name));
85
+ _ref = opts;
86
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
87
+ o = _ref[_i];
88
+ if (typeof o === 'object') {
89
+ text(ck_render_attrs(o));
90
+ }
91
+ }
92
+ if ((function(){ for (var _i=0, _len=ck_self_closing.length; _i<_len; _i++) { if (ck_self_closing[_i] === name) return true; } return false; }).call(this)) {
93
+ text(' />');
94
+ if (ck_options.format) {
95
+ text('\n');
96
+ }
97
+ } else {
98
+ text('>');
99
+ _ref = opts;
100
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
101
+ o = _ref[_i];
102
+ switch (typeof o) {
103
+ case 'string':
104
+ case 'number':
105
+ text(ck_esc(o));
106
+ break;
107
+ case 'function':
108
+ if (ck_options.format) {
109
+ text('\n');
110
+ }
111
+ ck_tabs++;
112
+ result = o.call(ck_options.context);
113
+ if (typeof result === 'string') {
114
+ ck_indent();
115
+ text(ck_esc(result));
116
+ if (ck_options.format) {
117
+ text('\n');
118
+ }
119
+ }
120
+ ck_tabs--;
121
+ ck_indent();
122
+ break;
123
+ }
124
+ }
125
+ text("</" + (name) + ">");
126
+ if (ck_options.format) {
127
+ text('\n');
128
+ }
129
+ }
130
+ return null;
131
+ };
132
+ coffeescript = function(code) {
133
+ return script(";(" + (code) + ")();");
134
+ };
135
+ return null;
136
+ };
137
+ support = 'var __slice = Array.prototype.slice;\nvar __hasProp = Object.prototype.hasOwnProperty;\nvar __bind = function(func, context) {return function(){ return func.apply(context, arguments); };};';
138
+ skeleton = String(skeleton).replace('function (ck_options) {', '').replace(/return null;\s*\}$/, '');
139
+ skeleton = support + skeleton;
140
+ 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('|');
141
+ coffeekup.compile = function(template, options) {
142
+ var _i, _len, _ref, code, k, t, tags_here, v;
143
+ options = (typeof options !== "undefined" && options !== null) ? options : {};
144
+ options.locals = (typeof options.locals !== "undefined" && options.locals !== null) ? options.locals : {};
145
+ if (typeof template === 'function') {
146
+ template = String(template);
147
+ } else if (typeof template === 'string' && (typeof coffee !== "undefined" && coffee !== null)) {
148
+ template = coffee.compile(template, {
149
+ 'noWrap': 'noWrap'
150
+ });
151
+ template = ("function(){" + (template) + "}");
152
+ }
153
+ tags_here = [];
154
+ _ref = tags;
155
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
156
+ t = _ref[_i];
157
+ if (template.indexOf(t) > -1) {
158
+ tags_here.push(t);
159
+ }
160
+ }
161
+ code = skeleton.replace(', text;', ", text, " + (tags_here.join(',')) + ";");
162
+ code += 'var arrayCreator = Array;';
163
+ _ref = tags_here;
164
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
165
+ t = _ref[_i];
166
+ code += ("" + (t) + " = function(){return ck_tag('" + (t) + "', arguments)};");
167
+ }
168
+ _ref = options.locals;
169
+ for (k in _ref) {
170
+ if (!__hasProp.call(_ref, k)) continue;
171
+ v = _ref[k];
172
+ if (typeof v === 'function') {
173
+ code += ("var " + (k) + " = " + (v) + ";");
174
+ } else {
175
+ code += ("var " + (k) + " = " + (JSON.stringify(v)) + ";");
176
+ }
177
+ }
178
+ if (options.dynamic_locals) {
179
+ code += 'with(ck_options.locals){';
180
+ }
181
+ code += ("(" + (template) + ").call(ck_options.context);");
182
+ if (options.dynamic_locals) {
183
+ code += '}';
184
+ }
185
+ code += "return ck_buffer.join('');";
186
+ return new Function('ck_options', code);
187
+ };
188
+ cache = {};
189
+ coffeekup.render = function(template, options) {
190
+ var _ref, tpl;
191
+ options = (typeof options !== "undefined" && options !== null) ? options : {};
192
+ options.context = (typeof options.context !== "undefined" && options.context !== null) ? options.context : {};
193
+ options.locals = (typeof options.locals !== "undefined" && options.locals !== null) ? options.locals : {};
194
+ options.cache = (typeof options.cache !== "undefined" && options.cache !== null) ? options.cache : true;
195
+ if (typeof (_ref = options.locals.body) !== "undefined" && _ref !== null) {
196
+ options.context.body = options.locals.body;
197
+ delete options.locals.body;
198
+ }
199
+ if (options.cache && (typeof (_ref = cache[template]) !== "undefined" && _ref !== null)) {
200
+ tpl = cache[template];
201
+ } else if (options.cache) {
202
+ tpl = (cache[template] = coffeekup.compile(template, options));
203
+ } else {
204
+ tpl = coffeekup.compile(template, options);
205
+ }
206
+ return tpl(options);
207
+ };
208
+ if (!(typeof window !== "undefined" && window !== null)) {
209
+ coffeekup.adapters = {
210
+ simple: function(template, data) {
211
+ return coffeekup.render(template, {
212
+ context: data
213
+ });
214
+ }
215
+ };
216
+ coffeekup.adapters.meryl = coffeekup.adapters.simple;
217
+ }
@@ -0,0 +1,23 @@
1
+ linkTo = (label, link, opts) ->
2
+ if (! link)
3
+ link = label
4
+ a href:link, -> label
5
+
6
+ navBar = (args...)->
7
+ if args.length == 2
8
+ opts = args.shift()
9
+ else
10
+ opts = {}
11
+ f = args[0]
12
+
13
+ navWrap = opts.navWrap || ul
14
+ linkWrap = opts.linkWrap || li
15
+
16
+ methods =
17
+ linkTo: (name, href)->
18
+ if (! href)
19
+ href = name
20
+ linkWrap -> linkTo name, href
21
+
22
+ navWrap ->
23
+ f(methods)
@@ -0,0 +1,37 @@
1
+ var linkTo, navBar;
2
+ var __slice = Array.prototype.slice;
3
+ linkTo = function(label, link, opts) {
4
+ if (!link) {
5
+ link = label;
6
+ }
7
+ return a({
8
+ href: link
9
+ }, function() {
10
+ return label;
11
+ });
12
+ };
13
+ navBar = function() {
14
+ var args, f, linkWrap, methods, navWrap, opts;
15
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
16
+ if (args.length === 2) {
17
+ opts = args.shift();
18
+ } else {
19
+ opts = {};
20
+ }
21
+ f = args[0];
22
+ navWrap = opts.navWrap || ul;
23
+ linkWrap = opts.linkWrap || li;
24
+ methods = {
25
+ linkTo: function(name, href) {
26
+ if (!href) {
27
+ href = name;
28
+ }
29
+ return linkWrap(function() {
30
+ return linkTo(name, href);
31
+ });
32
+ }
33
+ };
34
+ return navWrap(function() {
35
+ return f(methods);
36
+ });
37
+ };
File without changes
data/lib/ice.rb CHANGED
@@ -7,9 +7,12 @@ require 'ice/railtie'
7
7
  require 'ice/cube_helpers'
8
8
  require 'rails'
9
9
 
10
- require 'ice/eco_template/handler'
10
+ require 'ice/handlers/eco/handler'
11
+ require 'ice/handlers/coffeekup/handler'
11
12
 
12
- IceJavascriptHelpers = []
13
+ IceJavascriptHelpers = []
13
14
  IceCoffeescriptHelpers = []
14
15
 
15
- ActionView::Template.register_template_handler :eco, Ice::EcoTemplate::Handler
16
+
17
+ ActionView::Template.register_template_handler :coffeekup, Ice::Handlers::Coffeekup
18
+ ActionView::Template.register_template_handler :eco, Ice::Handlers::Eco
@@ -1,6 +1,5 @@
1
1
  module Ice
2
- module EcoTemplate
3
- module GeneratedHelpers
2
+ module GeneratedHelpers
4
3
  def self.get_routes
5
4
  coffeescript = ""
6
5
  Ice::BaseCube.subclasses.map(&:name).each do |cube_model_name|
@@ -26,6 +25,5 @@ module Ice
26
25
  coffeescript
27
26
  end
28
27
 
29
- end
30
28
  end
31
29
  end
@@ -0,0 +1,39 @@
1
+ require "ice/generated_helpers"
2
+
3
+ module Ice
4
+ module Handlers
5
+ module Base
6
+ def self.variables
7
+ <<-VARIABLES
8
+ variable_names = controller.instance_variable_names
9
+ variable_names -= %w[@template]
10
+ if controller.respond_to?(:protected_instance_variables)
11
+ variable_names -= controller.protected_instance_variables
12
+ end
13
+
14
+ variables = {}
15
+ variable_names.each do |name|
16
+ variables[name.sub(/^@/, "")] = controller.instance_variable_get(name)
17
+ end
18
+ VARIABLES
19
+ end
20
+
21
+ def self.convert_template(template_text)
22
+ V8::C::Locker() do
23
+ context = V8::Context.new
24
+
25
+ IceJavascriptHelpers.each do |helper|
26
+ context.eval(helper)
27
+ end
28
+ IceCoffeescriptHelpers.each do |helper|
29
+ context.eval CoffeeScript.compile(helper, :bare => true)
30
+ end
31
+
32
+ context.eval CoffeeScript.compile(GeneratedHelpers.get_routes, :bare => true)
33
+ yield context
34
+
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ require "ice/handlers/base"
2
+ require 'v8'
3
+
4
+ module Ice
5
+ module Handlers
6
+ module Coffeekup
7
+ def self.convert_template(template_text, vars = {})
8
+ Base.convert_template(template_text) do |context|
9
+ coffeescript_file = "#{File.dirname(__FILE__)}/../../../../js/coffee-script.js"
10
+ coffeekup_file = "#{File.dirname(__FILE__)}/../../../../js/coffeekup.js"
11
+
12
+ context.eval(open(coffeescript_file).read)
13
+ context.eval(open(coffeekup_file).read)
14
+
15
+ coffeekup_helpers_file = "#{File.dirname(__FILE__)}/../../../../js/lib/coffeekup-path-helper.coffee"
16
+ combo = open(coffeekup_helpers_file).read + "\n" + template_text.sub(/^(\s)*/, "")
17
+ template = context["coffeekup"]["compile"].call(combo)
18
+ template.call({context: vars.to_ice})
19
+ end
20
+ end
21
+
22
+ def self.call(template)
23
+ <<-COFFEEKUP
24
+ template_source = <<-COFFEEKUP_TEMPLATE
25
+ #{template.source}
26
+ COFFEEKUP_TEMPLATE
27
+ #{Base.variables}
28
+
29
+ Ice::Handlers::Coffeekup.convert_template(template_source, variables.merge(local_assigns))
30
+ COFFEEKUP
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ require "ice/handlers/base"
2
+ require 'eco'
3
+ require 'v8'
4
+
5
+ module Ice
6
+ module Handlers
7
+ module Eco
8
+ def self.convert_template(template_text, vars = {})
9
+ Base.convert_template(template_text) do |context|
10
+ helpers = "#{File.dirname(__FILE__)}/../../../../js/lib/eco-path-helper.js"
11
+
12
+ context.eval(open(helpers).read)
13
+ context.eval(::Eco::Source.combined_contents)
14
+ template = context["eco"]["compile"].call(template_text)
15
+ template.call(vars.to_ice)
16
+ end
17
+ end
18
+
19
+ def self.call(template)
20
+ <<-ECO
21
+ template_source = <<-ECO_TEMPLATE
22
+ #{template.source}
23
+ ECO_TEMPLATE
24
+
25
+ #{Base.variables}
26
+
27
+ Ice::Handlers::Eco.convert_template(template_source, variables.merge(local_assigns))
28
+ ECO
29
+ end
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ice
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.4
5
+ version: 0.5.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nate Kidwell
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-29 00:00:00 -04:00
13
+ date: 2011-07-02 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -48,16 +48,21 @@ files:
48
48
  - lib/ice/cube_association.rb
49
49
  - lib/ice/cube_helpers.rb
50
50
  - lib/ice/cubeable.rb
51
- - lib/ice/eco_template/base.rb
52
- - lib/ice/eco_template/generated_helpers.rb
53
- - lib/ice/eco_template/handler.rb
51
+ - lib/ice/generated_helpers.rb
52
+ - lib/ice/handlers/base.rb
53
+ - lib/ice/handlers/coffeekup/handler.rb
54
+ - lib/ice/handlers/eco/handler.rb
54
55
  - lib/ice/railtie.rb
55
56
  - lib/ice.rb
56
57
  - js/Cakefile
58
+ - js/coffee-script.js
59
+ - js/coffeekup.js
60
+ - js/lib/coffeekup-path-helper.coffee
61
+ - js/lib/coffeekup-path-helper.js
62
+ - js/lib/eco-path-helper.coffee
63
+ - js/lib/eco-path-helper.js
57
64
  - js/lib/form-tag-inputs.coffee
58
65
  - js/lib/form-tag-inputs.js
59
- - js/lib/path-helper.coffee
60
- - js/lib/path-helper.js
61
66
  - MIT-LICENSE
62
67
  - Rakefile
63
68
  - Gemfile