batman-rails 0.0.9 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +22 -0
- data/README.md +43 -39
- data/Rakefile +2 -9
- data/batman-rails.gemspec +20 -21
- data/lib/batman-rails.rb +8 -1
- data/lib/batman-rails/version.rb +6 -0
- data/lib/generators/batman/app_generator.rb +117 -0
- data/lib/generators/batman/controller_generator.rb +8 -17
- data/lib/generators/batman/html_generator.rb +42 -0
- data/lib/generators/batman/model_generator.rb +2 -2
- data/lib/generators/batman/scaffold_generator.rb +14 -4
- data/lib/generators/batman/view_generator.rb +18 -0
- data/lib/generators/{batman/common.rb → common.rb} +19 -5
- data/lib/templates/batman/application_controller.coffee +1 -0
- data/lib/templates/batman/batman_app.coffee +20 -0
- data/lib/templates/batman/controller.coffee +7 -0
- data/lib/templates/batman/html/edit.html +2 -0
- data/lib/templates/batman/html/index.html +2 -0
- data/lib/templates/batman/html/main_index.html +259 -0
- data/lib/templates/batman/html/show.html +2 -0
- data/lib/templates/batman/main_controller.coffee +8 -0
- data/lib/templates/batman/model.coffee +13 -0
- data/lib/templates/batman/view.coffee +7 -0
- data/lib/templates/rails/controller.rb +7 -0
- data/lib/templates/rails/index.html +0 -0
- data/lib/templates/rails/layout.html +15 -0
- data/test/app_generator_test.rb +111 -0
- data/test/controller_generator_test.rb +41 -15
- data/test/model_generator_test.rb +47 -16
- data/test/test_helper.rb +3 -3
- data/test/view_generator_test.rb +36 -0
- data/vendor/assets/images/batman/bullet.png +0 -0
- data/vendor/assets/images/batman/content-bg-fade.png +0 -0
- data/vendor/assets/images/batman/content-bg.png +0 -0
- data/vendor/assets/images/batman/header-wrapper-bg.jpg +0 -0
- data/vendor/assets/images/batman/logo.png +0 -0
- data/vendor/assets/javascripts/batman/batman.jquery.js +16 -74
- data/vendor/assets/javascripts/batman/batman.js +8951 -8551
- data/vendor/assets/javascripts/batman/batman.paginator.js +216 -0
- data/vendor/assets/javascripts/batman/batman.rails.js +78 -33
- data/vendor/assets/javascripts/batman/es5-shim.js +0 -0
- metadata +76 -57
- data/lib/batman/rails.rb +0 -6
- data/lib/batman/rails/engine.rb +0 -6
- data/lib/batman/rails/version.rb +0 -6
- data/lib/generators/batman/helper_generator.rb +0 -14
- data/lib/generators/batman/install_generator.rb +0 -93
- data/lib/generators/batman/templates/batman_app.coffee +0 -24
- data/lib/generators/batman/templates/controller.coffee +0 -5
- data/lib/generators/batman/templates/helper.coffee +0 -5
- data/lib/generators/batman/templates/model.coffee +0 -7
- data/test/install_generator_test.rb +0 -105
- data/vendor/assets/javascripts/batman/batman.i18n.js +0 -116
- data/vendor/assets/javascripts/batman/batman.solo.js +0 -558
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTg5OGJkMTdiNzEyMjI1ZmMzNGQ2ZDk4NTQ4MjgzYTZiOGM2M2U0Zg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Zjk1NTc0MWEwN2RmZWNhZDAzNGJjMjBkZjQxNjMxZDZjNWYwYjgwYg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Y2IzNDQxMDI5NzBjODZkY2E2YTAzNmQyMmUwYWQ2MmQzODEyMzUwNTA1ZGUw
|
10
|
+
YzU4YzE0N2UyMTI3MDIxYjE0NTA0OWJiMzlmNjVlZDRiNzM2YWMzMDE5NmRm
|
11
|
+
NDM3MTNiODFiZjNjNDkzMWNiYTFiNDdmNGUzYjYwOTBkOGY2OGY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWQyMWM1YjcxY2U5YWJlYjYyMTliZTg5Y2UyNzUyMGNhNGEyZjMzYTU0ODIz
|
14
|
+
N2EyMWIxMGI3YjQzZmQ0YTc2MjYwMzRmMzdlYzM5YWUyN2EwMTRjNmIwNzk0
|
15
|
+
MjNlYzZlNmQ2MzZiY2UxMWJjYWZmM2I4MWJkMDY2NjlkMmRiNzc=
|
data/Gemfile
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matt Helm
|
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
CHANGED
@@ -1,58 +1,55 @@
|
|
1
|
-
# Batman
|
1
|
+
# Batman::Rails
|
2
2
|
|
3
|
-
Easily setup and use batman.js (0.
|
3
|
+
Easily setup and use batman.js (0.15) with Rails 4
|
4
4
|
|
5
|
-
##
|
6
|
-
This gem requires the use of rails 3.1, coffeescript and the new rails asset pipeline provided by sprockets.
|
5
|
+
## Installation
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
### Installation
|
7
|
+
Add this line to your application's Gemfile:
|
11
8
|
|
12
|
-
|
9
|
+
gem 'batman-rails'
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
Then run the following commands:
|
11
|
+
And then execute:
|
17
12
|
|
18
|
-
bundle
|
19
|
-
rails
|
13
|
+
$ bundle
|
14
|
+
$ rails generate batman:app
|
20
15
|
|
21
16
|
### Layout and namespacing
|
22
17
|
|
23
|
-
Running `rails
|
24
|
-
|
25
|
-
controllers/
|
18
|
+
Running `rails generate batman:app` will create the following directory structure under `app/assets/app_name/`:
|
19
|
+
|
26
20
|
models/
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
21
|
+
views/
|
22
|
+
controllers/
|
23
|
+
html/
|
24
|
+
lib/
|
25
|
+
|
26
|
+
It will also create a toplevel `app_name.coffee` file to setup namespacing and setup initial requires.
|
27
|
+
|
31
28
|
## Generators
|
32
|
-
|
33
|
-
The generators will only create client side code (
|
29
|
+
Batman-Rails provides 3 simple generators to help get you started using Batman.js with Rails.
|
30
|
+
The generators will only create client side code (CoffeeScript).
|
34
31
|
|
35
32
|
### Model Generator
|
36
33
|
|
37
|
-
rails
|
38
|
-
|
39
|
-
This generator creates a batman model
|
34
|
+
rails generate batman:model
|
35
|
+
|
36
|
+
This generator creates a batman model inside `app/assets/app_name/models` to be used to talk to the Rails backend.
|
40
37
|
|
41
38
|
### Controllers
|
42
|
-
|
43
|
-
rails
|
44
|
-
|
39
|
+
|
40
|
+
rails generate batman:controller
|
41
|
+
|
45
42
|
This generator creates a batman controller for the given actions provided.
|
46
43
|
|
47
44
|
### Scaffolding
|
48
45
|
|
49
|
-
rails
|
50
|
-
|
51
|
-
This generator creates a controller, helper and
|
46
|
+
rails generate batman:scaffold
|
47
|
+
|
48
|
+
This generator creates a controller, helper and model to create a simple crud single page app
|
52
49
|
|
53
|
-
##
|
50
|
+
## Usage
|
54
51
|
|
55
|
-
Created a new
|
52
|
+
Created a new Rails application called `blog`.
|
56
53
|
|
57
54
|
rails new blog
|
58
55
|
|
@@ -63,10 +60,17 @@ Edit your Gemfile and add
|
|
63
60
|
Install the gem and generate scaffolding.
|
64
61
|
|
65
62
|
bundle install
|
66
|
-
rails
|
67
|
-
rails
|
63
|
+
rails generate batman:app
|
64
|
+
rails generate scaffold Post title:string content:string
|
68
65
|
rake db:migrate
|
69
|
-
rails
|
70
|
-
|
71
|
-
You now have installed the batman-rails gem, setup a default directory structure for your frontend batman code.
|
72
|
-
|
66
|
+
rails generate batman:scaffold Post title:string content:string
|
67
|
+
|
68
|
+
You now have installed the `batman-rails` gem, setup a default directory structure for your frontend batman code. Then you generated the usual Rails server side scaffolding and finally generated Batman.js code to provide a simple single page app.
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
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 'rake/testtask'
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
10
3
|
|
11
4
|
Rake::TestTask.new(:test) do |t|
|
12
5
|
t.libs << 'lib'
|
data/batman-rails.gemspec
CHANGED
@@ -1,27 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'batman-rails/version'
|
4
5
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "batman-rails"
|
8
|
+
gem.version = Batman::Rails::VERSION
|
9
|
+
gem.authors = ["Nick Small", "Matt Helm", "John Duff"]
|
10
|
+
gem.email = ["batmanjs@shopify.com"]
|
11
|
+
gem.description = %q{Quickly get started with batman.js in a Rails app. Provides generators to get started and bundles in the latest version of batman.js.}
|
12
|
+
gem.summary = %q{Use batman.js with Rails}
|
13
|
+
gem.homepage = "https://github.com/Shopify/batman-rails"
|
13
14
|
|
14
|
-
|
15
|
+
gem.add_dependency "railties", [">= 3.2"]
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
s.add_development_dependency "mocha"
|
21
|
-
s.add_development_dependency "sqlite3"
|
17
|
+
gem.add_development_dependency "bundler"
|
18
|
+
gem.add_development_dependency "rails"
|
19
|
+
gem.add_development_dependency "mocha"
|
20
|
+
gem.add_development_dependency "sqlite3"
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
gem.files = `git ls-files`.split($/)
|
23
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
24
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
25
|
+
gem.require_paths = ["lib"]
|
27
26
|
end
|
data/lib/batman-rails.rb
CHANGED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'generators/common'
|
2
|
+
|
3
|
+
module Batman
|
4
|
+
module Generators
|
5
|
+
class AppGenerator < ::Rails::Generators::Base
|
6
|
+
include Common
|
7
|
+
requires_app_name
|
8
|
+
|
9
|
+
desc "This generator installs Batman.js with a default folder layout"
|
10
|
+
|
11
|
+
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
|
12
|
+
:desc => "Skip Git ignores and keeps"
|
13
|
+
|
14
|
+
class_option :skip_jquery, :type => :boolean, :aliases => "-J", :default => false,
|
15
|
+
:desc => "Skip including jQuery"
|
16
|
+
|
17
|
+
class_option :skip_es5, :type => :boolean, :default => false,
|
18
|
+
:desc => "Skip including the ES5 shim"
|
19
|
+
|
20
|
+
def setup_rails
|
21
|
+
with_app_name do
|
22
|
+
template "rails/controller.rb", "app/controllers/#{app_name}_controller.rb"
|
23
|
+
template "rails/layout.html", "app/views/layouts/#{app_name}.html.erb"
|
24
|
+
|
25
|
+
unless ENV["RAILS_ENV"] == "test"
|
26
|
+
inject_into_file "config/routes.rb", :after => "#{js_application_name}::Application.routes.draw do\n" do
|
27
|
+
route_catchall
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_app
|
35
|
+
with_app_name do
|
36
|
+
template "batman/batman_app.coffee", "#{app_path}/#{application_name}.js.coffee"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_directories
|
41
|
+
%w(models views controllers html lib).each do |dir|
|
42
|
+
empty_directory "#{app_path}/#{dir}"
|
43
|
+
create_file "#{app_path}/#{dir}/.gitkeep" unless options[:skip_git]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_default_controllers
|
48
|
+
with_app_name do
|
49
|
+
empty_directory "#{app_path}/html/main"
|
50
|
+
|
51
|
+
template "batman/application_controller.coffee", "#{app_path}/controllers/application_controller.js.coffee"
|
52
|
+
template "batman/main_controller.coffee", "#{app_path}/controllers/main_controller.js.coffee"
|
53
|
+
template "batman/html/main_index.html", "#{app_path}/html/main/index.html"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def inject_batman
|
58
|
+
with_app_name do
|
59
|
+
application_file = File.join(app_path, "#{application_name}.js.coffee")
|
60
|
+
|
61
|
+
prepend_file application_file, app_requires
|
62
|
+
prepend_file application_file, jquery_requires unless options[:skip_jquery]
|
63
|
+
prepend_file application_file, batman_requires
|
64
|
+
prepend_file application_file, es5_requires unless options[:skip_es5]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def route_catchall
|
69
|
+
<<-CODE
|
70
|
+
\n get "(*redirect_path)", to: "#{app_name}\#index", constraints: lambda { |request| request.format == "text/html" }\n
|
71
|
+
CODE
|
72
|
+
end
|
73
|
+
|
74
|
+
def es5_requires
|
75
|
+
<<-CODE
|
76
|
+
#= require batman/es5-shim\n
|
77
|
+
CODE
|
78
|
+
end
|
79
|
+
|
80
|
+
def batman_requires
|
81
|
+
<<-CODE
|
82
|
+
#= require batman/batman
|
83
|
+
#= require batman/batman.rails\n
|
84
|
+
CODE
|
85
|
+
end
|
86
|
+
|
87
|
+
def jquery_requires
|
88
|
+
<<-CODE
|
89
|
+
#= require jquery
|
90
|
+
#= require batman/batman.jquery\n
|
91
|
+
CODE
|
92
|
+
end
|
93
|
+
|
94
|
+
def app_requires
|
95
|
+
<<-CODE
|
96
|
+
#= require_self
|
97
|
+
|
98
|
+
#= require_tree ./lib
|
99
|
+
#= require_tree ./controllers
|
100
|
+
#= require_tree ./models
|
101
|
+
#= require_tree ./views\n
|
102
|
+
CODE
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def file_exists?(file)
|
108
|
+
relative_root = relative_to_original_destination_root(destination_root, false)
|
109
|
+
source_paths.any? do |source|
|
110
|
+
source_file = File.expand_path(file, File.join(source, relative_root))
|
111
|
+
File.exists?(source_file)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'generators/
|
1
|
+
require 'generators/common'
|
2
2
|
module Batman
|
3
3
|
module Generators
|
4
4
|
class ControllerGenerator < ::Rails::Generators::NamedBase
|
@@ -8,26 +8,17 @@ module Batman
|
|
8
8
|
desc "This generator creates a Batman controller"
|
9
9
|
argument :actions, :type => :array, :default => [], :banner => "action action"
|
10
10
|
|
11
|
-
|
12
|
-
RESERVED_JS_WORDS = %w{
|
13
|
-
break case catch continue debugger default delete do else finally for
|
14
|
-
function if in instanceof new return switch this throw try typeof var void while with
|
15
|
-
}
|
16
|
-
|
17
|
-
def validate_no_reserved_words
|
18
|
-
actions.each do |action|
|
19
|
-
if RESERVED_JS_WORDS.include? action
|
20
|
-
raise Thor::Error, "The name '#{action}' is reserved by javascript " <<
|
21
|
-
"Please choose an alternative action name and run this generator again."
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
11
|
def create_batman_controller
|
27
12
|
with_app_name do
|
28
|
-
template "controller.coffee", "#{
|
13
|
+
template "batman/controller.coffee", "#{app_path}/controllers/#{file_name.downcase}_controller.js.coffee"
|
14
|
+
generate "batman:html #{plural_name} #{action_names} #{app_name_flag}"
|
15
|
+
generate "batman:view #{plural_name} #{app_name_flag}"
|
29
16
|
end
|
30
17
|
end
|
18
|
+
|
19
|
+
def action_names
|
20
|
+
options[:actions].join(' ') if options[:actions]
|
21
|
+
end
|
31
22
|
end
|
32
23
|
end
|
33
24
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'generators/common'
|
2
|
+
module Batman
|
3
|
+
module Generators
|
4
|
+
class HtmlGenerator < ::Rails::Generators::NamedBase
|
5
|
+
include Common
|
6
|
+
requires_app_name
|
7
|
+
|
8
|
+
desc "This generator creates a the HTML files needed for a Batman.Controller"
|
9
|
+
argument :actions, :type => :array, :default => [], :banner => "action action"
|
10
|
+
|
11
|
+
|
12
|
+
RESERVED_JS_WORDS = %w{
|
13
|
+
break case catch continue debugger default delete do else finally for
|
14
|
+
function if in instanceof new return switch this throw try typeof var void while with
|
15
|
+
}
|
16
|
+
|
17
|
+
def validate_no_reserved_words
|
18
|
+
actions.each do |action|
|
19
|
+
if RESERVED_JS_WORDS.include? action
|
20
|
+
raise Thor::Error, "The name '#{action}' is reserved by javascript " <<
|
21
|
+
"Please choose an alternative action name and run this generator again."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_directory
|
27
|
+
with_app_name do
|
28
|
+
empty_directory "#{app_path}/html/#{plural_name.downcase}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_files
|
33
|
+
with_app_name do
|
34
|
+
(options[:arguments] || %w(index show edit)).each do |file|
|
35
|
+
template "batman/html/#{file}.html", "#{app_path}/html/#{plural_name.downcase}/#{file}.html"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'generators/
|
1
|
+
require 'generators/common'
|
2
2
|
module Batman
|
3
3
|
module Generators
|
4
4
|
class ModelGenerator < ::Rails::Generators::NamedBase
|
@@ -10,7 +10,7 @@ module Batman
|
|
10
10
|
|
11
11
|
def create_batman_model
|
12
12
|
with_app_name do
|
13
|
-
template "model.coffee", "#{
|
13
|
+
template "batman/model.coffee", "#{app_path}/models/#{singular_table_name.downcase}.js.coffee"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|