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.
Files changed (56) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +1 -1
  3. data/LICENSE.txt +22 -0
  4. data/README.md +43 -39
  5. data/Rakefile +2 -9
  6. data/batman-rails.gemspec +20 -21
  7. data/lib/batman-rails.rb +8 -1
  8. data/lib/batman-rails/version.rb +6 -0
  9. data/lib/generators/batman/app_generator.rb +117 -0
  10. data/lib/generators/batman/controller_generator.rb +8 -17
  11. data/lib/generators/batman/html_generator.rb +42 -0
  12. data/lib/generators/batman/model_generator.rb +2 -2
  13. data/lib/generators/batman/scaffold_generator.rb +14 -4
  14. data/lib/generators/batman/view_generator.rb +18 -0
  15. data/lib/generators/{batman/common.rb → common.rb} +19 -5
  16. data/lib/templates/batman/application_controller.coffee +1 -0
  17. data/lib/templates/batman/batman_app.coffee +20 -0
  18. data/lib/templates/batman/controller.coffee +7 -0
  19. data/lib/templates/batman/html/edit.html +2 -0
  20. data/lib/templates/batman/html/index.html +2 -0
  21. data/lib/templates/batman/html/main_index.html +259 -0
  22. data/lib/templates/batman/html/show.html +2 -0
  23. data/lib/templates/batman/main_controller.coffee +8 -0
  24. data/lib/templates/batman/model.coffee +13 -0
  25. data/lib/templates/batman/view.coffee +7 -0
  26. data/lib/templates/rails/controller.rb +7 -0
  27. data/lib/templates/rails/index.html +0 -0
  28. data/lib/templates/rails/layout.html +15 -0
  29. data/test/app_generator_test.rb +111 -0
  30. data/test/controller_generator_test.rb +41 -15
  31. data/test/model_generator_test.rb +47 -16
  32. data/test/test_helper.rb +3 -3
  33. data/test/view_generator_test.rb +36 -0
  34. data/vendor/assets/images/batman/bullet.png +0 -0
  35. data/vendor/assets/images/batman/content-bg-fade.png +0 -0
  36. data/vendor/assets/images/batman/content-bg.png +0 -0
  37. data/vendor/assets/images/batman/header-wrapper-bg.jpg +0 -0
  38. data/vendor/assets/images/batman/logo.png +0 -0
  39. data/vendor/assets/javascripts/batman/batman.jquery.js +16 -74
  40. data/vendor/assets/javascripts/batman/batman.js +8951 -8551
  41. data/vendor/assets/javascripts/batman/batman.paginator.js +216 -0
  42. data/vendor/assets/javascripts/batman/batman.rails.js +78 -33
  43. data/vendor/assets/javascripts/batman/es5-shim.js +0 -0
  44. metadata +76 -57
  45. data/lib/batman/rails.rb +0 -6
  46. data/lib/batman/rails/engine.rb +0 -6
  47. data/lib/batman/rails/version.rb +0 -6
  48. data/lib/generators/batman/helper_generator.rb +0 -14
  49. data/lib/generators/batman/install_generator.rb +0 -93
  50. data/lib/generators/batman/templates/batman_app.coffee +0 -24
  51. data/lib/generators/batman/templates/controller.coffee +0 -5
  52. data/lib/generators/batman/templates/helper.coffee +0 -5
  53. data/lib/generators/batman/templates/model.coffee +0 -7
  54. data/test/install_generator_test.rb +0 -105
  55. data/vendor/assets/javascripts/batman/batman.i18n.js +0 -116
  56. data/vendor/assets/javascripts/batman/batman.solo.js +0 -558
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= application_name.titleize %></title>
5
+ <%%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%%= javascript_include_tag "<%= application_name %>" %>
7
+ <%%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <div data-yield="main"></div>
12
+
13
+ <%= js_application_name %>.run()
14
+ </body>
15
+ </html>
@@ -0,0 +1,111 @@
1
+ require 'mocha'
2
+ require 'test_helper'
3
+ require 'generators/batman/app_generator'
4
+
5
+ module AppGeneratorTests
6
+
7
+ def setup
8
+ mkdir_p "#{destination_root}/app/assets"
9
+ cp fixture(application_javascript_path), "#{destination_root}/app/assets"
10
+ Rails.application.class.stubs(:name).returns("Dummy::Application")
11
+ super
12
+ end
13
+
14
+ def teardown
15
+ Rails.application.class.unstub(:name)
16
+ end
17
+
18
+ def test_batman_application_file_is_created
19
+ run_generator
20
+
21
+ assert_file "#{javascripts_path}batman/dummy.js.coffee" do |app|
22
+ assert_match /class Dummy extends Batman\.App/, app
23
+ end
24
+ end
25
+
26
+ def test_batman_application_file_is_created_for_two_word_application_name
27
+ Rails.application.class.stubs(:name).returns("FooBar::Application")
28
+ run_generator
29
+
30
+ assert_file "#{javascripts_path}batman/foo_bar.js.coffee" do |app|
31
+ assert_match /class FooBar extends Batman\.App/, app
32
+ end
33
+ end
34
+
35
+ def test_batman_directory_structure_is_created
36
+ run_generator
37
+
38
+ %W{controllers models views html lib}.each do |dir|
39
+ assert_directory "#{javascripts_path}/batman/#{dir}"
40
+ assert_file "#{javascripts_path}batman/#{dir}/.gitkeep"
41
+ end
42
+ end
43
+
44
+ def test_no_gitkeep_files_are_created_when_skipping_git
45
+ run_generator [destination_root, "--skip-git"]
46
+
47
+ %W{controllers models views html lib}.each do |dir|
48
+ assert_directory "#{javascripts_path}/batman/#{dir}"
49
+ assert_no_file "#{javascripts_path}/batman/#{dir}/.gitkeep"
50
+ end
51
+ end
52
+
53
+ def test_jquery_isnt_added_when_skipping_jquery
54
+ run_generator [destination_root, "--skip-jquery"]
55
+
56
+ assert_file "#{javascripts_path}batman/dummy.js.coffee" do |app|
57
+ assert_no_match /require jquery/, app
58
+ end
59
+ end
60
+
61
+ def test_es5_shim_isnt_added_when_skipping_es5_shim
62
+ run_generator [destination_root, "--skip-es5"]
63
+
64
+ assert_file "#{javascripts_path}batman/dummy.js.coffee" do |app|
65
+ assert_no_match /require batman\/es5-shim/, app
66
+ end
67
+ end
68
+
69
+ def test_batmanjs_require_batman_jquery_rails
70
+ run_generator
71
+
72
+ assert_file "#{javascripts_path}batman/dummy.js.coffee" do |app|
73
+ %W{batman batman.jquery batman.rails}.each do |require|
74
+ assert_equal 1, app.scan(%r{require batman\/#{require}$}).length
75
+ end
76
+
77
+ %W{models controllers views lib}.each do |require|
78
+ assert_equal 1, app.scan(/require_tree \.\/#{require}/).length
79
+ end
80
+
81
+ assert_equal 1, app.scan(/Dummy\.run\(\)/).length
82
+
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ def fixture(file)
89
+ File.expand_path("fixtures/#{file}", File.dirname(__FILE__))
90
+ end
91
+ end
92
+
93
+ class AppGeneratorWithApplicationJavascriptTest < Rails::Generators::TestCase
94
+ tests Batman::Generators::AppGenerator
95
+
96
+ def application_javascript_path
97
+ "application.js"
98
+ end
99
+
100
+ include AppGeneratorTests
101
+ end
102
+
103
+ # class AppGeneratorWithApplicationCoffeescriptTest < Rails::Generators::TestCase
104
+ # tests Batman::Generators::AppGenerator
105
+
106
+ # def application_javascript_path
107
+ # "application.js.coffee"
108
+ # end
109
+
110
+ # include AppGeneratorTests
111
+ # end
@@ -3,38 +3,64 @@ require 'generators/batman/controller_generator'
3
3
 
4
4
  class ControllerGeneratorTest < Rails::Generators::TestCase
5
5
  tests Batman::Generators::ControllerGenerator
6
-
6
+
7
7
  test "simple controller" do
8
8
  run_generator %w(Task index show)
9
-
10
- assert_file "#{javascripts_path}/controllers/tasks_controller.js.coffee" do |controller|
11
- controller_class = Regexp.escape("class Sample.TasksController extends Batman.Controller")
12
-
9
+
10
+ assert_file "#{javascripts_path}/batman/controllers/task_controller.js.coffee" do |controller|
11
+ controller_class = Regexp.escape("class Sample.TaskController extends Sample.ApplicationController")
12
+
13
13
  assert_match /#{controller_class}/, controller
14
14
  assert_match %r{ index: \(params\) ->}, controller
15
15
  assert_match %r{ show: \(params\) ->}, controller
16
16
  end
17
17
  end
18
-
18
+
19
+ test "controller pluralization [singular]" do
20
+ run_generator %w(Task index show)
21
+ assert_file "#{javascripts_path}/batman/controllers/task_controller.js.coffee" do |controller|
22
+ controller_class = Regexp.escape("class Sample.TaskController extends Sample.ApplicationController")
23
+ assert_match /#{controller_class}/, controller
24
+ end
25
+ end
26
+
27
+ test "controller pluralization [plural]" do
28
+ run_generator %w(Tasks index show)
29
+ assert_file "#{javascripts_path}/batman/controllers/tasks_controller.js.coffee" do |controller|
30
+ controller_class = Regexp.escape("class Sample.TasksController extends Sample.ApplicationController")
31
+ assert_match /#{controller_class}/, controller
32
+ end
33
+ end
34
+
19
35
  test "two word controller is camelcased" do
20
36
  run_generator %w(RegularUser index)
21
-
22
- assert_file "#{javascripts_path}/controllers/regular_users_controller.js.coffee" do |controller|
23
- controller_class = Regexp.escape("class Sample.RegularUsersController extends Batman.Controller")
24
-
37
+
38
+ assert_file "#{javascripts_path}/batman/controllers/regular_user_controller.js.coffee" do |controller|
39
+ controller_class = Regexp.escape("class Sample.RegularUserController extends Sample.ApplicationController")
40
+
25
41
  assert_match /#{controller_class}/, controller
26
42
  assert_match %r{ index: \(params\) ->}, controller
27
43
  end
28
44
  end
29
-
45
+
30
46
  test "simple controller with app_name" do
31
47
  run_generator %w(Task index --app_name MyApp)
32
-
33
- assert_file "#{javascripts_path}/controllers/tasks_controller.js.coffee" do |controller|
34
- controller_class = Regexp.escape("class MyApp.TasksController extends Batman.Controller")
35
-
48
+
49
+ assert_file "#{javascripts_path}/MyApp/controllers/task_controller.js.coffee" do |controller|
50
+ controller_class = Regexp.escape("class MyApp.TaskController extends MyApp.ApplicationController")
51
+
36
52
  assert_match /#{controller_class}/, controller
37
53
  assert_match %r{ index: \(params\) ->}, controller
38
54
  end
39
55
  end
56
+
57
+ test "routingKey is present" do
58
+ run_generator %w(Resource)
59
+
60
+ assert_file "#{javascripts_path}/batman/controllers/resource_controller.js.coffee" do |controller|
61
+ routing_key = Regexp.escape("routingKey: 'resource'")
62
+
63
+ assert_match /#{routing_key}/ , controller
64
+ end
65
+ end
40
66
  end
@@ -3,42 +3,73 @@ require 'generators/batman/model_generator'
3
3
 
4
4
  class ModelGeneratorTest < Rails::Generators::TestCase
5
5
  tests Batman::Generators::ModelGenerator
6
-
6
+
7
7
  test "simple model" do
8
8
  run_generator %w(Task title:string created_at:date)
9
-
10
- assert_file "#{javascripts_path}/models/task.js.coffee" do |model|
9
+
10
+ assert_file "#{javascripts_path}/batman/models/task.js.coffee" do |model|
11
11
  model_class = Regexp.escape("class Sample.Task extends Batman.Model")
12
-
12
+
13
13
  assert_match /#{model_class}/, model
14
-
14
+
15
15
  assert_match /@storageKey: 'tasks'/, model
16
16
  assert_match /@persist Batman.RailsStorage/, model
17
-
17
+
18
18
  assert_match /@encode 'title'/, model
19
19
  assert_match /@encode 'created_at', Batman.Encoders.railsDate/, model
20
20
  end
21
21
  end
22
-
22
+
23
+ test "model pluralization [singular]" do
24
+ run_generator %w(Task)
25
+ assert_file "#{javascripts_path}/batman/models/task.js.coffee" do |model|
26
+ model_class = Regexp.escape("class Sample.Task extends Batman.Model")
27
+ assert_match /#{model_class}/, model
28
+ end
29
+ end
30
+
31
+ test "model pluralization [plural]" do
32
+ run_generator %w(Tasks)
33
+ assert_file "#{javascripts_path}/batman/models/task.js.coffee" do |model|
34
+ model_class = Regexp.escape("class Sample.Task extends Batman.Model")
35
+ assert_match /#{model_class}/, model
36
+ end
37
+ end
38
+
23
39
  test "two word model is camelcased" do
24
40
  run_generator %w(RegularUser name:string)
25
-
26
- assert_file "#{javascripts_path}/models/regular_user.js.coffee" do |model|
41
+
42
+ assert_file "#{javascripts_path}/batman/models/regular_user.js.coffee" do |model|
27
43
  model_class = Regexp.escape("class Sample.RegularUser extends Batman.Model")
28
-
44
+
29
45
  assert_match /#{model_class}/, model
30
-
46
+
31
47
  assert_match /@storageKey: 'regular_users'/, model
48
+ assert_match /@encode 'name'/, model
32
49
  end
33
50
  end
34
-
35
- test "simple model with app_name" do
51
+
52
+ test "simple model with app_nam and created_at date" do
36
53
  run_generator %w(Task title:string created_at:date --app_name MyApp)
37
-
38
- assert_file "#{javascripts_path}/models/task.js.coffee" do |model|
54
+
55
+ assert_file "#{javascripts_path}/MyApp/models/task.js.coffee" do |model|
56
+ model_class = Regexp.escape("class MyApp.Task extends Batman.Model")
57
+
58
+ assert_match /#{model_class}/, model
59
+ assert_match /@encode 'title'/, model
60
+ assert_match /@encode 'created_at', Batman.Encoders.railsDate/, model
61
+ end
62
+ end
63
+
64
+ test "simple model with duck-typing" do
65
+ run_generator %w(Task title created_at:date --app_name MyApp)
66
+
67
+ assert_file "#{javascripts_path}/MyApp/models/task.js.coffee" do |model|
39
68
  model_class = Regexp.escape("class MyApp.Task extends Batman.Model")
40
-
69
+
41
70
  assert_match /#{model_class}/, model
71
+ assert_match /@encode 'title'/, model
72
+ assert_match /@encode 'created_at', Batman.Encoders.railsDate/, model
42
73
  end
43
74
  end
44
75
  end
@@ -16,9 +16,9 @@ require 'rails/generators/test_case'
16
16
  class Rails::Generators::TestCase
17
17
  destination File.expand_path("../tmp", File.dirname(__FILE__))
18
18
  setup :prepare_destination
19
-
19
+
20
20
  def javascripts_path
21
- "app/assets/javascripts/"
21
+ "app/assets/"
22
22
  end
23
-
23
+
24
24
  end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+ require 'generators/batman/view_generator'
3
+
4
+ class ViewGeneratorTest < Rails::Generators::TestCase
5
+ tests Batman::Generators::ViewGenerator
6
+
7
+ test "simple view" do
8
+ run_generator %w(Task index show)
9
+
10
+ assert_file "#{javascripts_path}/batman/views/task_view.js.coffee" do |view|
11
+ view_class = Regexp.escape("class Sample.TaskView extends Batman.View")
12
+ view_index_class = Regexp.escape("class Sample.TaskIndexView extends Sample.TaskView")
13
+ view_show_class = Regexp.escape("class Sample.TaskShowView extends Sample.TaskView")
14
+
15
+ assert_match /#{view_class}/, view
16
+ assert_match /#{view_index_class}/, view
17
+ assert_match /#{view_show_class}/, view
18
+ end
19
+ end
20
+
21
+ test "view pluralization [singular]" do
22
+ run_generator %w(Task)
23
+ assert_file "#{javascripts_path}/batman/views/task_view.js.coffee" do |view|
24
+ view_class = Regexp.escape("class Sample.TaskView extends Batman.View")
25
+ assert_match /#{view_class}/, view
26
+ end
27
+ end
28
+
29
+ test "view pluralization [plural]" do
30
+ run_generator %w(Tasks)
31
+ assert_file "#{javascripts_path}/batman/views/tasks_view.js.coffee" do |view|
32
+ view_class = Regexp.escape("class Sample.TasksView extends Batman.View")
33
+ assert_match /#{view_class}/, view
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,4 @@
1
1
  (function() {
2
-
3
2
  Batman.extend(Batman.DOM, {
4
3
  querySelectorAll: function(node, selector) {
5
4
  return jQuery(selector, node);
@@ -8,47 +7,26 @@
8
7
  return jQuery(selector, node)[0];
9
8
  },
10
9
  setInnerHTML: function(node, html) {
11
- var child, childNodes, result, _i, _j, _len, _len1;
12
- childNodes = (function() {
13
- var _i, _len, _ref, _results;
14
- _ref = node.childNodes;
15
- _results = [];
16
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
17
- child = _ref[_i];
18
- _results.push(child);
19
- }
20
- return _results;
21
- })();
22
- for (_i = 0, _len = childNodes.length; _i < _len; _i++) {
23
- child = childNodes[_i];
24
- Batman.DOM.willRemoveNode(child);
25
- }
26
- result = jQuery(node).html(html);
27
- for (_j = 0, _len1 = childNodes.length; _j < _len1; _j++) {
28
- child = childNodes[_j];
29
- Batman.DOM.didRemoveNode(child);
30
- }
31
- return result;
32
- },
33
- removeNode: function(node) {
34
- var _ref;
35
- Batman.DOM.willRemoveNode(node);
36
- if ((_ref = node.parentNode) != null) {
37
- _ref.removeChild(node);
38
- }
39
- return Batman.DOM.didRemoveNode(node);
10
+ return jQuery(node).html(html);
40
11
  },
41
12
  destroyNode: function(node) {
42
- Batman.DOM.willDestroyNode(node);
43
- Batman.DOM.willRemoveNode(node);
13
+ Batman.DOM.cleanupNode(node);
44
14
  jQuery(node).remove();
45
- Batman.DOM.didRemoveNode(node);
46
- return Batman.DOM.didDestroyNode(node);
47
15
  },
48
- appendChild: function(parent, child) {
49
- Batman.DOM.willInsertNode(child);
50
- jQuery(parent).append(child);
51
- return Batman.DOM.didInsertNode(child);
16
+ textContent: function(node) {
17
+ return jQuery(node).text();
18
+ },
19
+ addEventListener: function(node, eventName, callback) {
20
+ return $(node).on(eventName, callback);
21
+ },
22
+ removeEventListener: function(node, eventName, callback) {
23
+ return $(node).off(eventName, callback);
24
+ }
25
+ });
26
+
27
+ Batman.View.accessor('$node', function() {
28
+ if (this.get('node')) {
29
+ return $(this.node);
52
30
  }
53
31
  });
54
32
 
@@ -122,40 +100,4 @@
122
100
  return jQuery.ajax(this._prepareOptions(data));
123
101
  };
124
102
 
125
- Batman.mixins.animation = {
126
- show: function(addToParent) {
127
- var jq, show, _ref, _ref1;
128
- jq = $(this);
129
- show = function() {
130
- return jq.show(600);
131
- };
132
- if (addToParent) {
133
- if ((_ref = addToParent.append) != null) {
134
- _ref.appendChild(this);
135
- }
136
- if ((_ref1 = addToParent.before) != null) {
137
- _ref1.parentNode.insertBefore(this, addToParent.before);
138
- }
139
- jq.hide();
140
- setTimeout(show, 0);
141
- } else {
142
- show();
143
- }
144
- return this;
145
- },
146
- hide: function(removeFromParent) {
147
- var _this = this;
148
- $(this).hide(600, function() {
149
- var _ref;
150
- if (removeFromParent) {
151
- if ((_ref = _this.parentNode) != null) {
152
- _ref.removeChild(_this);
153
- }
154
- }
155
- return Batman.DOM.didRemoveNode(_this);
156
- });
157
- return this;
158
- }
159
- };
160
-
161
103
  }).call(this);