foundation_rails_helper_mod 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +91 -0
- data/Rakefile +6 -0
- data/foundation_rails_helper_mod.gemspec +22 -0
- data/lib/foundation_rails_helper_mod.rb +4 -0
- data/lib/foundation_rails_helper_mod/action_view_extension.rb +25 -0
- data/lib/foundation_rails_helper_mod/flash_helper.rb +25 -0
- data/lib/foundation_rails_helper_mod/form_builder.rb +140 -0
- data/lib/foundation_rails_helper_mod/version.rb +3 -0
- data/lib/railtie.rb +8 -0
- data/spec/foundation_rails_helper_mod/flash_helper_spec.rb +37 -0
- data/spec/foundation_rails_helper_mod/form_builder_spec.rb +173 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/mock_rails.rb +107 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGM1N2E0ZWM1MTkzMzdiOTUxNzRlNGM2ZjU2MjU3NTYzNzZlYWUwMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGI5NGM2MTk2Yjg2ZDgzZWI1ZGEyODRlYzFiN2UwZjM3ZDcxODE3Yg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
N2RlNGE5NWM5NDdjMmMyYWVkYTRmOGQ2ZjIzYjQ1NjdjZWU2MWZmOTQyNDEz
|
10
|
+
OGFlNjAyNjczNTUxZDc1Nzk0MWI0YTVjNDhmMDQxNmQwMjk2YzkxMTY1M2Ni
|
11
|
+
ZDI2OTBmNzMzYTdlODg2ZGM2YzY1YjgyYzZiM2MyMmEwM2Y2MmI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZGZiZmM5M2FiMTdlYmFkZGYxZmE5MzRmNjM3YWNmMDJiNzM2N2Q5YzA5ZGZh
|
14
|
+
MDQzMjkwYjRiODljYTNmNmI5Y2QxNjU2OTNiMGNjNDAyYTVmOTM5ZjkyZWY4
|
15
|
+
ZjY0N2NhMzkzODRiZjk1NmQ0ODBkYWM1ZGJhNzVkZDQ2YmIwMjc=
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Sébastien Gruhier
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# FoundationRailsHelperMod [](http://travis-ci.org/sgruhier/foundation_rails_helper)
|
2
|
+
|
3
|
+
Based on foundation_rails_helper repo. But fixed.
|
4
|
+
_______
|
5
|
+
|
6
|
+
Gem for Rails 3 applications that use the excellent Zurb Foundation framework.
|
7
|
+
|
8
|
+
* [Zurb Foundation](https://github.com/zurb/foundation)
|
9
|
+
* [Zurb Foundation Rails](https://github.com/zurb/foundation-rails)
|
10
|
+
|
11
|
+
So far it includes:
|
12
|
+
|
13
|
+
* 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.
|
14
|
+
|
15
|
+
* A `display_flash_messages` helper method that uses Zurb Foundation Alerts UI.
|
16
|
+
|
17
|
+
This gem has been used with Rails 3.1, 3.2 and ruby 1.9.2, 1.9.3. It should work for Rails 3.0.
|
18
|
+
|
19
|
+
## Screenshots
|
20
|
+
|
21
|
+
### Forms
|
22
|
+
A classic devise sign up view will look like this:
|
23
|
+
|
24
|
+
```erb
|
25
|
+
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
26
|
+
<%= f.email_field :email %>
|
27
|
+
<%= f.password_field :password %>
|
28
|
+
<%= f.password_field :password_confirmation %>
|
29
|
+
|
30
|
+
<%= f.submit %>
|
31
|
+
<% end %>
|
32
|
+
```
|
33
|
+
|
34
|
+
<table>
|
35
|
+
<tr>
|
36
|
+
<th>Form</th>
|
37
|
+
<th>Form with errors</th>
|
38
|
+
</tr>
|
39
|
+
<tr>
|
40
|
+
<td valign='top'> <img src="http://dl.dropbox.com/u/517768/sign-up.png"/></td>
|
41
|
+
<td valign='top'> <img src="http://dl.dropbox.com/u/517768/sign-up-with-errors.png"/></td>
|
42
|
+
</tr>
|
43
|
+
</table>
|
44
|
+
|
45
|
+
### Flash messages
|
46
|
+
|
47
|
+

|
48
|
+
|
49
|
+
## Installation
|
50
|
+
|
51
|
+
Add this line to your application's Gemfile:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
gem 'zurb-foundation'
|
55
|
+
gem 'foundation_rails_helper_mod'
|
56
|
+
```
|
57
|
+
|
58
|
+
And then execute:
|
59
|
+
|
60
|
+
```bash
|
61
|
+
$ bundle
|
62
|
+
```
|
63
|
+
|
64
|
+
## Usage
|
65
|
+
|
66
|
+
There is nothing additional to do for form helpers.
|
67
|
+
|
68
|
+
To get access to `display_flash_messages` in your views, add
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
include FoundationRailsHelperMod::FlashHelper
|
72
|
+
```
|
73
|
+
|
74
|
+
to `app/helpers/application_helper.rb`
|
75
|
+
|
76
|
+
## TODO
|
77
|
+
|
78
|
+
* Handle more UI components
|
79
|
+
* Make something for ajax forms
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
1. Fork it
|
84
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
85
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
86
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
87
|
+
5. Create a new Pull Request
|
88
|
+
|
89
|
+
## Copyright
|
90
|
+
|
91
|
+
Sébastien Gruhier (http://xilinus.com, http://v2.maptimize.com) - MIT LICENSE - 2012
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/foundation_rails_helper_mod/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alex Zanardo", "Sebastien Gruhier"]
|
6
|
+
gem.email = ["info@alexzanardo.com", "sebastien.gruhier@xilinus.com"]
|
7
|
+
gem.description = %q{Rails 3 for zurb foundation CSS framework. Form builder, flash message, ...}
|
8
|
+
gem.summary = %q{Rails 3 helpers for zurb foundation CSS framework}
|
9
|
+
gem.homepage = "https://github.com/responsa/foundation_rails_helper_mod"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "foundation_rails_helper_mod"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = FoundationRailsHelperMod::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'railties', '~> 3.0'
|
19
|
+
gem.add_dependency "actionpack", '~> 3.0'
|
20
|
+
gem.add_development_dependency "rspec-rails"
|
21
|
+
gem.add_development_dependency "capybara"
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module FormHelper
|
4
|
+
def form_for_with_foundation(record, options = {}, &block)
|
5
|
+
options[:builder] ||= FoundationRailsHelperMod::FormBuilder
|
6
|
+
options[:html] ||= {}
|
7
|
+
options[:html][:class] ||= 'nice'
|
8
|
+
form_for_without_foundation(record, options, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fields_for_with_foundation(record_name, record_object = nil, options = {}, &block)
|
12
|
+
options[:builder] ||= FoundationRailsHelperMod::FormBuilder
|
13
|
+
options[:html] ||= {}
|
14
|
+
options[:html][:class] ||= 'nice'
|
15
|
+
fields_for_without_foundation(record_name, record_object, options, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method_chain :form_for, :foundation
|
19
|
+
alias_method_chain :fields_for, :foundation
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
|
24
|
+
html_tag
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'action_view/helpers'
|
2
|
+
|
3
|
+
module FoundationRailsHelperMod
|
4
|
+
module FlashHelper
|
5
|
+
# <div class="alert-box [success alert secondary]">
|
6
|
+
# This is an alert box.
|
7
|
+
# <a href="" class="close">×</a>
|
8
|
+
# </div>
|
9
|
+
DEFAULT_KEY_MATCHING = {
|
10
|
+
:alert => :alert,
|
11
|
+
:notice => :success,
|
12
|
+
:info => :standard,
|
13
|
+
:secondary => :secondary,
|
14
|
+
}
|
15
|
+
def display_flash_messages(key_matching = {})
|
16
|
+
key_matching = DEFAULT_KEY_MATCHING.merge(key_matching)
|
17
|
+
|
18
|
+
flash.inject "" do |message, (key, value)|
|
19
|
+
message += content_tag :div, :class => "alert-box #{key_matching[key] || :standard}" do
|
20
|
+
(value + link_to("×".html_safe, "#", :class => :close)).html_safe
|
21
|
+
end
|
22
|
+
end.html_safe
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'action_view/helpers'
|
2
|
+
|
3
|
+
module FoundationRailsHelperMod
|
4
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
5
|
+
include ActionView::Helpers::TagHelper
|
6
|
+
%w(file_field email_field text_area telephone_field phone_field url_field number_field).each do |method_name|
|
7
|
+
define_method(method_name) do |*args|
|
8
|
+
attribute = args[0]
|
9
|
+
options = args[1] || {}
|
10
|
+
field(attribute, options) do |options|
|
11
|
+
super(attribute, options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def text_field(attribute, options = {})
|
17
|
+
html = ''.html_safe
|
18
|
+
|
19
|
+
if options[:label].present?
|
20
|
+
html = custom_label(attribute, options[:label], options[:label_options]) do
|
21
|
+
options.delete(:label)
|
22
|
+
options.delete(:label_options)
|
23
|
+
super(attribute, options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
html += content_tag(:p, options[:description], :class => 'description') if options[:description].present?
|
28
|
+
html += error_and_hint(attribute, options)
|
29
|
+
html += Tags::TextField.new(object_name, method, self, options).render
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_box(attribute, options = {})
|
33
|
+
html = custom_label(attribute, options[:label], options[:label_options]) do
|
34
|
+
options.delete(:label)
|
35
|
+
options.delete(:label_options)
|
36
|
+
super(attribute, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
html += content_tag(:p, options[:description], :class => 'description') if options[:description].present?
|
40
|
+
html += error_and_hint(attribute, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def radio_button(attribute, tag_value, options = {})
|
44
|
+
options[:for] ||= "#{object.class.to_s.downcase}_#{attribute}_#{tag_value}"
|
45
|
+
l = label(attribute, options)
|
46
|
+
c = super(attribute, tag_value, options)
|
47
|
+
l.gsub(/(for=\"\w*\"\>)/, "\\1#{c} ").html_safe
|
48
|
+
end
|
49
|
+
|
50
|
+
def password_field(attribute, options = {})
|
51
|
+
field attribute, options do |options|
|
52
|
+
super(attribute, options.merge(:autocomplete => :off))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def datetime_select(attribute, options = {})
|
57
|
+
field attribute, options do |options|
|
58
|
+
super(attribute, {}, options.merge(:autocomplete => :off))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def date_select(attribute, options = {}, html_options = {})
|
63
|
+
field attribute, html_options do |html_options|
|
64
|
+
super(attribute, options, html_options.merge(:autocomplete => :off))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def time_zone_select(attribute, options = {})
|
69
|
+
field attribute, options do |options|
|
70
|
+
super(attribute, {}, options.merge(:autocomplete => :off))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def select(attribute, choices, options = {}, html_options = {})
|
75
|
+
field attribute, options do |options|
|
76
|
+
html_options[:autocomplete] ||= :off
|
77
|
+
super(attribute, choices, options, html_options)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def autocomplete(attribute, url, options = {})
|
82
|
+
field attribute, options do |options|
|
83
|
+
autocomplete_field(attribute, url, options.merge(:update_elements => options[:update_elements],
|
84
|
+
:min_length => 0,
|
85
|
+
:value => object.send(attribute)))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def submit(value=nil, options={})
|
90
|
+
options[:class] ||= "small radius success button"
|
91
|
+
super(value, options)
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
def has_error?(attribute)
|
96
|
+
object && !object.errors[attribute].blank?
|
97
|
+
end
|
98
|
+
|
99
|
+
def error_for(attribute, options = {})
|
100
|
+
class_name = "error"
|
101
|
+
class_name += " #{options[:class]}" if options[:class]
|
102
|
+
content_tag(:small, object.errors[attribute].join(', '), :class => class_name) if has_error?(attribute)
|
103
|
+
end
|
104
|
+
|
105
|
+
def custom_label(attribute, text, options, &block)
|
106
|
+
if text == false
|
107
|
+
text = ""
|
108
|
+
elsif text.nil?
|
109
|
+
text = object.class.human_attribute_name(attribute)
|
110
|
+
end
|
111
|
+
text = block.call.html_safe + text if block_given?
|
112
|
+
options ||= {}
|
113
|
+
options[:class] ||= ""
|
114
|
+
options[:class] += " error" if has_error?(attribute)
|
115
|
+
label(attribute, text, options)
|
116
|
+
end
|
117
|
+
|
118
|
+
def error_and_hint(attribute, options = {})
|
119
|
+
html = ""
|
120
|
+
html += content_tag(:span, options[:hint], :class => :hint) if options[:hint]
|
121
|
+
html += error_for(attribute, options) || ""
|
122
|
+
html.html_safe
|
123
|
+
end
|
124
|
+
|
125
|
+
def field(attribute, options, &block)
|
126
|
+
html = ''.html_safe
|
127
|
+
html = custom_label(attribute, options[:label], options[:label_options]) if false != options[:label]
|
128
|
+
options[:class] ||= "medium"
|
129
|
+
options[:class] = "#{options[:class]} input-text"
|
130
|
+
options[:class] += " error" if has_error?(attribute)
|
131
|
+
options.delete(:label)
|
132
|
+
options.delete(:label_options)
|
133
|
+
html += '<div class="input-wrapper">'.html_safe
|
134
|
+
html += yield(options)
|
135
|
+
html += content_tag(:p, options[:description], :class => 'description') if options[:description].present?
|
136
|
+
html += error_and_hint(attribute, options)
|
137
|
+
html += '</div>'.html_safe
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
data/lib/railtie.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe FoundationRailsHelperMod::FlashHelper do
|
6
|
+
include ActionView::Context if defined?(ActionView::Context)
|
7
|
+
include ActionView::Helpers::UrlHelper
|
8
|
+
include ActionView::Helpers::TagHelper
|
9
|
+
include FoundationRailsHelperMod::FlashHelper
|
10
|
+
|
11
|
+
FoundationRailsHelperMod::FlashHelper::DEFAULT_KEY_MATCHING.each do |message_type, foundation_type|
|
12
|
+
it "displays flash message with #{foundation_type} class for #{message_type} message" do
|
13
|
+
self.stub!(:flash).and_return({message_type => "Flash message"})
|
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 => "×")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "displays flash message with overridden key matching" do
|
21
|
+
self.stub!(:flash).and_return({:notice => "Flash message"})
|
22
|
+
node = Capybara.string display_flash_messages({:notice => :alert})
|
23
|
+
node.should have_css("div.alert-box.alert")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "displays flash message with custom key matching" do
|
27
|
+
self.stub!(:flash).and_return({:custom_type => "Flash message"})
|
28
|
+
node = Capybara.string display_flash_messages({:custom_type => :custom_class})
|
29
|
+
node.should have_css("div.alert-box.custom_class")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "displays flash message with standard class if key doesn't match" do
|
33
|
+
self.stub!(:flash).and_return({:custom_type => "Flash message"})
|
34
|
+
node = Capybara.string display_flash_messages
|
35
|
+
node.should have_css("div.alert-box.standard")
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "FoundationRailsHelperMod::FormHelper" do
|
4
|
+
include FoundationRailsSpecHelper
|
5
|
+
|
6
|
+
before do
|
7
|
+
mock_everything
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should have FoundationRailsHelperMod::FormHelper as default buidler' do
|
11
|
+
form_for(@author) do |builder|
|
12
|
+
builder.class.should == FoundationRailsHelperMod::FormBuilder
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "input generators" do
|
17
|
+
it "should generate text_field input" do
|
18
|
+
form_for(@author) do |builder|
|
19
|
+
node = Capybara.string builder.text_field(:login)
|
20
|
+
node.should have_css('label[for="author_login"]', :text => "Login")
|
21
|
+
node.should have_css('input.medium.input-text[type="text"][name="author[login]"]')
|
22
|
+
node.find_field('author_login').value.should == @author.login
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should generate text_field input without label" do
|
27
|
+
form_for(@author) do |builder|
|
28
|
+
node = Capybara.string builder.text_field(:login, :label => false)
|
29
|
+
node.should_not have_css('label[for="author_login"]', :text => "Login")
|
30
|
+
node.should have_css('input.medium.input-text[type="text"][name="author[login]"]')
|
31
|
+
node.find_field('author_login').value.should == @author.login
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should generate password_field input" do
|
36
|
+
form_for(@author) do |builder|
|
37
|
+
node = Capybara.string builder.password_field(:password)
|
38
|
+
node.should have_css('label[for="author_password"]', :text => "Password")
|
39
|
+
node.should have_css('input.medium.input-text[type="password"][name="author[password]"]')
|
40
|
+
node.find_field('author_password').value.should be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should generate email_field input" do
|
45
|
+
form_for(@author) do |builder|
|
46
|
+
node = Capybara.string builder.email_field(:email)
|
47
|
+
node.should have_css('label[for="author_email"]', :text => "Email")
|
48
|
+
node.should have_css('input.medium.input-text[type="email"][name="author[email]"]')
|
49
|
+
node.find_field('author_email').value.should == @author.email
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should generate url_field input" do
|
54
|
+
form_for(@author) do |builder|
|
55
|
+
node = Capybara.string builder.url_field(:url)
|
56
|
+
node.should have_css('label[for="author_url"]', :text => "Url")
|
57
|
+
node.should have_css('input.medium.input-text[type="url"][name="author[url]"]')
|
58
|
+
node.find_field('author_url').value.should == @author.url
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should generate phone_field input" do
|
63
|
+
form_for(@author) do |builder|
|
64
|
+
node = Capybara.string builder.phone_field(:phone)
|
65
|
+
node.should have_css('label[for="author_phone"]', :text => "Phone")
|
66
|
+
node.should have_css('input.medium.input-text[type="tel"][name="author[phone]"]')
|
67
|
+
node.find_field('author_phone').value.should == @author.phone
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should generate number_field input" do
|
72
|
+
form_for(@author) do |builder|
|
73
|
+
node = Capybara.string builder.number_field(:some_number)
|
74
|
+
node.should have_css('label[for="author_some_number"]', :text => "Some number")
|
75
|
+
node.should have_css('input.medium.input-text[type="number"][name="author[some_number]"]')
|
76
|
+
node.find_field('author_some_number').value.should == @author.some_number
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should generate text_area input" do
|
81
|
+
form_for(@author) do |builder|
|
82
|
+
node = Capybara.string builder.text_area(:description)
|
83
|
+
node.should have_css('label[for="author_description"]', :text => "Description")
|
84
|
+
node.should have_css('textarea.medium.input-text[name="author[description]"]')
|
85
|
+
node.find_field('author_description').value.strip.should == @author.description
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should generate file_field input" do
|
90
|
+
form_for(@author) do |builder|
|
91
|
+
node = Capybara.string builder.file_field(:avatar)
|
92
|
+
node.should have_css('label[for="author_avatar"]', :text => "Avatar")
|
93
|
+
node.should have_css('input.medium.input-text[type="file"][name="author[avatar]"]')
|
94
|
+
node.find_field('author_avatar').value.should be_nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should generate select input" do
|
99
|
+
form_for(@author) do |builder|
|
100
|
+
node = Capybara.string builder.select(:description, [["Choice #1", :a], ["Choice #2", :b]])
|
101
|
+
node.should have_css('label[for="author_description"]', :text => "Description")
|
102
|
+
node.should have_css('select[name="author[description]"]')
|
103
|
+
node.should have_css('select[name="author[description]"] option[value="a"]', :text => "Choice #1")
|
104
|
+
node.should have_css('select[name="author[description]"] option[value="b"]', :text => "Choice #2")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should generate check_box input" do
|
109
|
+
form_for(@author) do |builder|
|
110
|
+
node = Capybara.string builder.check_box(:active)
|
111
|
+
node.should have_css('label[for="author_active"] input[type="hidden"][name="author[active]"][value="0"]')
|
112
|
+
node.should have_css('label[for="author_active"] input[type="checkbox"][name="author[active]"]')
|
113
|
+
node.should have_css('label[for="author_active"]', :text => "Active")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
it "should generate check_box input without a label" do
|
117
|
+
form_for(@author) do |builder|
|
118
|
+
node = Capybara.string builder.check_box(:active, :label => false)
|
119
|
+
node.should have_css('label[for="author_active"] input[type="hidden"][name="author[active]"][value="0"]')
|
120
|
+
node.should have_css('label[for="author_active"] input[type="checkbox"][name="author[active]"]')
|
121
|
+
node.should have_css('label[for="author_active"]', :text => "")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should generate radio_button input" do
|
126
|
+
form_for(@author) do |builder|
|
127
|
+
node = Capybara.string builder.label(:active) + builder.radio_button(:active, "ok")
|
128
|
+
node.should have_css('label[for="author_active_ok"] input[type="radio"][name="author[active]"]')
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should generate date_select input" do
|
133
|
+
form_for(@author) do |builder|
|
134
|
+
node = Capybara.string builder.label(:birthdate) + builder.date_select(:birthdate)
|
135
|
+
node.should have_css('label[for="author_birthdate"]', :text => "Birthdate")
|
136
|
+
%w(1 2 3).each {|i| node.should have_css("select.medium.input-text[name='author[birthdate(#{i}i)]']") }
|
137
|
+
node.should have_css('select#author_birthdate_1i option[selected="selected"][value="1969"]')
|
138
|
+
node.should have_css('select#author_birthdate_2i option[selected="selected"][value="6"]')
|
139
|
+
node.should have_css('select#author_birthdate_3i option[selected="selected"][value="18"]')
|
140
|
+
%w(4 5).each {|i| node.should_not have_css("select.medium.input-text[name='author[birthdate(#{i}i)]']") }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should generate date_select input with :discard_year => true" do
|
145
|
+
form_for(@author) do |builder|
|
146
|
+
node = Capybara.string builder.label(:birthdate) + builder.date_select(:birthdate, :discard_year => true)
|
147
|
+
node.should have_css('label[for="author_birthdate"]', :text => "Birthdate")
|
148
|
+
%w(2 3).each {|i| node.should have_css("select.medium.input-text[name='author[birthdate(#{i}i)]']") }
|
149
|
+
node.should_not have_css('select#author_birthdate_1i option[selected="selected"][value="1969"]')
|
150
|
+
node.should have_css('select#author_birthdate_2i option[selected="selected"][value="6"]')
|
151
|
+
node.should have_css('select#author_birthdate_3i option[selected="selected"][value="18"]')
|
152
|
+
%w(1 4 5).each {|i| node.should_not have_css("select.medium.input-text[name='author[birthdate(#{i}i)]']") }
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "errors generator" do
|
159
|
+
it "should not display errors" do
|
160
|
+
form_for(@author) do |builder|
|
161
|
+
node = Capybara.string builder.text_field(:login)
|
162
|
+
node.should_not have_css('small.error')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
it "should display errors" do
|
166
|
+
form_for(@author) do |builder|
|
167
|
+
@author.stub!(:errors).and_return({:login => ['required']})
|
168
|
+
node = Capybara.string builder.text_field(:login)
|
169
|
+
node.should have_css('small.error', :text => "required")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'active_support'
|
3
|
+
require 'action_pack'
|
4
|
+
require 'action_view'
|
5
|
+
require 'action_controller'
|
6
|
+
require 'action_dispatch'
|
7
|
+
|
8
|
+
# Thanks to Justin French for formtastic spec
|
9
|
+
module FoundationRailsSpecHelper
|
10
|
+
include ActionPack
|
11
|
+
include ActionView::Context if defined?(ActionView::Context)
|
12
|
+
include ActionController::RecordIdentifier
|
13
|
+
include ActionView::Helpers::FormHelper
|
14
|
+
include ActionView::Helpers::FormTagHelper
|
15
|
+
include ActionView::Helpers::FormOptionsHelper
|
16
|
+
include ActionView::Helpers::UrlHelper
|
17
|
+
include ActionView::Helpers::TagHelper
|
18
|
+
include ActionView::Helpers::TextHelper
|
19
|
+
include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper)
|
20
|
+
include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper)
|
21
|
+
include ActionView::Helpers::DateHelper
|
22
|
+
include ActionView::Helpers::CaptureHelper
|
23
|
+
include ActionView::Helpers::AssetTagHelper
|
24
|
+
include ActiveSupport
|
25
|
+
include ActionController::PolymorphicRoutes if defined?(ActionController::PolymorphicRoutes)
|
26
|
+
|
27
|
+
def active_model_validator(kind, attributes, options = {})
|
28
|
+
validator = mock("ActiveModel::Validations::#{kind.to_s.titlecase}Validator", :attributes => attributes, :options => options)
|
29
|
+
validator.stub!(:kind).and_return(kind)
|
30
|
+
validator
|
31
|
+
end
|
32
|
+
|
33
|
+
def active_model_presence_validator(attributes, options = {})
|
34
|
+
active_model_validator(:presence, attributes, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def active_model_length_validator(attributes, options = {})
|
38
|
+
active_model_validator(:length, attributes, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def active_model_inclusion_validator(attributes, options = {})
|
42
|
+
active_model_validator(:inclusion, attributes, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def active_model_numericality_validator(attributes, options = {})
|
46
|
+
active_model_validator(:numericality, attributes, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
class ::Author
|
50
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
51
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
52
|
+
|
53
|
+
def to_label
|
54
|
+
end
|
55
|
+
|
56
|
+
def persisted?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def mock_everything
|
61
|
+
# Resource-oriented styles like form_for(@post) will expect a path method for the object,
|
62
|
+
# so we're defining some here.
|
63
|
+
def author_path(*args); "/authors/1"; end
|
64
|
+
def authors_path(*args); "/authors"; end
|
65
|
+
def new_author_path(*args); "/authors/new"; end
|
66
|
+
|
67
|
+
@author = ::Author.new
|
68
|
+
@author.stub!(:class).and_return(::Author)
|
69
|
+
@author.stub!(:to_label).and_return('Fred Smith')
|
70
|
+
@author.stub!(:login).and_return('fred_smith')
|
71
|
+
@author.stub!(:email).and_return('fred@foo.com')
|
72
|
+
@author.stub!(:url).and_return('http://example.com')
|
73
|
+
@author.stub!(:some_number).and_return('42')
|
74
|
+
@author.stub!(:phone).and_return('317 456 2564')
|
75
|
+
@author.stub!(:password).and_return('secret')
|
76
|
+
@author.stub!(:active).and_return(true)
|
77
|
+
@author.stub!(:description).and_return('bla bla bla')
|
78
|
+
@author.stub!(:avatar).and_return('avatar.png')
|
79
|
+
@author.stub!(:birthdate).and_return(Date.parse("1969-06-18 20:30"))
|
80
|
+
@author.stub!(:id).and_return(37)
|
81
|
+
@author.stub!(:new_record?).and_return(false)
|
82
|
+
@author.stub!(:errors).and_return(mock('errors', :[] => nil))
|
83
|
+
@author.stub!(:to_key).and_return(nil)
|
84
|
+
@author.stub!(:persisted?).and_return(nil)
|
85
|
+
|
86
|
+
::Author.stub!(:scoped).and_return(::Author)
|
87
|
+
::Author.stub!(:find).and_return([@author])
|
88
|
+
::Author.stub!(:all).and_return([@author])
|
89
|
+
::Author.stub!(:where).and_return([@author])
|
90
|
+
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.to_s.humanize }
|
91
|
+
::Author.stub!(:human_name).and_return('::Author')
|
92
|
+
::Author.stub!(:content_columns).and_return([mock('column', :name => 'login'), mock('column', :name => 'created_at')])
|
93
|
+
::Author.stub!(:to_key).and_return(nil)
|
94
|
+
::Author.stub!(:persisted?).and_return(nil)
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.included(base)
|
98
|
+
base.class_eval do
|
99
|
+
attr_accessor :output_buffer
|
100
|
+
|
101
|
+
def protect_against_forgery?
|
102
|
+
false
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foundation_rails_helper_mod
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Zanardo
|
8
|
+
- Sebastien Gruhier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: actionpack
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec-rails
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: capybara
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: Rails 3 for zurb foundation CSS framework. Form builder, flash message,
|
71
|
+
...
|
72
|
+
email:
|
73
|
+
- info@alexzanardo.com
|
74
|
+
- sebastien.gruhier@xilinus.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- .gitignore
|
80
|
+
- .rspec
|
81
|
+
- .travis.yml
|
82
|
+
- CHANGELOG.md
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- foundation_rails_helper_mod.gemspec
|
88
|
+
- lib/foundation_rails_helper_mod.rb
|
89
|
+
- lib/foundation_rails_helper_mod/action_view_extension.rb
|
90
|
+
- lib/foundation_rails_helper_mod/flash_helper.rb
|
91
|
+
- lib/foundation_rails_helper_mod/form_builder.rb
|
92
|
+
- lib/foundation_rails_helper_mod/version.rb
|
93
|
+
- lib/railtie.rb
|
94
|
+
- spec/foundation_rails_helper_mod/flash_helper_spec.rb
|
95
|
+
- spec/foundation_rails_helper_mod/form_builder_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- spec/support/mock_rails.rb
|
98
|
+
homepage: https://github.com/responsa/foundation_rails_helper_mod
|
99
|
+
licenses: []
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.5.0
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Rails 3 helpers for zurb foundation CSS framework
|
121
|
+
test_files:
|
122
|
+
- spec/foundation_rails_helper_mod/flash_helper_spec.rb
|
123
|
+
- spec/foundation_rails_helper_mod/form_builder_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
- spec/support/mock_rails.rb
|