rails_utils 3.1.2 → 3.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 575576983b143a63084e04cfc17aaf964bce0b1f
4
- data.tar.gz: 60e890dd30557ea66e3d6c4fc8b5ed42610f7269
3
+ metadata.gz: 4fc2649ebeba860870f2999dbb5ddaa99989764c
4
+ data.tar.gz: 5cbd6201a7d3d2d6d5fa22237189437141ec0099
5
5
  SHA512:
6
- metadata.gz: 9149e4e80dbbdb9c0c136d01facdfa732add09dc195a4f07cefd94574b2773dd253b566b3ac8aad219af974288c2de7812ec93a143a7744ccaa9428924ceba25
7
- data.tar.gz: 2c488bf0acf4ebd3760cd2d4ca91a93b76936fffba7507a9892e180d4ca2f52fa54b611ab37426482288a86396885e3549435cb96b2d8b5cfdb57823680af3a3
6
+ metadata.gz: 5b60acb1cbe5f6e198764153720195b9f9283f049d95a2f98f6f6408fc873a20cb6da1b7df338d5e09a3120858ee329327fea3391e9203021044e1a7d1f3805c
7
+ data.tar.gz: 3de6f653754c0edc375b9fc855943c5e7148dad0a1eb16b14a6db86347c8b23067a3d5ffb5036cd9f425db20095975f05fcc288b5119c77a34d2ac098f29adb4
data/README.markdown CHANGED
@@ -40,6 +40,26 @@ so that you only need to write CSS to target `new` and `edit`, and not all four
40
40
  For finer grained control, you can also choose the use the 2 methods that are used to build `page_class` individually.
41
41
  The two methods are `page_controller_class` and `page_action_class`.
42
42
 
43
+ ## #`page_title`
44
+
45
+ This helper method returns page title based on controller name and action name.
46
+
47
+ When controller and action is `anime#show`
48
+ you can easily use `page_title` like
49
+
50
+ .page-title= page_title
51
+
52
+ becomes
53
+
54
+ <div class='page-title'>Anime Show</div>
55
+
56
+ Besides, it supports I18n too.
57
+
58
+ en:
59
+ anime:
60
+ show:
61
+ title: An awesome title
62
+
43
63
  ## #`javascript_initialization`
44
64
 
45
65
  This helper method attempts to initialize JavaScript classes and methods based on a standard structure.
@@ -95,6 +115,11 @@ Minitest-ed. To run all tests, just run `rake` or `rake test`.
95
115
 
96
116
  ## Changelog
97
117
 
118
+ _Version 3.2.0_
119
+
120
+ - Add `page_title` that supports I18n - by @huynhquancam.
121
+
122
+
98
123
  _Version 3.1.2_
99
124
 
100
125
  - Add `alert-danger` class to flash error messages for Bootstrap 3 support.
@@ -123,4 +148,4 @@ Rails Utils is maintained by [Winston Teo](mailto:winstonyw+rails_utils@gmail.co
123
148
 
124
149
  ## License
125
150
 
126
- Copyright © 2013 Winston Teo Yong Wei. Free software, released under the MIT license.
151
+ Copyright © 2014 Winston Teo Yong Wei. Free software, released under the MIT license.
@@ -1,3 +1,3 @@
1
1
  module RailsUtils
2
- VERSION = "3.1.2"
2
+ VERSION = "3.2.0"
3
3
  end
data/lib/rails_utils.rb CHANGED
@@ -15,6 +15,11 @@ module RailsUtils
15
15
  "#{page_controller_class} #{page_action_class}"
16
16
  end
17
17
 
18
+ def page_title
19
+ default_page_title = "#{page_controller_class.capitalize} #{page_action_class.capitalize}"
20
+ I18n.t("#{page_controller_class}.#{page_action_class}.title", default: default_page_title)
21
+ end
22
+
18
23
  def javascript_initialization
19
24
  application_name = Rails.application.class.parent_name
20
25
 
@@ -70,6 +70,34 @@ describe "RailsUtils::ActionViewExtensions" do
70
70
  end
71
71
  end
72
72
 
73
+ describe "#page_title" do
74
+ let(:controller_name) { "anime" }
75
+
76
+ before do
77
+ view.stubs(:page_controller_class).returns(controller_name)
78
+ view.stubs(:page_action_class).returns(action_name)
79
+ end
80
+
81
+ describe 'when translation is missing' do
82
+ let(:action_name) { "random" }
83
+ let(:default_translation) { "#{controller_name.capitalize} #{action_name.capitalize}" }
84
+
85
+ it "combines page_controller_class and page_action_class" do
86
+ view.page_title.must_equal default_translation
87
+ end
88
+ end
89
+
90
+ describe 'when translation is avaiable' do
91
+ let(:action_name) { 'show' }
92
+
93
+ before { I18n.backend.store_translations("en", {controller_name.to_sym => {action_name.to_sym => {title: "An awesome title"}}}) }
94
+
95
+ it 'translates page title' do
96
+ view.page_title.must_equal 'An awesome title'
97
+ end
98
+ end
99
+ end
100
+
73
101
  describe "#javascript_initialization" do
74
102
  let(:controller_class) { "Awesome::AnimeController" }
75
103
  let(:controller_name) { "awesome_anime" }
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.1.2
4
+ version: 3.2.0
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-06-23 00:00:00.000000000 Z
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.0.6
132
+ rubygems_version: 2.1.9
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Rails helpers based on opinionated project practices.