rails_utils 3.3.5 → 3.3.6

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: 62874537daa9a28165f507ea6ab01842d59d3923
4
- data.tar.gz: ec5e57344d53efbf67eb98ab94ba2a8b9300efeb
3
+ metadata.gz: ca8126cf30f04a6410c38ebe21bff67a8bbf2cb1
4
+ data.tar.gz: f2b9f88ae90d694873add1150c0c33235ccb546a
5
5
  SHA512:
6
- metadata.gz: 14ca4eca82e4bba2d1a070ccad0d6064df49073c8944dc9259f696d134127951407e0dd11731fea59b98e71379ea3f84bdb93e3e1af23921cd799ef28bbb46f6
7
- data.tar.gz: 4c786fc854c62c6e64fe761e378a4a835baf02cbf64d260a9129b1881aa613777991ec8ffda48f48dc759a6d12746322325ef7dc93d7c75d23ad8ecf3481755b
6
+ metadata.gz: ad2a51666570a073cc271859b88560f35ecbb1bdb1e37ddf249e466ed6605f3277c5c5f815fe6b970dfcc53bb345d4451ce544064acf9127a403a1491d0d3763
7
+ data.tar.gz: 64a6f6c494b22a7266ea78966f34f2032bc1708130a1955603a18e653f50ee73e1322f122211dc11ce05d02f003d38595f872511f01df9bd35892593c5e67f80
data/MIT-LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2013 Winston Teo Yong Wei
3
+ Copyright (c) 2013-2016 Winston Teo Yong Wei
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person
6
6
  obtaining a copy of this software and associated documentation files (the "Software"),
@@ -19,4 +19,4 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
19
19
  FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
20
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
21
  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22
- OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,16 +1,25 @@
1
- # Rails Utils
1
+ # Rails Utils [![Gem Version][version-badge]][rubygems] [![Build Status][travis-badge]][travis]
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/rails_utils.svg)](http://badge.fury.io/rb/rails_utils)
4
- [![Build Status](https://travis-ci.org/winston/rails_utils.svg)](https://travis-ci.org/winston/rails_utils)
5
-
6
- Rails helpers based on opinionated project practices. Currently useful for structuring CSS and JS.
3
+ Rails helpers based on opinionated project practices. Useful for structuring CSS and JavaScript,
4
+ display title of the page, and flash messages with Bootstrap.
7
5
 
8
6
  ## Installation
9
7
 
8
+ Add rails_utils to your application's Gemfile:
9
+
10
+ gem 'rails_utils'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
10
18
  gem install 'rails_utils'
11
19
 
20
+ ## Usage
12
21
 
13
- ## #`page_class`
22
+ ### #`page_class`
14
23
 
15
24
  This helper method returns controller name and action name as a single string value,
16
25
  which can be used to target CSS styles specifically for this controller or action.
@@ -18,99 +27,147 @@ which can be used to target CSS styles specifically for this controller or actio
18
27
  For example, when controller and action is `animes#show`,
19
28
  you can use `page_class` to include the controller name and action name as CSS classes on the page.
20
29
 
21
- %body{ class: page_class }
30
+ ```html+erb
31
+ <body class=<%= page_class %>>
32
+ ...
33
+ </body>
34
+ ```
22
35
 
23
36
  becomes
24
37
 
25
- <body class='animes show'>
38
+ ```html
39
+ <body class='animes show'>
40
+ ...
41
+ </body>
42
+ ```
26
43
 
27
44
  Then in your CSS, you can either target your styles specific to controller and/or action.
28
45
 
29
- body.animes
30
- background: black
46
+ ```css
47
+ body.animes {
48
+ background: black;
49
+ }
31
50
 
32
- body.animes.show
33
- font-size: 24px
51
+ body.animes.show {
52
+ font-size: 24px;
53
+ }
54
+ ```
34
55
 
35
- Usually, when the `create` or `update` actions render, the `new` or `edit` views will be rendered due to a form error.
56
+ Usually, when the `create` or `update` actions render, the `new` or `edit` views will be rendered
57
+ due to a form error.
36
58
 
37
59
  Therefore the `page_class` helper converts `create` to `new` and `update` to `edit`
38
60
  so that you only need to write CSS to target `new` and `edit`, and not all four actions.
39
61
 
40
- For finer grained control, you can also choose the use the 2 methods that are used to build `page_class` individually.
62
+ For finer grained control, you can also choose the use the 2 methods that are used to build
63
+ `page_class` individually.
64
+
41
65
  The two methods are `page_controller_class` and `page_action_class`.
42
66
 
43
- ## #`page_title`
67
+ ### #`page_title`
44
68
 
45
69
  This helper method returns page title based on controller name and action name.
46
70
 
47
- When controller and action is `animes#show`
48
- you can easily use `page_title` like
71
+ When controller and action is `animes#show` you can easily use `page_title` like:
49
72
 
50
- .page-title= page_title
73
+ ```html+erb
74
+ <div class="page-title">
75
+ <%= page_title %>
76
+ </div>
77
+ ```
51
78
 
52
79
  becomes
53
80
 
54
- <div class='page-title'>Animes Show</div>
81
+ ```html
82
+ <div class="page-title">
83
+ Animes Show
84
+ </div>
85
+ ```
55
86
 
56
87
  Besides, it supports I18n and interpolation:
57
88
 
58
- en:
59
- animes:
60
- show:
61
- title: Showing anime of: %{anime_name}
89
+ ```yaml
90
+ en:
91
+ animes:
92
+ show:
93
+ title: Showing anime of: %{anime_name}
94
+ ```
95
+
96
+ Pass in `anime_name`:
62
97
 
63
- .page-title= page_title(anime_name: 'Frozen')
98
+ ```html+erb
99
+ <div class="page-title">
100
+ <%= page_title(anime_name: "Frozen") %>
101
+ </div>
102
+ ```
64
103
 
65
104
  becomes
66
105
 
67
- <div class='page-title'>Showing anime of: Frozen</div>
106
+ ```html
107
+ <div class="page-title">
108
+ Showing anime of: Frozen
109
+ </div>
110
+ ```
68
111
 
69
- ## #`javascript_initialization`
112
+ ### #`javascript_initialization`
70
113
 
71
114
  This helper method attempts to initialize JavaScript classes and methods based on a standard structure.
72
115
 
73
116
  With this standard structure, calling your JavaScript has never been easier.
74
117
 
75
- Add `javascript_initialization` to the bottom of your layout.
76
-
77
- = javascript_initialization
118
+ Add `javascript_initialization` to the bottom of your layout:
78
119
 
79
- When application is MyApp, and controller/action is `animes#show`, `javascript_initialization` compiles to:
120
+ ```erb
121
+ <%= javascript_initialization %>
122
+ ```
80
123
 
81
- <script type="text/javascript">
82
- //<![CDATA[
83
- MyApp.init();
84
- if(MyApp.animes) {
85
- if(MyApp.animes.init) { MyApp.animes.init(); }
86
- if(MyApp.animes.init_show) { MyApp.animes.init_show(); }
87
- }
88
- //]]>
89
- </script>
124
+ When application is `MyApp`, and controller/action is `animes#show`, `javascript_initialization`
125
+ compiles to:
126
+
127
+ ```html
128
+ <script type="text/javascript">
129
+ //<![CDATA[
130
+ MyApp.init();
131
+ if(MyApp.animes) {
132
+ if(MyApp.animes.init) { MyApp.animes.init(); }
133
+ if(MyApp.animes.show && MyApp.animes.show.init) { MyApp.animes.show.init(); }
134
+ }
135
+ //]]>
136
+ </script>
137
+ ```
90
138
 
91
- By looking at the compiled JavaScript output, it should be apparent on how you should structure your JavaScript.
139
+ By looking at the compiled JavaScript output, it should be apparent on how you should structure
140
+ your JavaScript:
92
141
 
93
- As similar to `page_class`, `create` is mapped to `new` and `update` is mapped to `edit`.
142
+ ```JavaScript
143
+ // Sample application.js
144
+ window.MyApp = {
145
+ init: function() {
146
+ console.log("Init!")
147
+ }
148
+ }
149
+ ```
94
150
 
95
- // Sample CoffeeScript to get you started
96
- window.MyApplication =
97
- init: ->
98
- console.log("Init!")
151
+ As similar to [`page_class`](#page_class), `create` is mapped to `new` and `update` is mapped to `edit`.
99
152
 
100
- ## #`flash_messages`
153
+ ### #`flash_messages`
101
154
 
102
155
  This helper method prints Rails flash messages with classes that correspond to Bootstrap's convention.
103
156
 
104
157
  Just invoke `flash_messages` anywhere within `layout/application`.
105
158
 
106
- = flash_messages
159
+ ```html+erb
160
+ <%= flash_messages %>
161
+ ```
107
162
 
108
163
  Suppose there's a `flash[:success]`, you should see:
109
164
 
110
- <div class="alert alert-success fade in">
111
- <button class="close" data-dismiss-alert="alert" type="button">x</button>
112
- <p>flash is success</p>
113
- </div>
165
+ ```html
166
+ <div class="alert alert-success fade in">
167
+ <button class="close" data-dismiss-alert="alert" type="button">x</button>
168
+ <p>flash is success</p>
169
+ </div>
170
+ ```
114
171
 
115
172
  You can also:
116
173
 
@@ -119,7 +176,7 @@ You can also:
119
176
 
120
177
  ## Configuration
121
178
 
122
- Override any of these defaults in `config/initializers/rails_utils.rb`
179
+ Override any of these defaults in `config/initializers/rails_utils.rb`:
123
180
 
124
181
  ```ruby
125
182
  RailsUtils.configure do |config|
@@ -141,4 +198,10 @@ Rails Utils is maintained by [Winston Teo](mailto:winstonyw+rails_utils@gmail.co
141
198
 
142
199
  ## License
143
200
 
144
- Copyright © 2014 Winston Teo Yong Wei. Free software, released under the MIT license.
201
+ Copyright © 2013-2016 Winston Teo Yong Wei. Free software, released under the MIT license.
202
+
203
+
204
+ [version-badge]: https://badge.fury.io/rb/rails_utils.svg
205
+ [rubygems]: https://rubygems.org/gems/rails_utils
206
+ [travis-badge]: https://travis-ci.org/winston/rails_utils.svg
207
+ [travis]: https://travis-ci.org/winston/rails_utils
data/lib/rails_utils.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'rails_utils/configuration'
2
- require 'action_view'
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_utils/configuration"
4
+ require "action_view"
3
5
 
4
6
  module RailsUtils
5
7
  module ActionViewExtensions
@@ -52,7 +54,7 @@ module RailsUtils
52
54
  def flash_messages(options = {})
53
55
  flash.collect do |key, message|
54
56
  next if message.blank?
55
- next if key.to_s == 'timedout'
57
+ next if key.to_s == "timedout"
56
58
 
57
59
  content_tag(:div, content_tag(:button, options[:button_html] || "x", type: "button", class: options[:button_class] || "close", "data-dismiss" => "alert") + message.html_safe, class: "#{flash_class(key)} fade in #{options[:class]}")
58
60
  end.join("\n").html_safe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsUtils
2
- VERSION = "3.3.5"
4
+ VERSION = "3.3.6"
3
5
  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.5
4
+ version: 3.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winston Teo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-09 00:00:00.000000000 Z
11
+ date: 2016-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.2.2
103
+ rubygems_version: 2.6.1
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Rails helpers based on opinionated project practices.