teacup-rails 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in teacup-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alon Salant
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Teacup::Rails
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'teacup-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install teacup-rails
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module Teacup
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "teacup-rails/version"
2
+
3
+ module Teacup
4
+ module Rails
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'teacup-rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "teacup-rails"
8
+ gem.version = Teacup::Rails::VERSION
9
+ gem.authors = ["Alon Salant"]
10
+ gem.email = ["alon@salant.org"]
11
+ gem.description = %q{Makes Teacup templates written in native CoffeeScript available to Rails asset pipeline.}
12
+ gem.summary = %q{Use Teacup templates in Rails.}
13
+ gem.homepage = "http://github.com/asalant/teacup-rails"
14
+
15
+ gem.add_dependency('railties', '>= 3.1.0')
16
+ gem.add_dependency('coffee-script', '~> 2.2.0')
17
+
18
+ gem.files = `git ls-files`.split($/)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,385 @@
1
+ // Generated by CoffeeScript 1.4.0
2
+ (function() {
3
+ var Teacup, doctypes, elements, merge_elements, tagName, _fn, _fn1, _fn2, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2,
4
+ __slice = [].slice,
5
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
6
+
7
+ doctypes = {
8
+ 'default': '<!DOCTYPE html>',
9
+ '5': '<!DOCTYPE html>',
10
+ 'xml': '<?xml version="1.0" encoding="utf-8" ?>',
11
+ 'transitional': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
12
+ 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
13
+ 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
14
+ '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
15
+ 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
16
+ 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">',
17
+ 'ce': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ce-html-1.0-transitional.dtd">'
18
+ };
19
+
20
+ elements = {
21
+ regular: 'a abbr address article aside audio b bdi bdo blockquote body button\
22
+ canvas caption cite code colgroup datalist dd del details dfn div dl dt em\
23
+ fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup\
24
+ html i iframe ins kbd label legend li map mark menu meter nav noscript object\
25
+ ol optgroup option output p pre progress q rp rt ruby s samp section\
26
+ select small span strong sub summary sup table tbody td textarea tfoot\
27
+ th thead time title tr u ul video',
28
+ raw: 'script style',
29
+ "void": 'area base br col command embed hr img input keygen link meta param\
30
+ source track wbr',
31
+ obsolete: 'applet acronym bgsound dir frameset noframes isindex listing\
32
+ nextid noembed plaintext rb strike xmp big blink center font marquee multicol\
33
+ nobr spacer tt',
34
+ obsolete_void: 'basefont frame'
35
+ };
36
+
37
+ merge_elements = function() {
38
+ var a, args, element, result, _i, _j, _len, _len1, _ref;
39
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
40
+ result = [];
41
+ for (_i = 0, _len = args.length; _i < _len; _i++) {
42
+ a = args[_i];
43
+ _ref = elements[a].split(' ');
44
+ for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
45
+ element = _ref[_j];
46
+ if (__indexOf.call(result, element) < 0) {
47
+ result.push(element);
48
+ }
49
+ }
50
+ }
51
+ return result;
52
+ };
53
+
54
+ Teacup = (function() {
55
+
56
+ function Teacup() {
57
+ this.htmlOut = null;
58
+ }
59
+
60
+ Teacup.prototype.resetBuffer = function(html) {
61
+ var previous;
62
+ if (html == null) {
63
+ html = null;
64
+ }
65
+ previous = this.htmlOut;
66
+ this.htmlOut = html;
67
+ return previous;
68
+ };
69
+
70
+ Teacup.prototype.render = function() {
71
+ var args, previous, result, template;
72
+ template = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
73
+ previous = this.resetBuffer('');
74
+ try {
75
+ template.apply(null, args);
76
+ } catch (error) {
77
+ throw this.cleanStack(error);
78
+ } finally {
79
+ result = this.resetBuffer(previous);
80
+ }
81
+ return result;
82
+ };
83
+
84
+ Teacup.prototype.cede = function() {
85
+ var args;
86
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
87
+ return this.render.apply(this, args);
88
+ };
89
+
90
+ Teacup.prototype.cleanStack = (function() {
91
+ var lineExpressions, tagExpression;
92
+ lineExpressions = ['\\s*at Teacup\\.renderContents .*', '\\s*at Teacup\\.tag .*', '\\s*at Teacup.* \\[as (\\w+)\\].*', '\\s*at Teacup\\.tags\\.bound.*$'];
93
+ tagExpression = new RegExp("^" + (lineExpressions.join('\\n')), 'mg');
94
+ return function(error) {
95
+ var _ref;
96
+ error.stack = (_ref = error.stack) != null ? _ref.replace(tagExpression, ' at Teacup.$1') : void 0;
97
+ return error;
98
+ };
99
+ })();
100
+
101
+ Teacup.prototype.renderable = function(template) {
102
+ var teacup;
103
+ teacup = this;
104
+ return function() {
105
+ var args, result;
106
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
107
+ if (teacup.htmlOut === null) {
108
+ teacup.htmlOut = '';
109
+ try {
110
+ template.apply(this, args);
111
+ } catch (error) {
112
+ throw teacup.cleanStack(error);
113
+ } finally {
114
+ result = teacup.resetBuffer();
115
+ }
116
+ return result;
117
+ } else {
118
+ return template.apply(this, args);
119
+ }
120
+ };
121
+ };
122
+
123
+ Teacup.prototype.renderAttr = function(name, value) {
124
+ var k, v;
125
+ if ((value == null) || value === false) {
126
+ return '';
127
+ }
128
+ if (name === 'data' && typeof value === 'object') {
129
+ return ((function() {
130
+ var _results;
131
+ _results = [];
132
+ for (k in value) {
133
+ v = value[k];
134
+ _results.push(this.renderAttr("data-" + k, v));
135
+ }
136
+ return _results;
137
+ }).call(this)).join('');
138
+ }
139
+ if (value === true) {
140
+ value = name;
141
+ }
142
+ return " " + name + "=" + (this.quote(this.escape(value.toString())));
143
+ };
144
+
145
+ Teacup.prototype.attrOrder = ['id', 'class'];
146
+
147
+ Teacup.prototype.renderAttrs = function(obj) {
148
+ var name, result, value, _i, _len, _ref;
149
+ result = '';
150
+ _ref = this.attrOrder;
151
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
152
+ name = _ref[_i];
153
+ if (!(name in obj)) {
154
+ continue;
155
+ }
156
+ result += this.renderAttr(name, obj[name]);
157
+ delete obj[name];
158
+ }
159
+ for (name in obj) {
160
+ value = obj[name];
161
+ result += this.renderAttr(name, value);
162
+ }
163
+ return result;
164
+ };
165
+
166
+ Teacup.prototype.renderContents = function(contents) {
167
+ if (contents == null) {
168
+
169
+ } else if (typeof contents === 'function') {
170
+ return contents.call(this);
171
+ } else {
172
+ return this.text(contents);
173
+ }
174
+ };
175
+
176
+ Teacup.prototype.isSelector = function(string) {
177
+ var _ref;
178
+ return string.length > 1 && ((_ref = string[0]) === '#' || _ref === '.');
179
+ };
180
+
181
+ Teacup.prototype.parseSelector = function(selector) {
182
+ var classes, id, klass, token, _i, _len, _ref, _ref1;
183
+ id = null;
184
+ classes = [];
185
+ _ref = selector.split('.');
186
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
187
+ token = _ref[_i];
188
+ if (id) {
189
+ classes.push(token);
190
+ } else {
191
+ _ref1 = token.split('#'), klass = _ref1[0], id = _ref1[1];
192
+ if (klass !== '') {
193
+ classes.push(token);
194
+ }
195
+ }
196
+ }
197
+ return {
198
+ id: id,
199
+ classes: classes
200
+ };
201
+ };
202
+
203
+ Teacup.prototype.normalizeArgs = function(args) {
204
+ var arg, attrs, classes, contents, id, index, selector, _i, _len;
205
+ attrs = {};
206
+ selector = null;
207
+ contents = null;
208
+ for (index = _i = 0, _len = args.length; _i < _len; index = ++_i) {
209
+ arg = args[index];
210
+ if (arg != null) {
211
+ switch (typeof arg) {
212
+ case 'string':
213
+ if (index === 0 && this.isSelector(arg)) {
214
+ selector = this.parseSelector(arg);
215
+ } else {
216
+ contents = arg;
217
+ }
218
+ break;
219
+ case 'function':
220
+ case 'number':
221
+ case 'boolean':
222
+ contents = arg;
223
+ break;
224
+ case 'object':
225
+ attrs = arg;
226
+ break;
227
+ default:
228
+ console.log("Teacup: invalid argument: " + (arg.toString()));
229
+ }
230
+ }
231
+ }
232
+ if (selector != null) {
233
+ id = selector.id, classes = selector.classes;
234
+ if (id != null) {
235
+ attrs.id = id;
236
+ }
237
+ if (classes != null ? classes.length : void 0) {
238
+ attrs["class"] = classes.join(' ');
239
+ }
240
+ }
241
+ return {
242
+ attrs: attrs,
243
+ contents: contents
244
+ };
245
+ };
246
+
247
+ Teacup.prototype.tag = function() {
248
+ var args, attrs, contents, tagName, _ref;
249
+ tagName = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
250
+ _ref = this.normalizeArgs(args), attrs = _ref.attrs, contents = _ref.contents;
251
+ this.raw("<" + tagName + (this.renderAttrs(attrs)) + ">");
252
+ this.renderContents(contents);
253
+ return this.raw("</" + tagName + ">");
254
+ };
255
+
256
+ Teacup.prototype.rawTag = function() {
257
+ var args, attrs, contents, tagName, _ref;
258
+ tagName = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
259
+ _ref = this.normalizeArgs(args), attrs = _ref.attrs, contents = _ref.contents;
260
+ this.raw("<" + tagName + (this.renderAttrs(attrs)) + ">");
261
+ this.raw(contents);
262
+ return this.raw("</" + tagName + ">");
263
+ };
264
+
265
+ Teacup.prototype.selfClosingTag = function() {
266
+ var args, attrs, contents, tag, _ref;
267
+ tag = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
268
+ _ref = this.normalizeArgs(args), attrs = _ref.attrs, contents = _ref.contents;
269
+ if (contents) {
270
+ throw new Error("Teacup: <" + tag + "/> must not have content. Attempted to nest " + content);
271
+ }
272
+ return this.raw("<" + tag + (this.renderAttrs(attrs)) + " />");
273
+ };
274
+
275
+ Teacup.prototype.coffeescript = function(fn) {
276
+ return this.raw("<script type=\"text/javascript\">(function() {\n var __slice = [].slice,\n __hasProp = {}.hasOwnProperty,\n __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; };\n (" + (fn.toString()) + ")();\n})();</script>");
277
+ };
278
+
279
+ Teacup.prototype.comment = function(text) {
280
+ return this.raw("<!--" + (this.escape(text)) + "-->");
281
+ };
282
+
283
+ Teacup.prototype.doctype = function(type) {
284
+ if (type == null) {
285
+ type = 5;
286
+ }
287
+ return this.raw(doctypes[type]);
288
+ };
289
+
290
+ Teacup.prototype.ie = function(condition, contents) {
291
+ this.raw("<!--[if " + (this.escape(condition)) + "]>");
292
+ this.renderContents(contents);
293
+ return this.raw("<![endif]-->");
294
+ };
295
+
296
+ Teacup.prototype.text = function(s) {
297
+ if (this.htmlOut == null) {
298
+ throw new Error("Teacup: can't call a tag function outside a rendering context");
299
+ }
300
+ return this.htmlOut += s && this.escape(s.toString()) || '';
301
+ };
302
+
303
+ Teacup.prototype.raw = function(s) {
304
+ return this.htmlOut += s;
305
+ };
306
+
307
+ Teacup.prototype.escape = function(text) {
308
+ return text.toString().replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
309
+ };
310
+
311
+ Teacup.prototype.quote = function(value) {
312
+ return "\"" + value + "\"";
313
+ };
314
+
315
+ Teacup.prototype.tags = function() {
316
+ var bound, boundMethodNames, method, _fn, _i, _len,
317
+ _this = this;
318
+ bound = {};
319
+ boundMethodNames = [].concat('cede coffeescript comment doctype escape ie raw render renderable script tag text'.split(' '), merge_elements('regular', 'obsolete', 'raw', 'void', 'obsolete_void'));
320
+ _fn = function(method) {
321
+ return bound[method] = function() {
322
+ var args;
323
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
324
+ return _this[method].apply(_this, args);
325
+ };
326
+ };
327
+ for (_i = 0, _len = boundMethodNames.length; _i < _len; _i++) {
328
+ method = boundMethodNames[_i];
329
+ _fn(method);
330
+ }
331
+ return bound;
332
+ };
333
+
334
+ return Teacup;
335
+
336
+ })();
337
+
338
+ _ref = merge_elements('regular', 'obsolete');
339
+ _fn = function(tagName) {
340
+ return Teacup.prototype[tagName] = function() {
341
+ var args;
342
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
343
+ return this.tag.apply(this, [tagName].concat(__slice.call(args)));
344
+ };
345
+ };
346
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
347
+ tagName = _ref[_i];
348
+ _fn(tagName);
349
+ }
350
+
351
+ _ref1 = merge_elements('raw');
352
+ _fn1 = function(tagName) {
353
+ return Teacup.prototype[tagName] = function() {
354
+ var args;
355
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
356
+ return this.rawTag.apply(this, [tagName].concat(__slice.call(args)));
357
+ };
358
+ };
359
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
360
+ tagName = _ref1[_j];
361
+ _fn1(tagName);
362
+ }
363
+
364
+ _ref2 = merge_elements('void', 'obsolete_void');
365
+ _fn2 = function(tagName) {
366
+ return Teacup.prototype[tagName] = function() {
367
+ var args;
368
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
369
+ return this.selfClosingTag.apply(this, [tagName].concat(__slice.call(args)));
370
+ };
371
+ };
372
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
373
+ tagName = _ref2[_k];
374
+ _fn2(tagName);
375
+ }
376
+
377
+ if (typeof module !== "undefined" && module !== null ? module.exports : void 0) {
378
+ module.exports = new Teacup().tags();
379
+ module.exports.Teacup = Teacup;
380
+ } else {
381
+ window.teacup = new Teacup().tags();
382
+ window.teacup.Teacup = Teacup;
383
+ }
384
+
385
+ }).call(this);
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teacup-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alon Salant
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: coffee-script
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.2.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.2.0
46
+ description: Makes Teacup templates written in native CoffeeScript available to Rails
47
+ asset pipeline.
48
+ email:
49
+ - alon@salant.org
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - lib/teacup-rails.rb
60
+ - lib/teacup-rails/version.rb
61
+ - teacup-rails.gemspec
62
+ - vendor/assets/javascripts/teacup.js
63
+ homepage: http://github.com/asalant/teacup-rails
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Use Teacup templates in Rails.
87
+ test_files: []