thorax-rails 0.0.0 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/README.md +69 -0
  2. data/Rakefile +2 -2
  3. data/lib/generators/thorax/install/install_generator.rb +24 -6
  4. data/lib/generators/thorax/install/templates/collection-view.coffee +1 -0
  5. data/lib/generators/thorax/install/templates/collection.coffee +1 -0
  6. data/lib/generators/thorax/install/templates/init.js +34 -0
  7. data/lib/generators/thorax/install/templates/layout-view.coffee +1 -0
  8. data/lib/generators/thorax/install/templates/model.coffee +1 -0
  9. data/lib/generators/thorax/install/templates/namespace.coffee +4 -0
  10. data/lib/generators/thorax/install/templates/root.coffee +11 -0
  11. data/lib/generators/thorax/install/templates/root.hbs +1 -0
  12. data/lib/generators/thorax/install/templates/view.coffee +1 -0
  13. data/lib/generators/thorax/model/model_generator.rb +23 -0
  14. data/lib/generators/thorax/model/templates/collection.coffee +11 -0
  15. data/lib/generators/thorax/model/templates/model.coffee +7 -0
  16. data/lib/generators/thorax/{thorax_helpers.rb → resource_helpers.rb} +12 -8
  17. data/lib/generators/thorax/router/router_generator.rb +44 -0
  18. data/lib/generators/thorax/router/templates/router.coffee +20 -0
  19. data/lib/generators/thorax/router/templates/template.hbs +2 -0
  20. data/lib/generators/thorax/router/templates/view.coffee +3 -0
  21. data/lib/generators/thorax/view/templates/template.hbs +2 -0
  22. data/lib/generators/thorax/view/templates/view.coffee +3 -0
  23. data/lib/generators/thorax/view/view_generator.rb +40 -0
  24. data/lib/tasks/thorax-rails_tasks.rake +4 -0
  25. data/lib/{thorax.rb → thorax-rails.rb} +1 -1
  26. data/vendor/assets/javascripts/handlebars.runtime.js +362 -0
  27. data/vendor/assets/javascripts/{undersccore.js → underscore.js} +0 -0
  28. metadata +42 -22
  29. data/README.rdoc +0 -19
  30. data/vendor/assets/javascripts/handlebars.js +0 -45
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ #thorax-rails
2
+
3
+ The thorax gem includes Thorax.js and its dependencies (backbone, underscore, and handlebars) in your Rails asset pipeline. A few handy generators take care the boilerplate code so you don't have to. Enjoy!
4
+
5
+ ## Rails setup
6
+ This gem requires the use of rails 3.1 and greater, coffeescript and the new rails asset pipeline provided by sprockets.
7
+
8
+ ### Installation
9
+
10
+ In your Gemfile, add this line:
11
+
12
+ gem "thorax-rails", "~> 0.1.0"
13
+
14
+ Then run the following commands:
15
+
16
+ bundle install
17
+ rails g thorax:install
18
+
19
+
20
+ Running `rails g thorax:install` will create the following directory structure under `app/assets/javascripts/`:
21
+
22
+ models/
23
+ collections/
24
+ routers/
25
+ templates/
26
+ views/
27
+
28
+ It will also create view, model, collection, and router files that your app will extend. These are great places to define app-wide behaviors.
29
+
30
+ ## Generators
31
+ thorax-rails currently provides 3 simple generators to help get you started using Thorax.js with rails 3.1 and greater.
32
+ The generators will only create client side code (javascript).
33
+
34
+ ### Model Generator
35
+
36
+ rails g thorax:model ModelName field:type field:type
37
+
38
+ This generator creates thorax models and collections in `app/assets/javascript/models` and `app/assets/javascripts/collections` respectively.
39
+
40
+ ### Routers
41
+
42
+ rails g thorax:router ModelName action action
43
+
44
+ This generator creates a thorax router with corresponding views and templates for the given actions provided.
45
+
46
+ ### Views
47
+
48
+ rails g thorax:view ModelName viewName viewName
49
+
50
+ This generator creates views and their associated templates
51
+
52
+ ### Scaffolds
53
+
54
+ Coming soon! I am currently developing a full CRUD scaffold which will create views and wire up a router for all the RESTful actions for a given model. Watch for version 2!
55
+
56
+
57
+ ##Contributing to thorax-rails
58
+
59
+ This gem is still in development. I would love to hear about any bugs you run into, or tips on how it could be improved. If you would like to contribute directly, please fork the project and start a new branch with a helpful name. Please write tests for your changes.
60
+
61
+ ##Acknowledgments
62
+
63
+ This gem was written with help from the authors of [Thorax](https://github.com/walmartlabs/thorax), and was heavily influenced by the wonderful [backbone-rails gem](https://github.com/codebrew/backbone-rails)
64
+
65
+ ##Copyright
66
+
67
+ Copyright (c) 2013 WalmartLabs. See MIT-LICENSE for
68
+ further details.
69
+
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ require 'rdoc/task'
10
10
 
11
11
  RDoc::Task.new(:rdoc) do |rdoc|
12
12
  rdoc.rdoc_dir = 'rdoc'
13
- rdoc.title = 'BackboneRails'
13
+ rdoc.title = 'ThoraxRails'
14
14
  rdoc.options << '--line-numbers' << '--inline-source'
15
15
  rdoc.rdoc_files.include('README.md')
16
16
  rdoc.rdoc_files.include('lib/**/*.rb')
@@ -36,7 +36,7 @@ namespace :thorax do
36
36
  'handlebars.js' => 'https://raw.github.com/wycats/handlebars.js/master/lib/handlebars.js',
37
37
  'thorax.js' => 'https://github.com/components/thorax/blob/master/thorax.js'
38
38
  }
39
- vendor_dir = "vendor/assets/javascripts/thorax"
39
+ vendor_dir = "vendor/assets/javascripts"
40
40
 
41
41
  require 'open-uri'
42
42
  files.each do |local, remote|
@@ -1,4 +1,4 @@
1
- require 'generators/thorax/thorax_helpers'
1
+ require 'generators/thorax/resource_helpers'
2
2
 
3
3
  module Thorax
4
4
  module Generators
@@ -7,24 +7,42 @@ module Thorax
7
7
 
8
8
  source_root File.expand_path("../templates", __FILE__)
9
9
 
10
- desc "This generator installs thorax.js with a default folder layout in app/assets/javascripts/thorax"
10
+ desc "This generator a directory sturcture for thorax in app/assets/javascripts"
11
11
 
12
12
  class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
13
13
  :desc => "Skip Git ignores and keeps"
14
14
 
15
+
15
16
  def inject_thorax
16
17
  inject_into_file "app/assets/javascripts/application.js", :before => "//= require_tree" do
17
- "//= require underscore\n//= require backbone\n//= require handlebars\n//= require thorax\n"
18
+ "//= require underscore\n//= require backbone\n//= require handlebars.runtime\n//= require thorax\n//= require #{application_name.underscore}\n//= require view\n//= require collection-view\n//= require layout-view\n//= require model\n//= require collection\n//= require_tree ./templates\n//= require_tree ./models\n//= require_tree ./collections\n//= require_tree ./views\n//= require_tree ./routers\n//= require ./templates/root\n"
18
19
  end
19
20
  end
20
21
 
21
22
  def create_dir_layout
22
- %W{routers models views templates}.each do |dir|
23
- empty_directory "app/assets/javascripts/thorax/#{dir}"
24
- create_file "app/assets/javascripts/thorax/#{dir}/.gitkeep" unless options[:skip_git]
23
+ %W{collections routers models views templates}.each do |dir|
24
+ empty_directory "app/assets/javascripts/#{dir}"
25
+ create_file "app/assets/javascripts/#{dir}/.gitkeep" unless options[:skip_git]
25
26
  end
26
27
  end
27
28
 
29
+ def create_class_files
30
+ template "collection-view.coffee", "app/assets/javascripts/collection-view.js.coffee"
31
+ template "collection.coffee", "app/assets/javascripts/collection.js.coffee"
32
+ template "layout-view.coffee", "app/assets/javascripts/layout-view.js.coffee"
33
+ template "model.coffee", "app/assets/javascripts/model.js.coffee"
34
+ template "view.coffee", "app/assets/javascripts/view.js.coffee"
35
+ template "root.coffee", "app/assets/javascripts/views/root.js.coffee"
36
+ template "root.hbs", "app/assets/javascripts/templates/root.hbs"
37
+ template "namespace.coffee", "app/assets/javascripts/#{application_name.underscore}.js.coffee"
38
+ end
39
+
40
+ def initialize_thorax
41
+ template "init.js", "#{destination_root}/app/assets/javascripts/#{application_name.underscore}_initializer.js.coffee"
42
+ append_file "app/assets/javascripts/application.js", File.open("#{destination_root}/app/assets/javascripts/#{application_name.underscore}_initializer.js.coffee", "rb").read
43
+ File.delete("#{destination_root}/app/assets/javascripts/#{application_name.underscore}_initializer.js.coffee")
44
+ end
45
+
28
46
  end
29
47
  end
30
48
  end
@@ -0,0 +1 @@
1
+ class window.<%= js_app_name %>.CollectionView extends Thorax.CollectionView
@@ -0,0 +1 @@
1
+ class window.<%= js_app_name %>.Collection extends Thorax.Collection
@@ -0,0 +1,34 @@
1
+ function initialize(complete) {
2
+ // Configure Backbone to talk with Rails
3
+ Backbone.ajax = function() {
4
+ Backbone.$.ajaxSetup.call(Backbone.$, {
5
+ beforeSend: function(jqXHR){
6
+ var token = $("meta[name='csrf-token']").attr('content');
7
+ jqXHR.setRequestHeader('X-CSRF-Token', token);
8
+ }
9
+ });
10
+ return Backbone.$.ajax.apply(Backbone.$, arguments);
11
+ };
12
+ $(function() {
13
+ Backbone.history.start({
14
+ pushState: false,
15
+ root: '/',
16
+ silent: true
17
+ });
18
+
19
+ // RootView may use link or url helpers which
20
+ // depend on Backbone history being setup
21
+ // so need to wait to loadUrl() (which will)
22
+ // actually execute the route
23
+ <%= js_app_name %>.RootView.getInstance(document.body);
24
+
25
+ complete(function() {
26
+ Backbone.history.loadUrl();
27
+ });
28
+ });
29
+ }
30
+
31
+ initialize(function(next) {
32
+ // things to do when your application is loaded!
33
+ next();
34
+ });
@@ -0,0 +1 @@
1
+ class window.<%= js_app_name %>.LayoutView extends Thorax.LayoutView
@@ -0,0 +1 @@
1
+ class window.<%= js_app_name %>.Model extends Thorax.Model
@@ -0,0 +1,4 @@
1
+ window.<%=js_app_name%> =
2
+ Views: {}
3
+ Models: {}
4
+ Collections: {}
@@ -0,0 +1,11 @@
1
+ class <%= js_app_name %>.RootView extends <%= js_app_name %>.LayoutView
2
+ name: "root"
3
+ template: HandlebarsTemplates["root"]
4
+
5
+ do ->
6
+ instance = null
7
+ <%= js_app_name %>.RootView.getInstance = (target) ->
8
+ if not instance
9
+ instance = new <%= js_app_name %>.RootView
10
+ instance.appendTo target || document.body
11
+ instance
@@ -0,0 +1 @@
1
+ {{layout-element}}
@@ -0,0 +1 @@
1
+ class window.<%= js_app_name %>.View extends Thorax.View
@@ -0,0 +1,23 @@
1
+ require 'generators/thorax/resource_helpers'
2
+
3
+ module Thorax
4
+ module Generators
5
+ class ModelGenerator < Rails::Generators::NamedBase
6
+ include Thorax::Generators::ResourceHelpers
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+ desc "This generator creates a thorax model"
10
+
11
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
12
+
13
+ def create_thorax_model
14
+ template "model.coffee", "#{thorax_path}/models/#{file_name}.js.coffee"
15
+ end
16
+
17
+ def create_thorax_collection
18
+ template "collection.coffee", "#{thorax_path}/collections/#{file_name}.js.coffee"
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ class <%=collection_namespace%>Collection extends <%= js_app_name %>.Collection
2
+ name: '<%= plural_name %>'
3
+ model: <%=model_namespace%>Model
4
+ url: '/<%= plural_table_name %>'
5
+
6
+ do ->
7
+ instance = null
8
+ <%=collection_namespace%>Collection.getInstance = ->
9
+ if not instance
10
+ instance = new <%=collection_namespace%>Collection
11
+ instance
@@ -0,0 +1,7 @@
1
+ class <%=model_namespace%>Model extends <%= js_app_name %>.Model
2
+ name: '<%= singular_table_name %>'
3
+
4
+ defaults:
5
+ <% attributes.each do |attribute| -%>
6
+ <%= attribute.name %>: null
7
+ <% end -%>
@@ -1,13 +1,17 @@
1
1
  module Thorax
2
2
  module Generators
3
- module ThoraxHelpers
3
+ module ResourceHelpers
4
4
 
5
5
  def thorax_path
6
- "app/assets/javascripts/thorax"
6
+ "app/assets/javascripts"
7
+ end
8
+
9
+ def template_path
10
+ "app/assets/javascripts/templates"
7
11
  end
8
12
 
9
13
  def model_namespace
10
- [js_app_name, "Models", class_name].join(".")
14
+ [js_app_name, class_name].join(".")
11
15
  end
12
16
 
13
17
  def singular_model_name
@@ -19,19 +23,19 @@ module Thorax
19
23
  end
20
24
 
21
25
  def collection_namespace
22
- [js_app_name, "Collections", plural_name.camelize].join(".")
26
+ [js_app_name, plural_name.camelize].join(".")
23
27
  end
24
28
 
25
29
  def view_namespace
26
- [js_app_name, "Views", plural_name.camelize].join(".")
30
+ [js_app_name, plural_name.camelize].join(".")
27
31
  end
28
32
 
29
33
  def router_namespace
30
- [js_app_name, "Routers", plural_name.camelize].join(".")
34
+ [js_app_name, plural_name.camelize].join(".")
31
35
  end
32
36
 
33
- def jst(action)
34
- "backbone/templates/#{plural_name}/#{action}"
37
+ def hbs(action)
38
+ "#{plural_name}/#{action}"
35
39
  end
36
40
 
37
41
  def js_app_name
@@ -0,0 +1,44 @@
1
+ require 'generators/thorax/resource_helpers'
2
+
3
+ module Thorax
4
+ module Generators
5
+ class RouterGenerator < Rails::Generators::NamedBase
6
+ include Thorax::Generators::ResourceHelpers
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+ desc "This generator creates a thorax router with views and templates for the provided actions"
10
+
11
+ argument :actions, :type => :array, :default => [], :banner => "action action"
12
+
13
+ RESERVED_JS_WORDS = %W{
14
+ break case catch continue debugger default delete do else finally for
15
+ function if in instanceof new return switch this throw try typeof var void while with
16
+ }
17
+
18
+ def validate_no_reserved_words
19
+ actions.each do |action|
20
+ if RESERVED_JS_WORDS.include? action
21
+ raise Thor::Error, "The name '#{action}' is reserved by javascript " <<
22
+ "Please choose an alternative action name and run this generator again."
23
+ end
24
+ end
25
+ end
26
+
27
+ def create_router_files
28
+ template 'router.coffee', File.join(thorax_path, "routers", class_path, "#{file_name}.js.coffee")
29
+ end
30
+
31
+ def create_view_files
32
+ actions.each do |action|
33
+ @action = action
34
+ @view_path = File.join(thorax_path, "views", plural_name, "#{@action}.js.coffee")
35
+ @hbs_path = File.join(template_path, plural_name, "#{@action}.hbs")
36
+
37
+ template "view.coffee", @view_path
38
+ template "template.hbs", @hbs_path
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ class <%= router_namespace %>Router extends Backbone.Router
2
+ initialize: (options) ->
3
+ @<%=plural_name%> = new <%=collection_namespace%>Collection.getInstance()
4
+ if !@<%=plural_name%>._fetched
5
+ @<%=plural_name%>.fetch()
6
+ @<%=plural_name%>._fetched = true
7
+
8
+ routes:
9
+ <% actions.each do |action| -%>
10
+ "<%= action %>": "<%= action %>"
11
+ <% end -%>
12
+
13
+ <% actions.each do |action| -%>
14
+ <%= action %>: ->
15
+ view = new <%= "#{view_namespace}#{action.camelize}View()" %>
16
+ <%= js_app_name %>.RootView.getInstance().setView view
17
+ <% end -%>
18
+
19
+ # Activate the router!
20
+ new <%= router_namespace %>Router
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= @action %></h1>
2
+ <p>Find me in <%= @hbs_path %></p>
@@ -0,0 +1,3 @@
1
+ class <%=view_namespace%><%=@action.camelize%>View extends <%= js_app_name %>.View
2
+ name: "<%=plural_model_name%>/<%=@action%>",
3
+ template: HandlebarsTemplates["<%= hbs @action %>"]
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= @action %></h1>
2
+ <p>Find me in <%= @hbs_path %></p>
@@ -0,0 +1,3 @@
1
+ <%=view_namespace%><%=@action.camelize%>View extends <%= js_app_name %>.View
2
+ name: "<%=view_namespace%>/<%=@action.camelize%>",
3
+ template: HandlebarsTemplates["<%= hbs @action %>"]
@@ -0,0 +1,40 @@
1
+ require 'generators/thorax/resource_helpers'
2
+
3
+ module Thorax
4
+ module Generators
5
+ class ViewGenerator < Rails::Generators::NamedBase
6
+ include Thorax::Generators::ResourceHelpers
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+ desc "This generator creates thorax views with associated templates for the provided model and actions"
10
+
11
+ argument :actions, :type => :array, :default => [], :banner => "action action"
12
+
13
+ RESERVED_JS_WORDS = %W{
14
+ break case catch continue debugger default delete do else finally for
15
+ function if in instanceof new return switch this throw try typeof var void while with
16
+ }
17
+
18
+ def validate_no_reserved_words
19
+ actions.each do |action|
20
+ if RESERVED_JS_WORDS.include? action
21
+ raise Thor::Error, "The name '#{action}' is reserved by javascript " <<
22
+ "Please choose an alternative action name and run this generator again."
23
+ end
24
+ end
25
+ end
26
+
27
+ def create_view_files
28
+ actions.each do |action|
29
+ @action = action
30
+ @view_path = File.join(thorax_path, "views", plural_name, "#{@action}.js.coffee")
31
+ @hbs_path = File.join(template_path, plural_name, "#{@action}.hbs")
32
+
33
+ template "view.coffee", @view_path
34
+ template "template.hbs", @hbs_path
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :thorax-rails do
3
+ # # Task goes here
4
+ # end
@@ -1,6 +1,6 @@
1
1
  require 'rails'
2
2
 
3
- module Thorax
3
+ module ThoraxRails
4
4
  class Engine < Rails::Engine
5
5
  end
6
6
  end
@@ -0,0 +1,362 @@
1
+ /*
2
+
3
+ Copyright (C) 2011 by Yehuda Katz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ */
24
+
25
+ // lib/handlebars/browser-prefix.js
26
+ var Handlebars = {};
27
+
28
+ (function(Handlebars, undefined) {
29
+ ;
30
+ // lib/handlebars/base.js
31
+
32
+ Handlebars.VERSION = "1.0.0";
33
+ Handlebars.COMPILER_REVISION = 4;
34
+
35
+ Handlebars.REVISION_CHANGES = {
36
+ 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
37
+ 2: '== 1.0.0-rc.3',
38
+ 3: '== 1.0.0-rc.4',
39
+ 4: '>= 1.0.0'
40
+ };
41
+
42
+ Handlebars.helpers = {};
43
+ Handlebars.partials = {};
44
+
45
+ var toString = Object.prototype.toString,
46
+ functionType = '[object Function]',
47
+ objectType = '[object Object]';
48
+
49
+ Handlebars.registerHelper = function(name, fn, inverse) {
50
+ if (toString.call(name) === objectType) {
51
+ if (inverse || fn) { throw new Handlebars.Exception('Arg not supported with multiple helpers'); }
52
+ Handlebars.Utils.extend(this.helpers, name);
53
+ } else {
54
+ if (inverse) { fn.not = inverse; }
55
+ this.helpers[name] = fn;
56
+ }
57
+ };
58
+
59
+ Handlebars.registerPartial = function(name, str) {
60
+ if (toString.call(name) === objectType) {
61
+ Handlebars.Utils.extend(this.partials, name);
62
+ } else {
63
+ this.partials[name] = str;
64
+ }
65
+ };
66
+
67
+ Handlebars.registerHelper('helperMissing', function(arg) {
68
+ if(arguments.length === 2) {
69
+ return undefined;
70
+ } else {
71
+ throw new Error("Missing helper: '" + arg + "'");
72
+ }
73
+ });
74
+
75
+ Handlebars.registerHelper('blockHelperMissing', function(context, options) {
76
+ var inverse = options.inverse || function() {}, fn = options.fn;
77
+
78
+ var type = toString.call(context);
79
+
80
+ if(type === functionType) { context = context.call(this); }
81
+
82
+ if(context === true) {
83
+ return fn(this);
84
+ } else if(context === false || context == null) {
85
+ return inverse(this);
86
+ } else if(type === "[object Array]") {
87
+ if(context.length > 0) {
88
+ return Handlebars.helpers.each(context, options);
89
+ } else {
90
+ return inverse(this);
91
+ }
92
+ } else {
93
+ return fn(context);
94
+ }
95
+ });
96
+
97
+ Handlebars.K = function() {};
98
+
99
+ Handlebars.createFrame = Object.create || function(object) {
100
+ Handlebars.K.prototype = object;
101
+ var obj = new Handlebars.K();
102
+ Handlebars.K.prototype = null;
103
+ return obj;
104
+ };
105
+
106
+ Handlebars.logger = {
107
+ DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
108
+
109
+ methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
110
+
111
+ // can be overridden in the host environment
112
+ log: function(level, obj) {
113
+ if (Handlebars.logger.level <= level) {
114
+ var method = Handlebars.logger.methodMap[level];
115
+ if (typeof console !== 'undefined' && console[method]) {
116
+ console[method].call(console, obj);
117
+ }
118
+ }
119
+ }
120
+ };
121
+
122
+ Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
123
+
124
+ Handlebars.registerHelper('each', function(context, options) {
125
+ var fn = options.fn, inverse = options.inverse;
126
+ var i = 0, ret = "", data;
127
+
128
+ var type = toString.call(context);
129
+ if(type === functionType) { context = context.call(this); }
130
+
131
+ if (options.data) {
132
+ data = Handlebars.createFrame(options.data);
133
+ }
134
+
135
+ if(context && typeof context === 'object') {
136
+ if(context instanceof Array){
137
+ for(var j = context.length; i<j; i++) {
138
+ if (data) { data.index = i; }
139
+ ret = ret + fn(context[i], { data: data });
140
+ }
141
+ } else {
142
+ for(var key in context) {
143
+ if(context.hasOwnProperty(key)) {
144
+ if(data) { data.key = key; }
145
+ ret = ret + fn(context[key], {data: data});
146
+ i++;
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ if(i === 0){
153
+ ret = inverse(this);
154
+ }
155
+
156
+ return ret;
157
+ });
158
+
159
+ Handlebars.registerHelper('if', function(conditional, options) {
160
+ var type = toString.call(conditional);
161
+ if(type === functionType) { conditional = conditional.call(this); }
162
+
163
+ if(!conditional || Handlebars.Utils.isEmpty(conditional)) {
164
+ return options.inverse(this);
165
+ } else {
166
+ return options.fn(this);
167
+ }
168
+ });
169
+
170
+ Handlebars.registerHelper('unless', function(conditional, options) {
171
+ return Handlebars.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn});
172
+ });
173
+
174
+ Handlebars.registerHelper('with', function(context, options) {
175
+ var type = toString.call(context);
176
+ if(type === functionType) { context = context.call(this); }
177
+
178
+ if (!Handlebars.Utils.isEmpty(context)) return options.fn(context);
179
+ });
180
+
181
+ Handlebars.registerHelper('log', function(context, options) {
182
+ var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
183
+ Handlebars.log(level, context);
184
+ });
185
+ ;
186
+ // lib/handlebars/utils.js
187
+
188
+ var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
189
+
190
+ Handlebars.Exception = function(message) {
191
+ var tmp = Error.prototype.constructor.apply(this, arguments);
192
+
193
+ // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
194
+ for (var idx = 0; idx < errorProps.length; idx++) {
195
+ this[errorProps[idx]] = tmp[errorProps[idx]];
196
+ }
197
+ };
198
+ Handlebars.Exception.prototype = new Error();
199
+
200
+ // Build out our basic SafeString type
201
+ Handlebars.SafeString = function(string) {
202
+ this.string = string;
203
+ };
204
+ Handlebars.SafeString.prototype.toString = function() {
205
+ return this.string.toString();
206
+ };
207
+
208
+ var escape = {
209
+ "&": "&amp;",
210
+ "<": "&lt;",
211
+ ">": "&gt;",
212
+ '"': "&quot;",
213
+ "'": "&#x27;",
214
+ "`": "&#x60;"
215
+ };
216
+
217
+ var badChars = /[&<>"'`]/g;
218
+ var possible = /[&<>"'`]/;
219
+
220
+ var escapeChar = function(chr) {
221
+ return escape[chr] || "&amp;";
222
+ };
223
+
224
+ Handlebars.Utils = {
225
+ extend: function(obj, value) {
226
+ for(var key in value) {
227
+ if(value.hasOwnProperty(key)) {
228
+ obj[key] = value[key];
229
+ }
230
+ }
231
+ },
232
+
233
+ escapeExpression: function(string) {
234
+ // don't escape SafeStrings, since they're already safe
235
+ if (string instanceof Handlebars.SafeString) {
236
+ return string.toString();
237
+ } else if (string == null || string === false) {
238
+ return "";
239
+ }
240
+
241
+ // Force a string conversion as this will be done by the append regardless and
242
+ // the regex test will do this transparently behind the scenes, causing issues if
243
+ // an object's to string has escaped characters in it.
244
+ string = string.toString();
245
+
246
+ if(!possible.test(string)) { return string; }
247
+ return string.replace(badChars, escapeChar);
248
+ },
249
+
250
+ isEmpty: function(value) {
251
+ if (!value && value !== 0) {
252
+ return true;
253
+ } else if(toString.call(value) === "[object Array]" && value.length === 0) {
254
+ return true;
255
+ } else {
256
+ return false;
257
+ }
258
+ }
259
+ };
260
+ ;
261
+ // lib/handlebars/runtime.js
262
+
263
+ Handlebars.VM = {
264
+ template: function(templateSpec) {
265
+ // Just add water
266
+ var container = {
267
+ escapeExpression: Handlebars.Utils.escapeExpression,
268
+ invokePartial: Handlebars.VM.invokePartial,
269
+ programs: [],
270
+ program: function(i, fn, data) {
271
+ var programWrapper = this.programs[i];
272
+ if(data) {
273
+ programWrapper = Handlebars.VM.program(i, fn, data);
274
+ } else if (!programWrapper) {
275
+ programWrapper = this.programs[i] = Handlebars.VM.program(i, fn);
276
+ }
277
+ return programWrapper;
278
+ },
279
+ merge: function(param, common) {
280
+ var ret = param || common;
281
+
282
+ if (param && common) {
283
+ ret = {};
284
+ Handlebars.Utils.extend(ret, common);
285
+ Handlebars.Utils.extend(ret, param);
286
+ }
287
+ return ret;
288
+ },
289
+ programWithDepth: Handlebars.VM.programWithDepth,
290
+ noop: Handlebars.VM.noop,
291
+ compilerInfo: null
292
+ };
293
+
294
+ return function(context, options) {
295
+ options = options || {};
296
+ var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
297
+
298
+ var compilerInfo = container.compilerInfo || [],
299
+ compilerRevision = compilerInfo[0] || 1,
300
+ currentRevision = Handlebars.COMPILER_REVISION;
301
+
302
+ if (compilerRevision !== currentRevision) {
303
+ if (compilerRevision < currentRevision) {
304
+ var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
305
+ compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
306
+ throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
307
+ "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
308
+ } else {
309
+ // Use the embedded version info since the runtime doesn't know about this revision yet
310
+ throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
311
+ "Please update your runtime to a newer version ("+compilerInfo[1]+").";
312
+ }
313
+ }
314
+
315
+ return result;
316
+ };
317
+ },
318
+
319
+ programWithDepth: function(i, fn, data /*, $depth */) {
320
+ var args = Array.prototype.slice.call(arguments, 3);
321
+
322
+ var program = function(context, options) {
323
+ options = options || {};
324
+
325
+ return fn.apply(this, [context, options.data || data].concat(args));
326
+ };
327
+ program.program = i;
328
+ program.depth = args.length;
329
+ return program;
330
+ },
331
+ program: function(i, fn, data) {
332
+ var program = function(context, options) {
333
+ options = options || {};
334
+
335
+ return fn(context, options.data || data);
336
+ };
337
+ program.program = i;
338
+ program.depth = 0;
339
+ return program;
340
+ },
341
+ noop: function() { return ""; },
342
+ invokePartial: function(partial, name, context, helpers, partials, data) {
343
+ var options = { helpers: helpers, partials: partials, data: data };
344
+
345
+ if(partial === undefined) {
346
+ throw new Handlebars.Exception("The partial " + name + " could not be found");
347
+ } else if(partial instanceof Function) {
348
+ return partial(context, options);
349
+ } else if (!Handlebars.compile) {
350
+ throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
351
+ } else {
352
+ partials[name] = Handlebars.compile(partial, {data: data !== undefined});
353
+ return partials[name](context, options);
354
+ }
355
+ }
356
+ };
357
+
358
+ Handlebars.template = Handlebars.VM.template;
359
+ ;
360
+ // lib/handlebars/browser-suffix.js
361
+ })(Handlebars);
362
+ ;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thorax-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-09-18 00:00:00.000000000 Z
14
+ date: 2013-10-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties
@@ -50,33 +50,33 @@ dependencies:
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
- - - ~>
53
+ - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
- version: 2.1.3
55
+ version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
59
59
  none: false
60
60
  requirements:
61
- - - ~>
61
+ - - ! '>='
62
62
  - !ruby/object:Gem::Version
63
- version: 2.1.3
63
+ version: '0'
64
64
  - !ruby/object:Gem::Dependency
65
- name: ejs
65
+ name: handlebars_assets
66
66
  requirement: !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
- - - ~>
69
+ - - '='
70
70
  - !ruby/object:Gem::Version
71
- version: 1.1.1
71
+ version: 0.14.1
72
72
  type: :runtime
73
73
  prerelease: false
74
74
  version_requirements: !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
- - - ~>
77
+ - - '='
78
78
  - !ruby/object:Gem::Version
79
- version: 1.1.1
79
+ version: 0.14.1
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rails
82
82
  requirement: !ruby/object:Gem::Requirement
@@ -130,17 +130,17 @@ dependencies:
130
130
  requirement: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements:
133
- - - ~>
133
+ - - '='
134
134
  - !ruby/object:Gem::Version
135
- version: 0.10.3
135
+ version: 0.13.2
136
136
  type: :development
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
- - - ~>
141
+ - - '='
142
142
  - !ruby/object:Gem::Version
143
- version: 0.10.3
143
+ version: 0.13.2
144
144
  - !ruby/object:Gem::Dependency
145
145
  name: turn
146
146
  requirement: !ruby/object:Gem::Requirement
@@ -176,22 +176,42 @@ dependencies:
176
176
  description: Add Thorax to the Rails asset pipeline. Generators take care of boilerplate
177
177
  code so you don't have to
178
178
  email:
179
- - ryan@codebrewstudios.com
179
+ - lauren.eastridge@formidablelabs.com
180
180
  executables: []
181
181
  extensions: []
182
182
  extra_rdoc_files: []
183
183
  files:
184
184
  - lib/generators/thorax/install/install_generator.rb
185
- - lib/generators/thorax/thorax_helpers.rb
186
- - lib/thorax.rb
185
+ - lib/generators/thorax/install/templates/collection-view.coffee
186
+ - lib/generators/thorax/install/templates/collection.coffee
187
+ - lib/generators/thorax/install/templates/init.js
188
+ - lib/generators/thorax/install/templates/layout-view.coffee
189
+ - lib/generators/thorax/install/templates/model.coffee
190
+ - lib/generators/thorax/install/templates/namespace.coffee
191
+ - lib/generators/thorax/install/templates/root.coffee
192
+ - lib/generators/thorax/install/templates/root.hbs
193
+ - lib/generators/thorax/install/templates/view.coffee
194
+ - lib/generators/thorax/model/model_generator.rb
195
+ - lib/generators/thorax/model/templates/collection.coffee
196
+ - lib/generators/thorax/model/templates/model.coffee
197
+ - lib/generators/thorax/resource_helpers.rb
198
+ - lib/generators/thorax/router/router_generator.rb
199
+ - lib/generators/thorax/router/templates/router.coffee
200
+ - lib/generators/thorax/router/templates/template.hbs
201
+ - lib/generators/thorax/router/templates/view.coffee
202
+ - lib/generators/thorax/view/templates/template.hbs
203
+ - lib/generators/thorax/view/templates/view.coffee
204
+ - lib/generators/thorax/view/view_generator.rb
205
+ - lib/tasks/thorax-rails_tasks.rake
206
+ - lib/thorax-rails.rb
187
207
  - vendor/assets/javascripts/backbone.js
188
- - vendor/assets/javascripts/handlebars.js
208
+ - vendor/assets/javascripts/handlebars.runtime.js
189
209
  - vendor/assets/javascripts/thorax.js
190
- - vendor/assets/javascripts/undersccore.js
210
+ - vendor/assets/javascripts/underscore.js
191
211
  - MIT-LICENSE
192
212
  - Rakefile
193
- - README.rdoc
194
- homepage: http://github.com/walmartlabs/backbone-rails
213
+ - README.md
214
+ homepage: http://github.com/walmartlabs/thorax-gem
195
215
  licenses: []
196
216
  post_install_message:
197
217
  rdoc_options: []
data/README.rdoc DELETED
@@ -1,19 +0,0 @@
1
- = thorax
2
-
3
- The thorax gem includes Thorax.js in your Rails asset pipeline. A few handy generators take care the boilerplate code so you don't have to. Enjoy!
4
-
5
- == Contributing to thorax
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2013 WalmartLabs. See MIT-LICENSE.txt for
18
- further details.
19
-
@@ -1,45 +0,0 @@
1
- /*global Handlebars: true */
2
-
3
- var handlebars = require("./handlebars/base"),
4
-
5
- // Each of these augment the Handlebars object. No need to setup here.
6
- // (This is done to easily share code between commonjs and browse envs)
7
- utils = require("./handlebars/utils"),
8
- compiler = require("./handlebars/compiler"),
9
- runtime = require("./handlebars/runtime");
10
-
11
- var create = function() {
12
- var hb = handlebars.create();
13
-
14
- utils.attach(hb);
15
- compiler.attach(hb);
16
- runtime.attach(hb);
17
-
18
- return hb;
19
- };
20
-
21
- var Handlebars = create();
22
- Handlebars.create = create;
23
-
24
- module.exports = Handlebars; // instantiate an instance
25
-
26
- // Publish a Node.js require() handler for .handlebars and .hbs files
27
- if (require.extensions) {
28
- var extension = function(module, filename) {
29
- var fs = require("fs");
30
- var templateString = fs.readFileSync(filename, "utf8");
31
- module.exports = Handlebars.compile(templateString);
32
- };
33
- require.extensions[".handlebars"] = extension;
34
- require.extensions[".hbs"] = extension;
35
- }
36
-
37
- // BEGIN(BROWSER)
38
-
39
- // END(BROWSER)
40
-
41
- // USAGE:
42
- // var handlebars = require('handlebars');
43
-
44
- // var singleton = handlebars.Handlebars,
45
- // local = handlebars.create();