classnames-rails-view 0.1.3 → 2.0.0

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
  SHA256:
3
- metadata.gz: 93e4f68405abfd23a096ddf7454d171cf3d4a842e49f90f6778795c11390f515
4
- data.tar.gz: 1131a506fc35726c83131e5a4ae29ef4645b2df11f9b80fbcd6da7c76469b383
3
+ metadata.gz: 967a111319da073632bf349111353f6074e9ceb79e6f4d04c337c902ef147bc3
4
+ data.tar.gz: 8a2b9de3353e96b76ef19bd0e26b70fedda72cb01755629349d92198e4be7aaf
5
5
  SHA512:
6
- metadata.gz: 67d396e0439f907887915e20abb45ce014285fb492c529c425569400c184e2005718b5ae48f30e2797c4ce43462f85adbbd8f0da98539ec1b8e8ac212a411138
7
- data.tar.gz: 3b3cec22ab7ff96299f57ecf9b0a8e0c05a7c7c861991eaa866bc86958ab45663b9f4f3c2c3afdb5767e5b3d53fce7fe52bd0be77510d8941897f1b79c01d3d7
6
+ metadata.gz: cbce757f98992d4255bfd4fc2db79ef5ff224a713d4ab6a243c1d540b7a7310835690270200dac9f42479078bc6381348910a947de708c985d1f6f3666c31cc0
7
+ data.tar.gz: fac01677b331fcfe91347cd1a0a317ed968b45036b8afba6f5186a2bd2f3f24c89274f2d697ceb825be3126ef51376c95374f674f47ceb3f0b45b0c0b88aee87
data/README.md CHANGED
@@ -6,33 +6,33 @@ This is a view helper that dynamically generates class attributes in Rails view,
6
6
  The Helper method is included automatically, so you can use it immediately.
7
7
 
8
8
  ```erb
9
- <div class="<%= classNames('foo') %>">Hello World</div>
9
+ <div class="<%= class_names('foo') %>">Hello World</div>
10
10
  <%# <div class="foo">Hello World</div> %>
11
11
  ```
12
12
 
13
- The `classNames` method takes any number of arguments which can be a string or hash.
13
+ The `class_names` method takes any number of arguments which can be a string or hash.
14
14
  The argument `'foo'` is short for `{ foo: true }`. If the value associated with a given key is falsy, that key won't be included in the output.
15
15
 
16
16
  ```js
17
- classNames('foo', 'bar'); // => 'foo bar'
18
- classNames('foo', { bar: true }); // => 'foo bar'
19
- classNames({ 'foo-bar': true }); // => 'foo-bar'
20
- classNames({ 'foo-bar': false }); // => ''
21
- classNames({ foo: true }, { bar: true }); // => 'foo bar'
22
- classNames({ foo: true, bar: true }); // => 'foo bar'
17
+ class_names('foo', 'bar'); // => 'foo bar'
18
+ class_names('foo', { bar: true }); // => 'foo bar'
19
+ class_names({ 'foo-bar': true }); // => 'foo-bar'
20
+ class_names({ 'foo-bar': false }); // => ''
21
+ class_names({ foo: true }, { bar: true }); // => 'foo bar'
22
+ class_names({ foo: true, bar: true }); // => 'foo bar'
23
23
 
24
24
  // lots of arguments of various types
25
- classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'
25
+ class_names('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'
26
26
 
27
27
  // other falsy values are just ignored
28
- classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
28
+ class_names(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
29
29
  ```
30
30
 
31
31
  Arrays will be recursively flattened as per the rules above:
32
32
 
33
33
  ```js
34
34
  var arr = ['b', { c: true, d: false }];
35
- classNames('a', arr); // => 'a b c'
35
+ class_names('a', arr); // => 'a b c'
36
36
  ```
37
37
 
38
38
  ### Change the method name
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'bundler/setup'
3
5
  rescue LoadError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Classnames
2
4
  module Rails
3
5
  module View
@@ -19,4 +21,4 @@ module Classnames
19
21
  end
20
22
  end
21
23
 
22
- ActionView::Base.send :include, Classnames::Rails::View::Helper
24
+ ActionView::Base.include Classnames::Rails::View::Helper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Classnames
2
4
  module Rails
3
5
  module View
@@ -10,9 +12,7 @@ module Classnames
10
12
 
11
13
  def detect_elem(elem)
12
14
  if elem.is_a?(Hash)
13
- elem.inject '' do |out, (key, value)|
14
- value ? out << key.to_s << ' ' : out
15
- end.strip
15
+ elem.filter {|_k, v| v }.map {|k, _v| k }.join(' ')
16
16
  elsif elem.is_a?(Array)
17
17
  inject_values elem
18
18
  elsif elem == false
@@ -23,10 +23,7 @@ module Classnames
23
23
  end
24
24
 
25
25
  def inject_values(values)
26
- values.inject '' do |out, value|
27
- detected = detect_elem(value)
28
- detected == '' ? out : out << detect_elem(value) << ' '
29
- end.strip
26
+ values.map {|value| detect_elem(value) }.reject(&:empty?).join(' ')
30
27
  end
31
28
  end
32
29
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Classnames
2
4
  module Rails
3
5
  module View
4
6
  class Railtie < ::Rails::Railtie
5
7
  config.classnames_rails_view = ActiveSupport::OrderedOptions.new
6
- config.classnames_rails_view.method_name = :classNames
8
+ config.classnames_rails_view.method_name = :class_names
7
9
 
8
10
  config.after_initialize do |_app|
9
11
  require 'classnames/rails/view/action_view'
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Classnames
2
4
  module Rails
3
5
  module View
4
- VERSION = '0.1.3'.freeze
6
+ VERSION = '2.0.0'
5
7
  end
6
8
  end
7
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Classnames
2
4
  module Rails
3
5
  module View
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'classnames/rails/view'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # desc "Explaining what the task does"
2
4
  # task :classnames_rails_view do
3
5
  # # Task goes here
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classnames-rails-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masamoto Miyata
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-11 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,9 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.0'
20
- - - "<"
20
+ - - "<="
21
21
  - !ruby/object:Gem::Version
22
- version: '5.3'
22
+ version: 6.1.4.4
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +27,9 @@ dependencies:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '5.0'
30
- - - "<"
30
+ - - "<="
31
31
  - !ruby/object:Gem::Version
32
- version: '5.3'
32
+ version: 6.1.4.4
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: pry-byebug
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: '3.10'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '='
115
+ - !ruby/object:Gem::Version
116
+ version: '3.10'
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: rspec-rails
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +128,34 @@ dependencies:
114
128
  - - ">="
115
129
  - !ruby/object:Gem::Version
116
130
  version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '='
136
+ - !ruby/object:Gem::Version
137
+ version: 0.75.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '='
143
+ - !ruby/object:Gem::Version
144
+ version: 0.75.0
145
+ - !ruby/object:Gem::Dependency
146
+ name: rubocop-rails
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
117
159
  - !ruby/object:Gem::Dependency
118
160
  name: sqlite3
119
161
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +192,7 @@ homepage: https://github.com/gomo/classnames-rails-view
150
192
  licenses:
151
193
  - MIT
152
194
  metadata: {}
153
- post_install_message:
195
+ post_install_message:
154
196
  rdoc_options: []
155
197
  require_paths:
156
198
  - lib
@@ -158,16 +200,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
200
  requirements:
159
201
  - - ">="
160
202
  - !ruby/object:Gem::Version
161
- version: '0'
203
+ version: 2.6.0
162
204
  required_rubygems_version: !ruby/object:Gem::Requirement
163
205
  requirements:
164
206
  - - ">="
165
207
  - !ruby/object:Gem::Version
166
208
  version: '0'
167
209
  requirements: []
168
- rubyforge_project:
169
- rubygems_version: 2.7.6
170
- signing_key:
210
+ rubygems_version: 3.2.32
211
+ signing_key:
171
212
  specification_version: 4
172
213
  summary: The helper method to dynamically generate class attribute of HTML tag.
173
214
  test_files: []