thorax-rails 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 WalmartLabs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
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
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'bundler/gem_tasks'
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'BackboneRails'
14
+ rdoc.options << '--line-numbers' << '--inline-source'
15
+ rdoc.rdoc_files.include('README.md')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'lib'
23
+ t.libs << 'test'
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.verbose = false
26
+ end
27
+
28
+ task :default => :test
29
+
30
+ namespace :thorax do
31
+ desc "Download the latest releases of backbone, underscore, handlebars, and thorax"
32
+ task :download_latest do
33
+ files = {
34
+ 'underscore.js' => 'http://underscorejs.org/underscore.js',
35
+ 'backbone.js' => 'http://backbonejs.org/backbone.js',
36
+ 'handlebars.js' => 'https://raw.github.com/wycats/handlebars.js/master/lib/handlebars.js',
37
+ 'thorax.js' => 'https://github.com/components/thorax/blob/master/thorax.js'
38
+ }
39
+ vendor_dir = "vendor/assets/javascripts/thorax"
40
+
41
+ require 'open-uri'
42
+ files.each do |local, remote|
43
+ puts "Downloading #{local} from #{remote}"
44
+ File.open "#{vendor_dir}/#{local}", 'w' do |f|
45
+ f.write open(remote).read
46
+ end
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,30 @@
1
+ require 'generators/thorax/thorax_helpers'
2
+
3
+ module Thorax
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include Thorax::Generators::ResourceHelpers
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ desc "This generator installs thorax.js with a default folder layout in app/assets/javascripts/thorax"
11
+
12
+ class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
13
+ :desc => "Skip Git ignores and keeps"
14
+
15
+ def inject_thorax
16
+ 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
+ end
19
+ end
20
+
21
+ 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]
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,55 @@
1
+ module Thorax
2
+ module Generators
3
+ module ThoraxHelpers
4
+
5
+ def thorax_path
6
+ "app/assets/javascripts/thorax"
7
+ end
8
+
9
+ def model_namespace
10
+ [js_app_name, "Models", class_name].join(".")
11
+ end
12
+
13
+ def singular_model_name
14
+ uncapitalize singular_name.camelize
15
+ end
16
+
17
+ def plural_model_name
18
+ uncapitalize(plural_name.camelize)
19
+ end
20
+
21
+ def collection_namespace
22
+ [js_app_name, "Collections", plural_name.camelize].join(".")
23
+ end
24
+
25
+ def view_namespace
26
+ [js_app_name, "Views", plural_name.camelize].join(".")
27
+ end
28
+
29
+ def router_namespace
30
+ [js_app_name, "Routers", plural_name.camelize].join(".")
31
+ end
32
+
33
+ def jst(action)
34
+ "backbone/templates/#{plural_name}/#{action}"
35
+ end
36
+
37
+ def js_app_name
38
+ application_name.camelize
39
+ end
40
+
41
+ def application_name
42
+ if defined?(Rails) && Rails.application
43
+ Rails.application.class.name.split('::').first
44
+ else
45
+ "application"
46
+ end
47
+ end
48
+
49
+ def uncapitalize(str)
50
+ str[0, 1].downcase << str[1..-1]
51
+ end
52
+
53
+ end
54
+ end
55
+ end
data/lib/thorax.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+
3
+ module Thorax
4
+ class Engine < Rails::Engine
5
+ end
6
+ end