foundation_rails_helper 0.5.0 → 1.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: b91634e14b82386a58ec5123c79bbf9a7cc00e2c
4
- data.tar.gz: f668d1586441afb62f4308352eeb81cc8e1a1526
3
+ metadata.gz: 8778cbf569b219f1dc900b76ccc9dbce91f14352
4
+ data.tar.gz: 2f04eeda4780f7ea097fc6489b522089c3828799
5
5
  SHA512:
6
- metadata.gz: d2d484df58203229b48594064fdf2ca2977924620e4c6c36bc8a9a4fb3b1ec3721a3b295f1599242fd872f94d6712408c130d407a744b6395b371729179bba7b
7
- data.tar.gz: e50a0e0e2ff994a6d3f11b73af3655c9bc4ae8f85518c9b1d43ddcc92f5d619636215cdc157d46f8256d4333424a83ff84a4f05aef6097249edb7009440d8578
6
+ metadata.gz: 95f6960132fbfc01eba7fc1490897c3d67bbf9ea6fb678ef8ac478bc9a75421be821bb98d1f4e224ac5d3ec8bda5ae912d7bc596033c23b67126d37f7279d150
7
+ data.tar.gz: 44739788edf92dd99efdf494081aee4a5930d367e79750a987d9d336b8552351de84d464ea11470eb9fb1a620d0d95f7b65c7f0b2a74ed2cc78c0258403100c8
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .rbenv-gemsets
19
+ vendor/bundle/*
data/.travis.yml CHANGED
@@ -1,2 +1,4 @@
1
1
  rvm:
2
2
  - 1.9.3
3
+ - 2.1.0
4
+ - 2.2.0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## Version 1.0.0
2
+
3
+ * Released Feb 03rd 2015
4
+ * Added configuration option to set button class in an initializer
5
+ * Updated to be compatible with Foundation 5.2.2
6
+ * Bugfixes
7
+
1
8
  ## Version 0.5.0
2
9
 
3
10
  * Released Oct 10th 2014
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,40 @@
1
+ # Contributing
2
+
3
+ ### We love pull requests. Here's a quick guide.
4
+
5
+ Fork, then clone the repo:
6
+ ```
7
+ git clone git@github.com:your-username/foundation_rails_helper.git
8
+ ```
9
+
10
+ Set up your machine:
11
+ ```
12
+ git checkout -b your-branch-name
13
+ bundle
14
+ ```
15
+
16
+ Make sure the tests pass:
17
+ ```
18
+ rake
19
+ ```
20
+
21
+ Make your change. Add tests for your change. Make the tests pass:
22
+ ```
23
+ rake
24
+ ```
25
+
26
+ Push to your fork and [submit a pull request][pr].
27
+ ```
28
+ git push origin your-branch-name
29
+ ```
30
+
31
+ [pr]: https://github.com/sgruhier/foundation_rails_helper/compare/
32
+
33
+ At this point you're waiting on us. We like to at least comment on pull requests within three business days (and, typically, one business day). We may suggest some changes or improvements or alternatives.
34
+
35
+ Some things that will increase the chance that your pull request is accepted:
36
+
37
+ * Write tests.
38
+ * Write a [good commit message][commit].
39
+
40
+ [commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Sébastien Gruhier
1
+ Copyright (c) 2015 Sébastien Gruhier
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,21 +1,21 @@
1
- # FoundationRailsHelper [![Build Status](https://secure.travis-ci.org/sgruhier/foundation_rails_helper.png)](http://travis-ci.org/sgruhier/foundation_rails_helper)
1
+ # Foundation Rails Helper [![Build Status](https://secure.travis-ci.org/sgruhier/foundation_rails_helper.png)](http://travis-ci.org/sgruhier/foundation_rails_helper)
2
2
 
3
- Gem for Rails 4.1.x applications that use the excellent Zurb Foundation framework.
3
+ Gem for Rails 4.1+ applications that use the excellent Zurb Foundation framework.
4
4
 
5
5
  * [Zurb Foundation](https://github.com/zurb/foundation)
6
6
  * [Zurb Foundation Rails](https://github.com/zurb/foundation-rails)
7
7
 
8
8
  So far it includes:
9
9
 
10
- * A custom FormBuilder that generates a form using the Foundation framework. It replaces the current `form_for` so you don't have to change your Rails code. Error messages are properly displayed.
10
+ * A custom FormBuilder that generates a form using the Foundation framework classes. It replaces the current `form_for`, so there is no need to change your Rails code. Error messages are properly displayed.
11
11
 
12
12
  * A `display_flash_messages` helper method that uses Zurb Foundation Alerts UI.
13
13
 
14
14
  #### Compatibility
15
15
 
16
- * Only Rails 4.1 and Foundation 4 and 5 are fully supported
17
- * Some features may work with Foundation 3 and older, but results may vary, and markup which exists only for those versions will be gradually removed
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 welcomed.
16
+ * Only Rails 4.1/4.2 and Foundation 5 are fully supported
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
+ * 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
19
 
20
20
 
21
21
  ## Screenshots
@@ -25,7 +25,7 @@ A classic devise sign up view will look like this:
25
25
 
26
26
  ```erb
27
27
  <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
28
- <%= f.email_field :email %>
28
+ <%= f.email_field :email, label: 'E-mail' %>
29
29
  <%= f.password_field :password %>
30
30
  <%= f.password_field :password_confirmation %>
31
31
 
@@ -34,19 +34,27 @@ A classic devise sign up view will look like this:
34
34
  ```
35
35
 
36
36
  <table>
37
- <tr>
38
- <th>Form</th>
39
- <th>Form with errors</th>
40
- </tr>
41
- <tr>
42
- <td valign='top'> <img src="http://dl.dropbox.com/u/517768/sign-up.png"/></td>
43
- <td valign='top'> <img src="http://dl.dropbox.com/u/517768/sign-up-with-errors.png"/></td>
44
- </tr>
37
+ <thead>
38
+ <tr>
39
+ <th>Form</th>
40
+ <th>Form with errors</th>
41
+ </tr>
42
+ </thead>
43
+ <tbody>
44
+ <tr>
45
+ <td valign='top'>
46
+ <img src="https://cloud.githubusercontent.com/assets/1400414/5994195/d9b467ce-aa1e-11e4-914c-f696724b53ed.png"/>
47
+ </td>
48
+ <td valign='top'>
49
+ <img src="https://cloud.githubusercontent.com/assets/1400414/5994196/dbf4bc0a-aa1e-11e4-8c18-b7d3b1b370dc.png"/>
50
+ </td>
51
+ </tr>
52
+ </tbody>
45
53
  </table>
46
54
 
47
55
  ### Flash messages
48
56
 
49
- ![Flash-message](http://dl.dropbox.com/u/517768/flash.png "Flash-message")
57
+ ![Flash-message](https://cloud.githubusercontent.com/assets/393167/5845238/563dc094-a1b2-11e4-8548-2dd2950a60be.png "Flash-message")
50
58
 
51
59
  ## Installation
52
60
 
@@ -65,19 +73,13 @@ $ bundle
65
73
 
66
74
  ### Flash Messages
67
75
 
68
- To get access to `display_flash_messages` in your views, add
69
-
70
- ```ruby
71
- include FoundationRailsHelper::FlashHelper
72
- ```
73
-
74
- to `app/helpers/application_helper.rb`
76
+ To use the built in flash helper, add `<%= display_flash_messages %>` to your layout file (eg. *app/views/layouts/application.html.erb*).
75
77
 
76
78
  ## Usage
77
79
 
78
80
  ### form_for
79
81
 
80
- Form_for wraps the standard rails form_for helper and adds a 'nice' class by default.
82
+ Form_for wraps the standard rails form_for helper.
81
83
 
82
84
  ```erb
83
85
  <%= form_for @user do |f| %>
@@ -88,15 +90,9 @@ Form_for wraps the standard rails form_for helper and adds a 'nice' class by def
88
90
  generates:
89
91
 
90
92
  ```html
91
- <form accept-charset="UTF-8" action="/users" class="nice" id="new_user" method="post">
92
- ...
93
- ```
94
-
95
- Override the default class like so:
96
-
97
- ```erb
98
- <%= form_for(@user, html: {class: 'mean'}) do |f| %>
93
+ <form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
99
94
  ...
95
+ </form>
100
96
  ```
101
97
 
102
98
  ### text_field and Field Helpers
@@ -111,19 +107,7 @@ generates:
111
107
 
112
108
  ```html
113
109
  <label for="user_email">Name</label>
114
- <input class="medium input-text" id="user_name" name="user[name]" type="text">
115
- ```
116
-
117
- The 'input-text' class will always be added to the input element, but the 'medium' class can be replaced.
118
-
119
- ```ruby
120
- f.text_field :name, class: 'large'
121
- ```
122
-
123
- generates:
124
-
125
- ```html
126
- <input class="large input-text" ... >
110
+ <input id="user_name" name="user[name]" type="text">
127
111
  ```
128
112
 
129
113
  Prevent the generation of a label:
@@ -177,31 +161,33 @@ f.email_field :email
177
161
  generates:
178
162
 
179
163
  ```html
180
- <label class=" error" for="user_email">Email</label>
181
- <input class="medium input-text error" id="user_email" name="user[email]" type="email" value="">
182
- <small class="error medium input-text error">can't be blank</small>
164
+ <label class="error" for="user_email">Email</label>
165
+ <input class="error" id="user_email" name="user[email]" type="email" value="">
166
+ <small class="error">can't be blank</small>
183
167
  ```
184
168
 
185
169
  The class attribute of the 'small' element will mirror the class attribute of the 'input' element.
186
170
 
187
171
  If the `html_safe_errors: true` option is specified on a field, then any HTML you may have embedded in a custom error string will be displayed with the html_safe option.
188
172
 
189
- ## TODO
173
+ ## Configuration
174
+ Add an initializer file to your Rails app: *config/initializers/foundation_rails_helper.rb*. See below for current options.
190
175
 
191
- * Handle more UI components
192
- * Make something for ajax forms
176
+ ### Submit Button Class
177
+ To use a different class for the [submit button](https://github.com/sgruhier/foundation_rails_helper#submit-button) used in `form_for`, add a config named **button_class**. Please note, the button class can still be overridden by an options hash.
178
+ ```ruby
179
+ FoundationRailsHelper.configure do |config|
180
+ # Default: 'small radius success button'
181
+ config.button_class = 'large secondary button'
182
+ end
183
+ ```
193
184
 
194
185
  ## Contributing
195
186
 
196
- 1. Fork it
197
- 2. Create your feature branch (`git checkout -b my-new-feature`)
198
- 3. Commit your changes (`git commit -am 'Added some feature'`)
199
- 4. Push to the branch (`git push origin my-new-feature`)
200
- 5. Create a new Pull Request
187
+ See the [CONTRIBUTING](CONTRIBUTING.md) file.
201
188
 
202
189
  ## Copyright
203
190
 
204
- Sébastien Gruhier (http://xilinus.com, http://v2.maptimize.com) - MIT LICENSE - 2012
191
+ Sébastien Gruhier (http://xilinus.com, http://v2.maptimize.com) - MIT LICENSE - 2015
205
192
 
206
193
  [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/sgruhier/foundation_rails_helper/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
207
-
@@ -22,6 +22,6 @@ Gem::Specification.new do |gem|
22
22
  gem.add_dependency 'activesupport', '~> 4.1', '>= 4.1.1'
23
23
  gem.add_dependency 'tzinfo', '~> 1.2', '>= 1.2.2'
24
24
 
25
- gem.add_development_dependency 'rspec-rails', '~> 2.8', '>= 2.8.1'
25
+ gem.add_development_dependency 'rspec-rails', '~> 3.1', '>= 3.1.0'
26
26
  gem.add_development_dependency 'capybara', '~> 2.4', '>= 2.4.3'
27
27
  end
@@ -1,7 +1,8 @@
1
1
  require "foundation_rails_helper/version"
2
+ require "foundation_rails_helper/configuration"
2
3
  require "foundation_rails_helper/form_builder"
3
4
  require "foundation_rails_helper/flash_helper"
4
5
  require "foundation_rails_helper/action_view_extension"
5
6
  ActiveSupport.on_load(:action_view) do
6
7
  include FoundationRailsHelper::FlashHelper
7
- end
8
+ end
@@ -4,7 +4,6 @@ module ActionView
4
4
  def form_for_with_foundation(record, options = {}, &block)
5
5
  options[:builder] ||= FoundationRailsHelper::FormBuilder
6
6
  options[:html] ||= {}
7
- options[:html][:class] ||= 'nice'
8
7
  options[:auto_labels] = true unless options.has_key? :auto_labels
9
8
  form_for_without_foundation(record, options, &block)
10
9
  end
@@ -12,7 +11,6 @@ module ActionView
12
11
  def fields_for_with_foundation(record_name, record_object = nil, options = {}, &block)
13
12
  options[:builder] ||= FoundationRailsHelper::FormBuilder
14
13
  options[:html] ||= {}
15
- options[:html][:class] ||= 'nice'
16
14
  options[:html][:attached_labels] = options[:attached_labels]
17
15
  options[:auto_labels] = true unless options.has_key? :auto_labels
18
16
  fields_for_without_foundation(record_name, record_object, options, &block)
@@ -0,0 +1,25 @@
1
+ module FoundationRailsHelper
2
+ class << self
3
+ attr_writer :configuration
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.reset
11
+ @configuration = Configuration.new
12
+ end
13
+
14
+ def self.configure
15
+ yield(configuration)
16
+ end
17
+
18
+ class Configuration
19
+ attr_accessor :button_class
20
+
21
+ def initialize
22
+ @button_class = 'small radius success button'
23
+ end
24
+ end
25
+ end
@@ -9,14 +9,15 @@ module FoundationRailsHelper
9
9
  DEFAULT_KEY_MATCHING = {
10
10
  :alert => :alert,
11
11
  :notice => :success,
12
- :info => :standard,
12
+ :info => :info,
13
13
  :secondary => :secondary,
14
14
  :success => :success,
15
- :error => :alert
15
+ :error => :alert,
16
+ :warning => :warning
16
17
  }
17
18
  def display_flash_messages(key_matching = {})
18
19
  key_matching = DEFAULT_KEY_MATCHING.merge(key_matching)
19
-
20
+
20
21
  flash.inject "" do |message, (key, value)|
21
22
  message += content_tag :div, :data => { :alert => "" }, :class => "alert-box #{key_matching[key.to_sym] || :standard}" do
22
23
  (value + link_to("&times;".html_safe, "#", :class => :close)).html_safe
@@ -21,7 +21,6 @@ module FoundationRailsHelper
21
21
  super(attribute, (text || "").html_safe, options)
22
22
  end
23
23
 
24
-
25
24
  def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0")
26
25
  custom_label(attribute, options[:label], options[:label_options]) do
27
26
  options.delete(:label)
@@ -31,10 +30,14 @@ module FoundationRailsHelper
31
30
  end
32
31
 
33
32
  def radio_button(attribute, tag_value, options = {})
34
- options[:for] ||= "#{@object_name}_#{attribute}_#{tag_value}"
35
- c = super(attribute, tag_value, options)
36
- l = label(attribute, options.delete(:text), options)
37
- l.gsub(/(for=\"\w*\"\>)/, "\\1#{c} ").html_safe
33
+ options[:label_options] ||= {}
34
+ label_options = options.delete(:label_options).merge!(value: tag_value)
35
+ unless options[:label] == false
36
+ l = label(attribute, options.delete(:label), label_options)
37
+ end
38
+ r = @template.radio_button(@object_name, attribute, tag_value, objectify_options(options))
39
+
40
+ "#{r}#{l}".html_safe
38
41
  end
39
42
 
40
43
  def password_field(attribute, options = {})
@@ -91,7 +94,7 @@ module FoundationRailsHelper
91
94
  end
92
95
 
93
96
  def submit(value=nil, options={})
94
- options[:class] ||= "small radius success button"
97
+ options[:class] ||= FoundationRailsHelper.configuration.button_class
95
98
  super(value, options)
96
99
  end
97
100
 
@@ -137,8 +140,7 @@ module FoundationRailsHelper
137
140
  html = ''.html_safe
138
141
  html = custom_label(attribute, options[:label], options[:label_options]) if @options[:auto_labels] || options[:label]
139
142
  class_options = html_options || options
140
- class_options[:class] ||= "medium"
141
- class_options[:class] = "#{class_options[:class]} input-text"
143
+ class_options[:class] = class_options[:class].to_s
142
144
  class_options[:class] += " error" if has_error?(attribute)
143
145
  options.delete(:label)
144
146
  options.delete(:label_options)
@@ -1,3 +1,3 @@
1
1
  module FoundationRailsHelper
2
- VERSION = "0.5.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe FoundationRailsHelper do
4
+
5
+ describe FoundationRailsHelper::Configuration do
6
+ describe "#button_class" do
7
+ it "default value is 'small radius success button'" do
8
+ config = FoundationRailsHelper::Configuration.new
9
+ expect(config.button_class).to eq('small radius success button')
10
+ end
11
+ end
12
+
13
+ describe "#button_class=" do
14
+ it "can set value" do
15
+ config = FoundationRailsHelper::Configuration.new
16
+ config.button_class = 'new-class'
17
+ expect(config.button_class).to eq('new-class')
18
+ end
19
+ end
20
+
21
+ describe ".reset" do
22
+ before :each do
23
+ FoundationRailsHelper.configure do |config|
24
+ config.button_class = 'new-class'
25
+ end
26
+ end
27
+
28
+ it "resets the configuration" do
29
+ FoundationRailsHelper.reset
30
+
31
+ config = FoundationRailsHelper.configuration
32
+ expect(config.button_class).to eq('small radius success button')
33
+ end
34
+ end
35
+ end
36
+
37
+ end
@@ -10,28 +10,28 @@ describe FoundationRailsHelper::FlashHelper do
10
10
 
11
11
  FoundationRailsHelper::FlashHelper::DEFAULT_KEY_MATCHING.each do |message_type, foundation_type|
12
12
  it "displays flash message with #{foundation_type} class for #{message_type} message" do
13
- self.stub!(:flash).and_return({message_type => "Flash message"})
13
+ allow(self).to receive(:flash).and_return({message_type => "Flash message"})
14
14
  node = Capybara.string display_flash_messages
15
- node.should have_css("div.alert-box.#{foundation_type}", :text => "Flash message")
16
- node.should have_css("div.alert-box a.close", :text => "×")
15
+ expect(node).to have_css("div.alert-box.#{foundation_type}", :text => "Flash message")
16
+ expect(node).to have_css("div.alert-box a.close", :text => "×")
17
17
  end
18
18
  end
19
19
 
20
20
  it "displays flash message with overridden key matching" do
21
- self.stub!(:flash).and_return({:notice => "Flash message"})
21
+ allow(self).to receive(:flash).and_return({:notice => "Flash message"})
22
22
  node = Capybara.string display_flash_messages({:notice => :alert})
23
- node.should have_css("div.alert-box.alert")
23
+ expect(node).to have_css("div.alert-box.alert")
24
24
  end
25
25
 
26
26
  it "displays flash message with custom key matching" do
27
- self.stub!(:flash).and_return({:custom_type => "Flash message"})
27
+ allow(self).to receive(:flash).and_return({:custom_type => "Flash message"})
28
28
  node = Capybara.string display_flash_messages({:custom_type => :custom_class})
29
- node.should have_css("div.alert-box.custom_class")
29
+ expect(node).to have_css("div.alert-box.custom_class")
30
30
  end
31
31
 
32
32
  it "displays flash message with standard class if key doesn't match" do
33
- self.stub!(:flash).and_return({:custom_type => "Flash message"})
33
+ allow(self).to receive(:flash).and_return({:custom_type => "Flash message"})
34
34
  node = Capybara.string display_flash_messages
35
- node.should have_css("div.alert-box.standard")
35
+ expect(node).to have_css("div.alert-box.standard")
36
36
  end
37
- end
37
+ end