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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +40 -0
- data/LICENSE +2 -2
- data/README.md +44 -58
- data/foundation_rails_helper.gemspec +1 -1
- data/lib/foundation_rails_helper.rb +2 -1
- data/lib/foundation_rails_helper/action_view_extension.rb +0 -2
- data/lib/foundation_rails_helper/configuration.rb +25 -0
- data/lib/foundation_rails_helper/flash_helper.rb +4 -3
- data/lib/foundation_rails_helper/form_builder.rb +10 -8
- data/lib/foundation_rails_helper/version.rb +1 -1
- data/spec/foundation_rails_helper/configuration_spec.rb +37 -0
- data/spec/foundation_rails_helper/flash_helper_spec.rb +10 -10
- data/spec/foundation_rails_helper/form_builder_spec.rb +304 -147
- data/spec/support/mock_rails.rb +44 -44
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8778cbf569b219f1dc900b76ccc9dbce91f14352
|
4
|
+
data.tar.gz: 2f04eeda4780f7ea097fc6489b522089c3828799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95f6960132fbfc01eba7fc1490897c3d67bbf9ea6fb678ef8ac478bc9a75421be821bb98d1f4e224ac5d3ec8bda5ae912d7bc596033c23b67126d37f7279d150
|
7
|
+
data.tar.gz: 44739788edf92dd99efdf494081aee4a5930d367e79750a987d9d336b8552351de84d464ea11470eb9fb1a620d0d95f7b65c7f0b2a74ed2cc78c0258403100c8
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
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)
|
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
|
-
#
|
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
|
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
|
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
|
17
|
-
* Some features may work with Foundation
|
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
|
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
|
-
<
|
38
|
-
<
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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](
|
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
|
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
|
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="
|
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
|
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="
|
181
|
-
<input class="
|
182
|
-
<small class="error
|
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
|
-
##
|
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
|
-
|
192
|
-
|
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
|
-
|
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 -
|
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', '~>
|
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 => :
|
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("×".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[:
|
35
|
-
|
36
|
-
|
37
|
-
|
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] ||=
|
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]
|
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)
|
@@ -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.
|
13
|
+
allow(self).to receive(:flash).and_return({message_type => "Flash message"})
|
14
14
|
node = Capybara.string display_flash_messages
|
15
|
-
node.
|
16
|
-
node.
|
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.
|
21
|
+
allow(self).to receive(:flash).and_return({:notice => "Flash message"})
|
22
22
|
node = Capybara.string display_flash_messages({:notice => :alert})
|
23
|
-
node.
|
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.
|
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.
|
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.
|
33
|
+
allow(self).to receive(:flash).and_return({:custom_type => "Flash message"})
|
34
34
|
node = Capybara.string display_flash_messages
|
35
|
-
node.
|
35
|
+
expect(node).to have_css("div.alert-box.standard")
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|