rails_utils 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33b210e01ed9a77efe8aa4ebe41f61b47d79509d
4
+ data.tar.gz: 5f61964092970fd2efd328096dfb098079f2aabd
5
+ SHA512:
6
+ metadata.gz: bac3237ed94c4481c4a546ce816f7f6faffcbe6ccba37791c4e3033053f86bd2c635732fbafcee89b528e1485dedccd6a3140f6a4bdb6585d83f0365a10fd2e9
7
+ data.tar.gz: 2a3b0cc699aef7d01abf91eb16d7a16366e5d28835b4a893bb1c051f534a80f70b82feb69c487d4e6214b956c2afe7588b842f7ff1d34d2ca68ae1e016e17d99
data/README.markdown CHANGED
@@ -29,13 +29,16 @@ Usually, when the `create` or `update` actions render, the `new` or `edit` views
29
29
  Therefore the `page_class` helper converts `create` to `new` and `update` to `edit`
30
30
  so that you only need to write CSS to target `new` and `edit`, and not all four actions.
31
31
 
32
+ For finer grained control, you can also choose the use the 2 methods that are used to build `page_class` individually.
33
+ The two methods are `page_controller_class` and `page_action_class`.
34
+
32
35
  ## #`javascript_initialization`
33
36
 
34
37
  This helper method attempts to initialize JavaScript classes and methods based on a standard structure.
35
38
 
36
39
  With this standard structure, calling your JavaScript has never been easier.
37
40
 
38
- Add `javascript_initialization` to the bottom your layout.
41
+ Add `javascript_initialization` to the bottom of your layout.
39
42
 
40
43
  = javascript_initialization
41
44
 
@@ -48,7 +51,6 @@ When application is MyApp, and controller/action is `anime#show`, `javascript_in
48
51
  if(MyApp.anime.init) { MyApp.anime.init(); }
49
52
  if(MyApp.anime.init_show) { MyApp.anime.init_show(); }
50
53
  }
51
-
52
54
  //]]>
53
55
  </script>
54
56
 
@@ -56,6 +58,11 @@ By looking at the compiled JavaScript output, it should be apparent on how you s
56
58
 
57
59
  As similar to `page_class`, `create` is mapped to `new` and `update` is mapped to `edit`.
58
60
 
61
+ // Sample CoffeeScript to get you started
62
+ window.MyApplication =
63
+ init: ->
64
+ console.log("Init!")
65
+
59
66
  ## #`flash_messages`
60
67
 
61
68
  This helper method prints Rails flash messages with classes that correspond to Bootstrap's convention.
data/lib/rails_utils.rb CHANGED
@@ -2,6 +2,15 @@ require 'action_view'
2
2
 
3
3
  module RailsUtils
4
4
  module ActionViewExtensions
5
+ def page_controller_class
6
+ controller.controller_name
7
+ end
8
+
9
+ def page_action_class
10
+ class_mappings = { "create" => "new", "update" => "edit" }
11
+ class_mappings[controller.action_name] || controller.action_name
12
+ end
13
+
5
14
  def page_class
6
15
  "#{page_controller_class} #{page_action_class}"
7
16
  end
@@ -34,15 +43,6 @@ module RailsUtils
34
43
 
35
44
  private
36
45
 
37
- def page_controller_class
38
- controller.controller_name
39
- end
40
-
41
- def page_action_class
42
- class_mappings = { "create" => "new", "update" => "edit" }
43
- class_mappings[controller.action_name] || controller.action_name
44
- end
45
-
46
46
  def flash_class(key)
47
47
  case key
48
48
  when :success
@@ -1,3 +1,3 @@
1
1
  module RailsUtils
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
@@ -1 +0,0 @@
1
- Rendered inline template (6.2ms)
@@ -10,31 +10,52 @@ describe "RailsUtils::ActionViewExtensions" do
10
10
  view.controller = controller
11
11
  end
12
12
 
13
- describe "#page_class" do
14
- # controller_name, action_name, expected
13
+ describe "#page_controller_class" do
14
+ let(:controller_name) { "anime" }
15
+
16
+ before { controller.stubs(:controller_name).returns(controller_name) }
17
+
18
+ it "returns controller name" do
19
+ view.page_controller_class.must_equal controller_name
20
+ end
21
+ end
22
+
23
+ describe "#page_action_class" do
24
+ # action_name, expected
15
25
  [
16
- [ "anime", "index" , "anime index" ],
17
- [ "anime", "show" , "anime show" ],
18
- [ "anime", "new" , "anime new" ],
19
- [ "anime", "create" , "anime new" ],
20
- [ "anime", "edit" , "anime edit" ],
21
- [ "anime", "update" , "anime edit" ],
22
- [ "anime", "destroy", "anime destroy" ],
23
- [ "anime", "custom" , "anime custom" ],
24
- ].each do |controller_name, action_name, expected|
25
- describe "when #{controller_name} and #{action_name}" do
26
- before do
27
- controller.stubs(:controller_name).returns(controller_name)
28
- controller.stubs(:action_name).returns(action_name)
29
- end
26
+ [ "index" , "index" ],
27
+ [ "show" , "show" ],
28
+ [ "new" , "new" ],
29
+ [ "create" , "new" ],
30
+ [ "edit" , "edit" ],
31
+ [ "update" , "edit" ],
32
+ [ "destroy", "destroy" ],
33
+ [ "custom" , "custom" ],
34
+ ].each do |action_name, expected|
35
+ describe "when ##{action_name}" do
36
+ before { controller.stubs(:action_name).returns(action_name) }
30
37
 
31
38
  it "returns #{expected}" do
32
- view.page_class.must_equal expected
39
+ view.page_action_class.must_equal expected
33
40
  end
34
41
  end
35
42
  end
36
43
  end
37
44
 
45
+ describe "#page_class" do
46
+ let(:controller_name) { "anime" }
47
+ let(:action_name) { "custom" }
48
+
49
+ before do
50
+ view.stubs(:page_controller_class).returns(controller_name)
51
+ view.stubs(:page_action_class).returns(action_name)
52
+ end
53
+
54
+ it "uses page_controller_class and page_action_class" do
55
+ view.page_class.must_equal "#{controller_name} #{action_name}"
56
+ end
57
+ end
58
+
38
59
  describe "#javascript_initialization" do
39
60
  let(:controller_name) { "anime" }
40
61
 
metadata CHANGED
@@ -1,60 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
5
- prerelease:
4
+ version: 2.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Winston Teo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-17 00:00:00.000000000 Z
11
+ date: 2013-08-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
- requirement: &70237572439820 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.2'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70237572439820
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: minitest
27
- requirement: &70237572439300 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
- version: 4.7.0
33
+ version: 4.7.5
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70237572439300
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 4.7.5
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: turn
38
- requirement: &70237572437360 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
47
  version: 0.9.6
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70237572437360
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.6
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: mocha
49
- requirement: &70237572436900 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
54
- version: 0.13.3
61
+ version: 0.14.0
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *70237572436900
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.14.0
58
69
  description: Rails helpers based on opinionated project practices. Currently useful
59
70
  for structuring CSS and JS.
60
71
  email:
@@ -100,33 +111,26 @@ files:
100
111
  - test/test_helper.rb
101
112
  homepage: https://github.com/winston/rails_utils
102
113
  licenses: []
114
+ metadata: {}
103
115
  post_install_message:
104
116
  rdoc_options: []
105
117
  require_paths:
106
118
  - lib
107
119
  required_ruby_version: !ruby/object:Gem::Requirement
108
- none: false
109
120
  requirements:
110
- - - ! '>='
121
+ - - '>='
111
122
  - !ruby/object:Gem::Version
112
123
  version: '0'
113
- segments:
114
- - 0
115
- hash: -410381614727265590
116
124
  required_rubygems_version: !ruby/object:Gem::Requirement
117
- none: false
118
125
  requirements:
119
- - - ! '>='
126
+ - - '>='
120
127
  - !ruby/object:Gem::Version
121
128
  version: '0'
122
- segments:
123
- - 0
124
- hash: -410381614727265590
125
129
  requirements: []
126
130
  rubyforge_project:
127
- rubygems_version: 1.8.17
131
+ rubygems_version: 2.0.3
128
132
  signing_key:
129
- specification_version: 3
133
+ specification_version: 4
130
134
  summary: Rails helpers based on opinionated project practices.
131
135
  test_files:
132
136
  - test/dummy/app/assets/javascripts/application.js