foundation_rails_helper 1.2.2 → 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
  SHA1:
3
- metadata.gz: f7634ed75432e1905b3d92d6349fa9eaae18518d
4
- data.tar.gz: f1dda957b096788682c423a1c980e867b794345e
3
+ metadata.gz: eaf080baa48830a883681c55c892a30b366deabc
4
+ data.tar.gz: 84a7e2dd8b70cbbe2b622a41bc9d3500bae8f396
5
5
  SHA512:
6
- metadata.gz: add778ac067c4d80c54a09c05c5abf264482a9f17708b4a7b87502e9b3014789d70e1dd1d95615cce4c13df182b7a2b2b5255170189017a49432e99a93e6e952
7
- data.tar.gz: b1af3344fd2bb825aecb4ddff12aa4775b677bf2954ab383695bb43b143a61ee2658473e89ae09aa0372bd6b08637e1277e7c1714aa1905f61ff910ddd8c5d31
6
+ metadata.gz: b578327401357039bf3ec51d10c45c86f36183f86f682ea0b303c181da14278a7a3f4de4223c92c7c451d7dccba539eec8e7799c490c855bc7a9eabd7b70cfbc
7
+ data.tar.gz: b8d41f62ad350069855247e1bdc1672c6ae08d549424768123dd67500e79eb5e1bcea1dbe820ef4e79822ec04a251f6eddf67cdde003c40bbc28e3fb725fbdbf
@@ -0,0 +1,19 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+ Include:
6
+ - Rakefile
7
+ - Gemfile
8
+ - '*.gemspec'
9
+ Exclude:
10
+ - 'vendor/**/*'
11
+
12
+ # A quick fix for not having magic comments at the top of each file
13
+ # # frozen_string_literal: true
14
+ # https://github.com/bbatsov/rubocop/issues/3284
15
+ FrozenStringLiteralComment:
16
+ Enabled: false
17
+
18
+ Documentation:
19
+ Enabled: false
@@ -0,0 +1,67 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-09-14 16:08:41 -0700 using RuboCop version 0.42.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ Lint/NestedMethodDefinition:
11
+ Exclude:
12
+ - 'spec/support/mock_rails.rb'
13
+
14
+ # Offense count: 3
15
+ Metrics/AbcSize:
16
+ Max: 179
17
+
18
+ # Offense count: 1
19
+ # Configuration parameters: CountComments.
20
+ Metrics/ClassLength:
21
+ Max: 186
22
+
23
+ # Offense count: 1
24
+ Metrics/CyclomaticComplexity:
25
+ Max: 7
26
+
27
+ # Offense count: 157
28
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
29
+ # URISchemes: http, https
30
+ Metrics/LineLength:
31
+ Max: 163
32
+
33
+ # Offense count: 5
34
+ # Configuration parameters: CountComments.
35
+ Metrics/MethodLength:
36
+ Max: 55
37
+
38
+ # Offense count: 1
39
+ # Configuration parameters: CountComments.
40
+ Metrics/ModuleLength:
41
+ Max: 102
42
+
43
+ # Offense count: 2
44
+ # Configuration parameters: CountKeywordArgs.
45
+ Metrics/ParameterLists:
46
+ Max: 8
47
+
48
+ # Offense count: 1
49
+ Metrics/PerceivedComplexity:
50
+ Max: 8
51
+
52
+ # Offense count: 3
53
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
54
+ # SupportedStyles: nested, compact
55
+ Style/ClassAndModuleChildren:
56
+ Exclude:
57
+ - 'spec/support/mock_rails.rb'
58
+
59
+ # Offense count: 1
60
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
61
+ # NamePrefix: is_, has_, have_
62
+ # NamePrefixBlacklist: is_, has_, have_
63
+ # NameWhitelist: is_a?
64
+ Style/PredicateName:
65
+ Exclude:
66
+ - 'spec/**/*'
67
+ - 'lib/foundation_rails_helper/form_builder.rb'
@@ -3,7 +3,6 @@ branches:
3
3
  only:
4
4
  - master
5
5
  rvm:
6
- - 1.9.3
7
6
  - 2.1.9
8
7
  - 2.2.5
9
8
  - 2.3.1
@@ -14,8 +13,6 @@ env:
14
13
  - "RAILS_VERSION=5.0.0"
15
14
  matrix:
16
15
  exclude:
17
- - rvm: 1.9.3
18
- env: "RAILS_VERSION=5.0.0"
19
16
  - rvm: 2.1.9
20
17
  env: "RAILS_VERSION=5.0.0"
21
18
  - rvm: 2.4.0-preview1
@@ -1,3 +1,12 @@
1
+ ## Version 2.0
2
+ This will be used for Foundation 5 support
3
+
4
+ ### Breaking changes:
5
+ * Dropped support for Ruby 1.9.3
6
+
7
+ ### Features:
8
+ * Add Rubocop code style linting
9
+
1
10
  ## Version 1.2.2
2
11
  * Fix Rails 5 deprecation warnings about alias_method_chain
3
12
  * Allow Capybara to be upgraded beyond 2.6.x
data/README.md CHANGED
@@ -16,6 +16,8 @@ So far it includes:
16
16
  * Only Rails 4.1/4.2/5 and Foundation 5 are fully supported
17
17
  * Some features may work with Foundation 4 and older, but results may vary, and markup which exists only for those versions will be gradually removed
18
18
  * Legacy branches exist for Rails 3 and 4.0 (see the rails3 and rails4.0 branches). These are not actively supported, and fixes are not retroactively applied, but pull requests are welcome.
19
+ * We test against ruby versions 2.1 and up. This gem may still work fine on
20
+ 1.9.3, but your mileage may vary
19
21
 
20
22
 
21
23
  ## Screenshots
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
3
3
  require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
4
5
 
5
6
  RSpec::Core::RakeTask.new(:spec)
6
- task :default => :spec
7
+ RuboCop::RakeTask.new(:rubocop)
8
+ task default: [:spec, :rubocop]
@@ -2,26 +2,26 @@
2
2
  require File.expand_path('../lib/foundation_rails_helper/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Sebastien Gruhier"]
6
- gem.email = ["sebastien.gruhier@xilinus.com"]
7
- gem.description = %q{Rails for zurb foundation CSS framework. Form builder, flash message, ...}
8
- gem.summary = %q{Rails helpers for zurb foundation CSS framework}
9
- gem.homepage = "http://github.com/sgruhier/foundation_rails_helper"
5
+ gem.authors = ['Sebastien Gruhier']
6
+ gem.email = ['sebastien.gruhier@xilinus.com']
7
+ gem.description = 'Rails for zurb foundation CSS framework. Form builder, flash message, ...'
8
+ gem.summary = 'Rails helpers for zurb foundation CSS framework'
9
+ gem.homepage = 'http://github.com/sgruhier/foundation_rails_helper'
10
10
 
11
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
12
12
  gem.files = `git ls-files`.split("\n")
13
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
- gem.name = "foundation_rails_helper"
15
- gem.require_paths = ["lib"]
14
+ gem.name = 'foundation_rails_helper'
15
+ gem.require_paths = ['lib']
16
16
  gem.version = FoundationRailsHelper::VERSION
17
17
  gem.license = 'MIT'
18
18
 
19
19
  # Allow different versions of the rails gems to be specified, for testing:
20
- rails_version = ENV["RAILS_VERSION"] || "default"
20
+ rails_version = ENV['RAILS_VERSION'] || 'default'
21
21
 
22
22
  rails = case rails_version
23
- when "default"
24
- ">= 4.1"
23
+ when 'default'
24
+ '>= 4.1'
25
25
  else
26
26
  "~> #{rails_version}"
27
27
  end
@@ -35,4 +35,5 @@ Gem::Specification.new do |gem|
35
35
  gem.add_development_dependency 'rspec-rails', '>= 3.1'
36
36
  gem.add_development_dependency 'mime-types', '~> 2'
37
37
  gem.add_development_dependency 'capybara', '~> 2.7'
38
+ gem.add_development_dependency 'rubocop', '> 0.41'
38
39
  end
@@ -1,8 +1,8 @@
1
- require "foundation_rails_helper/version"
2
- require "foundation_rails_helper/configuration"
3
- require "foundation_rails_helper/form_builder"
4
- require "foundation_rails_helper/flash_helper"
5
- require "foundation_rails_helper/action_view_extension"
1
+ require 'foundation_rails_helper/version'
2
+ require 'foundation_rails_helper/configuration'
3
+ require 'foundation_rails_helper/form_builder'
4
+ require 'foundation_rails_helper/flash_helper'
5
+ require 'foundation_rails_helper/action_view_extension'
6
6
  ActiveSupport.on_load(:action_view) do
7
7
  include FoundationRailsHelper::FlashHelper
8
8
  end
@@ -1,4 +1,4 @@
1
1
  ActionView::Base.default_form_builder = FoundationRailsHelper::FormBuilder
2
- ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
2
+ ActionView::Base.field_error_proc = proc do |html_tag, _instance_tag|
3
3
  html_tag
4
4
  end
@@ -7,14 +7,14 @@ module FoundationRailsHelper
7
7
  # <a href="" class="close">&times;</a>
8
8
  # </div>
9
9
  DEFAULT_KEY_MATCHING = {
10
- :alert => :alert,
11
- :notice => :success,
12
- :info => :info,
13
- :secondary => :secondary,
14
- :success => :success,
15
- :error => :alert,
16
- :warning => :warning
17
- }
10
+ alert: :alert,
11
+ notice: :success,
12
+ info: :info,
13
+ secondary: :secondary,
14
+ success: :success,
15
+ error: :alert,
16
+ warning: :warning
17
+ }.freeze
18
18
  def display_flash_messages(key_matching = {})
19
19
  key_matching = DEFAULT_KEY_MATCHING.merge(key_matching)
20
20
  key_matching.default = :standard
@@ -28,18 +28,17 @@ module FoundationRailsHelper
28
28
  end
29
29
  end
30
30
 
31
- private
31
+ private
32
32
 
33
33
  def alert_box(value, alert_class)
34
- content_tag :div, :data => { :alert => "" }, :class => "alert-box #{alert_class}" do
34
+ content_tag :div, data: { alert: '' }, class: "alert-box #{alert_class}" do
35
35
  concat value
36
36
  concat close_link
37
37
  end
38
38
  end
39
39
 
40
40
  def close_link
41
- link_to("&times;".html_safe, "#", :class => :close)
41
+ link_to('&times;'.html_safe, '#', class: :close)
42
42
  end
43
-
44
43
  end
45
44
  end
@@ -37,9 +37,7 @@ module FoundationRailsHelper
37
37
  options[:label_options] ||= {}
38
38
  label_options = options.delete(:label_options).merge!(value: tag_value)
39
39
  label_text = options.delete(:label)
40
- unless label_text == false
41
- l = label(attribute, label_text, label_options)
42
- end
40
+ l = label(attribute, label_text, label_options) unless label_text == false
43
41
  r = @template.radio_button(@object_name, attribute, tag_value,
44
42
  objectify_options(options))
45
43
 
@@ -48,26 +46,26 @@ module FoundationRailsHelper
48
46
 
49
47
  def password_field(attribute, options = {})
50
48
  field attribute, options do |opts|
51
- super(attribute, opts.merge(:autocomplete => :off))
49
+ super(attribute, opts.merge(autocomplete: :off))
52
50
  end
53
51
  end
54
52
 
55
53
  def datetime_select(attribute, options = {}, html_options = {})
56
54
  field attribute, options, html_options do |html_opts|
57
- super(attribute, options, html_opts.merge(:autocomplete => :off))
55
+ super(attribute, options, html_opts.merge(autocomplete: :off))
58
56
  end
59
57
  end
60
58
 
61
59
  def date_select(attribute, options = {}, html_options = {})
62
60
  field attribute, options, html_options do |html_opts|
63
- super(attribute, options, html_opts.merge(:autocomplete => :off))
61
+ super(attribute, options, html_opts.merge(autocomplete: :off))
64
62
  end
65
63
  end
66
64
 
67
65
  def time_zone_select(attribute, priorities = nil, options = {}, html_options = {})
68
66
  field attribute, options, html_options do |html_opts|
69
67
  super(attribute, priorities, options,
70
- html_opts.merge(:autocomplete => :off))
68
+ html_opts.merge(autocomplete: :off))
71
69
  end
72
70
  end
73
71
 
@@ -96,8 +94,8 @@ module FoundationRailsHelper
96
94
 
97
95
  def autocomplete(attribute, url, options = {})
98
96
  field attribute, options do |opts|
99
- opts.merge!(:update_elements => opts[:update_elements],
100
- :min_length => 0, :value => object.send(attribute))
97
+ opts.merge!(update_elements: opts[:update_elements],
98
+ min_length: 0, value: object.send(attribute))
101
99
  autocomplete_field(attribute, url, opts)
102
100
  end
103
101
  end
@@ -107,7 +105,7 @@ module FoundationRailsHelper
107
105
  super(value, options)
108
106
  end
109
107
 
110
- private
108
+ private
111
109
 
112
110
  def has_error?(attribute)
113
111
  object.respond_to?(:errors) && !object.errors[attribute].blank?
@@ -121,11 +119,11 @@ module FoundationRailsHelper
121
119
 
122
120
  error_messages = object.errors[attribute].join(', ')
123
121
  error_messages = error_messages.html_safe if options[:html_safe_errors]
124
- content_tag(:small, error_messages, :class => class_name)
122
+ content_tag(:small, error_messages, class: class_name)
125
123
  end
126
124
 
127
- def custom_label(attribute, text, options, &block)
128
- return block_given? ? block.call.html_safe : ''.html_safe if text == false
125
+ def custom_label(attribute, text, options)
126
+ return block_given? ? yield.html_safe : ''.html_safe if text == false
129
127
  if text.nil? || text == true
130
128
  text =
131
129
  if object.class.respond_to?(:human_attribute_name)
@@ -134,31 +132,52 @@ module FoundationRailsHelper
134
132
  attribute.to_s.humanize
135
133
  end
136
134
  end
137
- text = block.call.html_safe + " #{text}" if block_given?
135
+ text = yield.html_safe + " #{text}" if block_given?
138
136
  options ||= {}
139
137
  label(attribute, text, options)
140
138
  end
141
139
 
142
140
  def column_classes(options)
143
- classes = ''
144
- if options[:small].present? && options[:small].to_i < 12
145
- classes += "small-#{options[:small]} "
141
+ classes = SizeClassCalcluator.new(options).classes
142
+ classes + ' columns'
143
+ end
144
+
145
+ class SizeClassCalcluator
146
+ def initialize(size_options)
147
+ @small = size_options[:small]
148
+ @medium = size_options[:medium]
149
+ @large = size_options[:large]
150
+ end
151
+
152
+ def classes
153
+ [small_class, medium_class, large_class].compact.join(' ')
154
+ end
155
+
156
+ private
157
+
158
+ def small_class
159
+ "small-#{@small}" if valid_size(@small)
146
160
  end
147
- if options[:medium].present? && options[:medium].to_i < 12
148
- classes += "medium-#{options[:medium]} "
161
+
162
+ def medium_class
163
+ "medium-#{@medium}" if valid_size(@medium)
149
164
  end
150
- if options[:large].present? && options[:large].to_i < 12
151
- classes += "large-#{options[:large]} "
165
+
166
+ def large_class
167
+ "large-#{@large}" if valid_size(@large)
168
+ end
169
+
170
+ def valid_size(value)
171
+ value.present? && value.to_i < 12
152
172
  end
153
- classes + 'columns'
154
173
  end
155
174
 
156
175
  def tag_from_options(name, options)
157
176
  return ''.html_safe unless options && options[:value].present?
158
177
 
159
178
  content_tag(:div,
160
- content_tag(:span, options[:value], :class => name),
161
- :class => "#{ column_classes( options ) }")
179
+ content_tag(:span, options[:value], class: name),
180
+ class: column_classes(options).to_s)
162
181
  end
163
182
 
164
183
  def decrement_input_size(input, column, options)
@@ -191,12 +210,12 @@ module FoundationRailsHelper
191
210
  postfix = tag_from_options('postfix', postfix_options)
192
211
 
193
212
  input_size = calculate_input_size(prefix_options, postfix_options)
194
- klass = "#{column_classes(input_size.marshal_dump)}"
195
- input = content_tag(:div, block, :class => klass)
213
+ klass = column_classes(input_size.marshal_dump).to_s
214
+ input = content_tag(:div, block, class: klass)
196
215
 
197
216
  html =
198
217
  if input_size.changed?
199
- content_tag(:div, prefix + input + postfix, :class => "row collapse")
218
+ content_tag(:div, prefix + input + postfix, class: 'row collapse')
200
219
  else
201
220
  block
202
221
  end
@@ -206,20 +225,18 @@ module FoundationRailsHelper
206
225
 
207
226
  def error_and_hint(attribute, options = {})
208
227
  html = ''
209
- if options[:hint]
210
- html += content_tag(:span, options[:hint], :class => :hint)
211
- end
228
+ html += content_tag(:span, options[:hint], class: :hint) if options[:hint]
212
229
  html += error_for(attribute, options) || ''
213
230
  html.html_safe
214
231
  end
215
232
 
216
- def field(attribute, options, html_options = nil, &block)
233
+ def field(attribute, options, html_options = nil)
217
234
  auto_labels = true unless @options[:auto_labels] == false
218
- if auto_labels || options[:label]
219
- html = custom_label(attribute, options[:label], options[:label_options])
220
- else
221
- html = ''.html_safe
222
- end
235
+ html = if auto_labels || options[:label]
236
+ custom_label(attribute, options[:label], options[:label_options])
237
+ else
238
+ ''.html_safe
239
+ end
223
240
  class_options = html_options || options
224
241
 
225
242
  if has_error?(attribute)
@@ -1,3 +1,3 @@
1
1
  module FoundationRailsHelper
2
- VERSION = "1.2.2"
2
+ VERSION = '2.0.0'.freeze
3
3
  end