rails_utils 3.3.1 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3569698ba27aae3cdcd88cb1ed58fc1d1e251b4
4
- data.tar.gz: 229ea1766631a6d548e0056809dcc2cb576554df
3
+ metadata.gz: 569b976c686f0894cee61eab2b3e9bb6a734be81
4
+ data.tar.gz: 839e43dfd75277b580f921d9ab7636d3a64d0f6a
5
5
  SHA512:
6
- metadata.gz: c50136816341a8e4cb2a36b9338d08186a702e044e7ff3b19784ea74a03e7e5c437dcd3a3f5e278364587e568ae3c03dddc0760dd8157b8cc3d673472487a3e5
7
- data.tar.gz: 3abd2f3ed1de45d30e1f303957c6a97bb99d7bc52a99b5976be5bdb0b1c02057929fba92ed0d2b35e3584f1c3e68b2573e43e8a9f5cded1c595838ed2d0ce05d
6
+ metadata.gz: 17401582ef98f636428dc7cc835d31e92c5e24a6b711612a66c6126b4c695bc256ff489c14b2cd646ee24fd97458eb35bb8206d12bc69a42959083f017f5b053
7
+ data.tar.gz: 8dc65383216c2719a1c5e67c36b24d2de93a829ac9f9a76f2d5c06a1f307bea700dc7051e3adeec4aa2ea94c1bd4033c492c9e36fd4ae36b4b93b3ac31e94f51
data/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  Rails helpers based on opinionated project practices. Currently useful for structuring CSS and JS.
6
6
 
7
-
8
7
  ## Installation
9
8
 
10
9
  gem install 'rails_utils'
@@ -56,7 +55,7 @@ becomes
56
55
  Besides, it supports I18n and interpolation:
57
56
 
58
57
  en:
59
- anime:
58
+ animes:
60
59
  show:
61
60
  title: Showing anime of: %{anime_name}
62
61
 
@@ -117,64 +116,27 @@ You can also:
117
116
  - Add additional CSS classes to the alert with the `class` option.
118
117
  - Customize the close button with `button_html` and `button_class` options.
119
118
 
120
- ## Contributing
121
-
122
- Pull Requests are very welcomed (with specs, of course)!
123
-
124
- Minitest-ed. To run all tests, just run `rake` or `rake test`.
125
-
126
- ## Changelog
127
-
128
- _Version 3.3.1_
129
-
130
- - [Pull Request 10](https://github.com/winston/rails_utils/pull/10) - Allow overiding of `default` for `page_title` - by @choonkeat.
131
-
132
- _Version 3.3.0_
133
-
134
- - [Pull Request 8](https://github.com/winston/rails_utils/pull/8) - Add `button_html` and `button_class` options for `flash_messages` - by @choonkeat.
135
- - [Pull Request 9](https://github.com/winston/rails_utils/pull/9) - Remove `timedout` from `flash` that's specific to `Devise`.
136
-
137
-
138
- _Version 3.2.2_
139
-
140
- - [Pull Request 5](https://github.com/winston/rails_utils/pull/5) - Minor updates - by @JuanitoFatas.
141
-
142
-
143
- _Version 3.2.1_
119
+ ## Configuration
144
120
 
145
- - Update `page_title` to support I18n interpolation - by @JuanitoFatas.
121
+ Override any of these defaults in `config/initializers/rails_utils.rb`
146
122
 
123
+ ```ruby
124
+ RailsUtils.configure do |config|
125
+ config.selector_format = :underscored # or :hyphenated
126
+ end
127
+ ```
147
128
 
148
- _Version 3.2.0_
149
-
150
- - Add `page_title` that supports I18n - by @huynhquancam.
151
-
152
-
153
- _Version 3.1.2_
154
-
155
- - Add `alert-danger` class to flash error messages for Bootstrap 3 support.
156
-
157
-
158
- _Version 3.1.1_
159
-
160
- - [Pull Request 1](https://github.com/winston/rails_utils/pull/2) Support for Rails 4.1.
161
-
162
-
163
- _Version 3.1.0_
164
-
165
- - Drop string `controller` from `page_class` and `javascript_initialization`.
166
-
129
+ ## Contributing
167
130
 
168
- _Version 3.0.0_
131
+ Pull Requests are very welcomed (with specs, of course)!
169
132
 
170
- - Controller namespace added to `page_class` and `javascript_initialization`.
133
+ Minitest-ed. To run all tests, just run `rake` or `rake test`.
171
134
 
172
135
  ## Author
173
136
 
174
137
  Rails Utils is maintained by [Winston Teo](mailto:winstonyw+rails_utils@gmail.com).
175
138
 
176
- [You should follow Winston on Twitter](http://www.twitter.com/winstonyw), or find out more on [WinstonYW](http://www.winstonyw.com) and [LinkedIn](http://sg.linkedin.com/in/winstonyw).
177
-
139
+ [You should follow Winston on Twitter](https://www.twitter.com/winstonyw), or find out more on [WinstonYW](http://www.winstonyw.com) and [LinkedIn](http://sg.linkedin.com/in/winstonyw).
178
140
 
179
141
  ## License
180
142
 
@@ -0,0 +1,17 @@
1
+ module RailsUtils
2
+ class Configuration
3
+ attr_accessor :selector_format
4
+
5
+ def initialize
6
+ @selector_format = :underscored
7
+ end
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ def self.configure
15
+ yield configuration
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsUtils
2
- VERSION = "3.3.1"
2
+ VERSION = "3.3.2"
3
3
  end
data/lib/rails_utils.rb CHANGED
@@ -1,9 +1,15 @@
1
+ require 'rails_utils/configuration'
1
2
  require 'action_view'
2
3
 
3
4
  module RailsUtils
4
5
  module ActionViewExtensions
5
6
  def page_controller_class
6
- controller.class.to_s.sub(/Controller$/, "").underscore.sub(/\//, "_")
7
+ case RailsUtils.configuration.selector_format.to_sym
8
+ when :hyphenated
9
+ page_controller_class_hyphenated
10
+ else # :underscored
11
+ page_controller_class_underscored
12
+ end
7
13
  end
8
14
 
9
15
  def page_action_class
@@ -21,14 +27,22 @@ module RailsUtils
21
27
  I18n.t("#{page_controller_class}.#{page_action_class}.title", i18n_options)
22
28
  end
23
29
 
24
- def javascript_initialization
25
- application_name = Rails.application.class.parent_name
30
+ def javascript_initialization(options = {})
31
+ application_name = Rails.application.class.parent_name
32
+ js_namespace_name = page_controller_class_underscored
33
+ js_function_name = page_action_class
34
+
35
+ if content_for?(:js_init_method)
36
+ js_custom_name = content_for(:js_init_method)
37
+ custom_js_init_method = "if(#{application_name}.#{js_namespace_name}.init_#{js_custom_name}) { #{application_name}.#{js_namespace_name}.init_#{js_custom_name}(); }"
38
+ end
26
39
 
27
40
  javascript_tag <<-JS
28
41
  #{application_name}.init();
29
- if(#{application_name}.#{page_controller_class}) {
30
- if(#{application_name}.#{page_controller_class}.init) { #{application_name}.#{page_controller_class}.init(); }
31
- if(#{application_name}.#{page_controller_class}.init_#{page_action_class}) { #{application_name}.#{page_controller_class}.init_#{page_action_class}(); }
42
+ if(#{application_name}.#{js_namespace_name}) {
43
+ if(#{application_name}.#{js_namespace_name}.init) { #{application_name}.#{js_namespace_name}.init(); }
44
+ if(#{application_name}.#{js_namespace_name}.init_#{js_function_name}) { #{application_name}.#{js_namespace_name}.init_#{js_function_name}(); }
45
+ #{custom_js_init_method}
32
46
  }
33
47
  JS
34
48
  end
@@ -44,20 +58,28 @@ module RailsUtils
44
58
 
45
59
  private
46
60
 
47
- def flash_class(key)
48
- case key.to_sym
49
- when :success
50
- "alert alert-success"
51
- when :notice
52
- "alert alert-info"
53
- when :error
54
- "alert alert-danger alert-error"
55
- when :alert
56
- "alert alert-danger alert-error"
57
- else
58
- "alert alert-#{key}"
61
+ def flash_class(key)
62
+ case key.to_sym
63
+ when :success
64
+ "alert alert-success"
65
+ when :notice
66
+ "alert alert-info"
67
+ when :error
68
+ "alert alert-danger alert-error"
69
+ when :alert
70
+ "alert alert-danger alert-error"
71
+ else
72
+ "alert alert-#{key}"
73
+ end
74
+ end
75
+
76
+ def page_controller_class_hyphenated
77
+ page_controller_class_underscored.dasherize
78
+ end
79
+
80
+ def page_controller_class_underscored
81
+ controller.class.to_s.sub(/Controller$/, "").underscore.sub(/\//, "_")
59
82
  end
60
- end
61
83
  end
62
84
  end
63
85
 
@@ -6,9 +6,6 @@ Dummy::Application.configure do
6
6
  # since you don't have to restart the web server when you make code changes.
7
7
  config.cache_classes = false
8
8
 
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
9
  # Show full error reports and disable caching
13
10
  config.consider_all_requests_local = true
14
11
  config.action_controller.perform_caching = false
@@ -22,10 +19,12 @@ Dummy::Application.configure do
22
19
  # Only use best-standards-support built into browsers
23
20
  config.action_dispatch.best_standards_support = :builtin
24
21
 
25
-
26
22
  # Do not compress assets
27
23
  config.assets.compress = false
28
24
 
29
25
  # Expands the lines which load the assets
30
26
  config.assets.debug = true
27
+
28
+ # Do not eager load code on boot.
29
+ config.eager_load = false
31
30
  end
@@ -61,4 +61,6 @@ Dummy::Application.configure do
61
61
  # Send deprecation notices to registered listeners
62
62
  config.active_support.deprecation = :notify
63
63
 
64
+ # Do not eager load code on boot.
65
+ config.eager_load = true
64
66
  end
@@ -11,9 +11,6 @@ Dummy::Application.configure do
11
11
  config.serve_static_assets = true
12
12
  config.static_cache_control = "public, max-age=3600"
13
13
 
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
16
-
17
14
  # Show full error reports and disable caching
18
15
  config.consider_all_requests_local = true
19
16
  config.action_controller.perform_caching = false
@@ -29,7 +26,9 @@ Dummy::Application.configure do
29
26
  # ActionMailer::Base.deliveries array.
30
27
  config.action_mailer.delivery_method = :test
31
28
 
32
-
33
29
  # Print deprecation notices to the stderr
34
30
  config.active_support.deprecation = :stderr
31
+
32
+ # Do not eager load code on boot.
33
+ config.eager_load = false
35
34
  end
@@ -32,6 +32,40 @@ describe "RailsUtils::ActionViewExtensions" do
32
32
  view.page_controller_class.must_equal controller_name
33
33
  end
34
34
  end
35
+
36
+ describe "simple controller with hyphenated selector format" do
37
+ let(:controller_class) { "Awesome::AnimeController" }
38
+ let(:controller_name) { "awesome-anime" }
39
+
40
+ before do
41
+ RailsUtils.configure do |config|
42
+ config.selector_format = :hyphenated
43
+ end
44
+
45
+ controller.stubs(:class).returns(controller_class)
46
+ end
47
+
48
+ it "returns controller name" do
49
+ view.page_controller_class.must_equal controller_name
50
+ end
51
+ end
52
+
53
+ describe "simple controller with specified selector format in string" do
54
+ let(:controller_class) { "Awesome::AnimeController" }
55
+ let(:controller_name) { "awesome_anime" }
56
+
57
+ before do
58
+ RailsUtils.configure do |config|
59
+ config.selector_format = "underscored"
60
+ end
61
+
62
+ controller.stubs(:class).returns(controller_class)
63
+ end
64
+
65
+ it "returns controller name" do
66
+ view.page_controller_class.must_equal controller_name
67
+ end
68
+ end
35
69
  end
36
70
 
37
71
  describe "#page_action_class" do
@@ -149,6 +183,23 @@ describe "RailsUtils::ActionViewExtensions" do
149
183
  view.javascript_initialization.must_match "Dummy.#{controller_name}.init_edit();"
150
184
  end
151
185
  end
186
+
187
+ describe "with a content_for custom js_init_method as an argument" do
188
+ let(:action_name) { "update" }
189
+
190
+ it "uses the custom js init method" do
191
+ view.content_for(:js_init_method) { "custom" }
192
+ view.javascript_initialization.must_match "Dummy.#{controller_name}.init_custom();"
193
+ end
194
+ end
195
+
196
+ describe "without a content_for custom js_init_method as an argument" do
197
+ let(:action_name) { "update" }
198
+
199
+ it "does not generate an additional javascript method" do
200
+ view.javascript_initialization.wont_match "Dummy.#{controller_name}.init_();"
201
+ end
202
+ end
152
203
  end
153
204
 
154
205
  describe "#flash_messages" do
@@ -214,6 +265,5 @@ describe "RailsUtils::ActionViewExtensions" do
214
265
  set_flash :timedout, "not important"
215
266
  view.flash_messages.must_equal ""
216
267
  end
217
-
218
268
  end
219
269
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winston Teo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -78,6 +78,7 @@ files:
78
78
  - README.md
79
79
  - Rakefile
80
80
  - lib/rails_utils.rb
81
+ - lib/rails_utils/configuration.rb
81
82
  - lib/rails_utils/version.rb
82
83
  - test/dummy/README.rdoc
83
84
  - test/dummy/Rakefile