foundation_rails_helper 0.1.alpha
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.
- data/.gitignore +17 -0
- data/.rbenv-gemsets +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/foundation_rails_helper.gemspec +21 -0
- data/lib/foundation_rails_helper.rb +4 -0
- data/lib/foundation_rails_helper/action_view_extension.rb +22 -0
- data/lib/foundation_rails_helper/flash_helper.rb +23 -0
- data/lib/foundation_rails_helper/form_builder.rb +70 -0
- data/lib/foundation_rails_helper/version.rb +3 -0
- data/lib/railtie.rb +8 -0
- data/spec/foundation_rails_helper/form_builder_spec.rb +27 -0
- data/spec/spec_helper.rb +106 -0
- metadata +97 -0
data/.gitignore
ADDED
data/.rbenv-gemsets
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
foundation_rails_helper
|
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,62 @@
|
|
1
|
+
Still in alpha release, don't use it yet.
|
2
|
+
|
3
|
+
|
4
|
+
# FoundationRailsHelper
|
5
|
+
|
6
|
+
Gem for rails 3 application that uses the excellent Zurb Foundation framework.
|
7
|
+
It includes so far
|
8
|
+
|
9
|
+
* A custum FormBuilder to generate form with Foundation framework. It replaces the current `form_for` so you don't have to
|
10
|
+
change your rails code.
|
11
|
+
Errors messages are propertly displayed
|
12
|
+
* A `display_flash` helper method to use Zurb Foundation Alerts UI
|
13
|
+
|
14
|
+
This gem has only been tested with Rails 3.1 and ruby 1.9.2.
|
15
|
+
|
16
|
+
## Screenshots
|
17
|
+
|
18
|
+
A classic devise sign up views will look like this:
|
19
|
+
|
20
|
+

|
21
|
+
|
22
|
+
With errors
|
23
|
+
|
24
|
+

|
25
|
+
|
26
|
+
And success flash message will be display like that:
|
27
|
+
|
28
|
+

|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
Add this line to your application's Gemfile:
|
33
|
+
|
34
|
+
gem "zurb-foundation"
|
35
|
+
gem 'foundation_rails_helper'
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
Nothing to do, just add this gem to your Gemfile
|
45
|
+
|
46
|
+
To get access to `display_flash` in your views add in your `app/helpers/application_helper.rb`
|
47
|
+
|
48
|
+
```
|
49
|
+
include FoundationRailsHelper::FlashHelper
|
50
|
+
```
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
59
|
+
|
60
|
+
|
61
|
+
## Copyright
|
62
|
+
Sébastien Gruhier (http://xilinus.com, http://v2.maptimize.com) - MIT LICENSE - 2012
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/foundation_rails_helper/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Sébastien Gruhier"]
|
6
|
+
gem.email = ["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 = "http://github.com/sgruhier/foundation_rails_helper"
|
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"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = FoundationRailsHelper::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'railties', '~> 3.0'
|
19
|
+
gem.add_dependency "actionpack", '~> 3.0'
|
20
|
+
gem.add_development_dependency "rspec-rails"
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module FormHelper
|
4
|
+
def form_for_with_foundation(record, options = {}, &block)
|
5
|
+
options[:builder] = FoundationRailsHelper::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] = FoundationRailsHelper::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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'action_view/helpers'
|
2
|
+
|
3
|
+
module FoundationRailsHelper
|
4
|
+
module FlashHelper
|
5
|
+
# <div class="alert-box [success warning error]">
|
6
|
+
# This is a success alert (div.alert-box.success).
|
7
|
+
# <a href="" class="close">×</a>
|
8
|
+
# </div>
|
9
|
+
KEY_MATCHING = {
|
10
|
+
:notice => :success,
|
11
|
+
:info => :warning,
|
12
|
+
:failure => :error,
|
13
|
+
:alert => :error,
|
14
|
+
}
|
15
|
+
def display_flash
|
16
|
+
flash.inject "" do |message, (key, value)|
|
17
|
+
message += content_tag :div, :class => "alert-box #{KEY_MATCHING[key] || key}" do
|
18
|
+
(value + link_to("×".html_safe, "#", :class => :close)).html_safe
|
19
|
+
end
|
20
|
+
end.html_safe
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'action_view/helpers'
|
2
|
+
|
3
|
+
module FoundationRailsHelper
|
4
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
5
|
+
include ActionView::Helpers::TagHelper
|
6
|
+
def error_for(attribute)
|
7
|
+
content_tag(:small, object.errors[attribute].join(', '), :class => :error) unless object.errors[attribute].blank?
|
8
|
+
end
|
9
|
+
|
10
|
+
%w(file_field email_field text_field text_area select).each do |method_name|
|
11
|
+
define_method(method_name) do |attribute, options = {}|
|
12
|
+
field(attribute, options) do |class_name|
|
13
|
+
super(attribute, :class => class_name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def password_field(attribute, options = {})
|
19
|
+
field attribute, options do |class_name|
|
20
|
+
super(attribute, :class => class_name, :autocomplete => :off)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def datetime_select(attribute, options = {})
|
25
|
+
field attribute, options do |class_name|
|
26
|
+
super(attribute, {:minute_step => 15}, :class => class_name, :autocomplete => :off)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def date_select(attribute, options = {})
|
31
|
+
field attribute, options do |class_name|
|
32
|
+
super(attribute, {}, :class => class_name, :autocomplete => :off)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def autocomplete(attribute, url, options = {})
|
37
|
+
field attribute, options do |class_name|
|
38
|
+
autocomplete_field(attribute, url, :class => class_name,
|
39
|
+
:update_elements => options[:update_elements],
|
40
|
+
:min_lenth => 0,
|
41
|
+
:value => object.send(attribute))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def submit(value=nil, options={})
|
46
|
+
options[:class] ||= "nice small radius blue button"
|
47
|
+
super(value, options)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
private
|
52
|
+
def custom_label(attribute, text = nil)
|
53
|
+
has_error = !object.errors[attribute].blank?
|
54
|
+
label(attribute, text, :class => has_error ? :red : '')
|
55
|
+
end
|
56
|
+
|
57
|
+
def error_and_hint(attribute)
|
58
|
+
html = ""
|
59
|
+
html += content_tag(:span, options[:hint], :class => :hint) if options[:hint]
|
60
|
+
html += error_for(attribute) || ""
|
61
|
+
html.html_safe
|
62
|
+
end
|
63
|
+
|
64
|
+
def field(attribute, options, &block)
|
65
|
+
html = custom_label(attribute, options[:label])
|
66
|
+
html += yield("#{options[:class] || "medium"} input-text placeholder")
|
67
|
+
html += error_and_hint(attribute)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/railtie.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "FoundationRailsHelper::FormHelper" do
|
4
|
+
include FoundationRailsSpecHelper
|
5
|
+
|
6
|
+
before do
|
7
|
+
mock_everything
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should have FoundationRailsHelper::FormHelper as default buidler' do
|
11
|
+
form_for(@author) do |builder|
|
12
|
+
builder.class.should == FoundationRailsHelper::FormBuilder
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should generate text_field input" do
|
17
|
+
form_for(@author) do |builder|
|
18
|
+
# Label
|
19
|
+
builder.text_field(:login).should match(%r{<label class="" for="author_login">Login</label>})
|
20
|
+
# Input class/type
|
21
|
+
builder.text_field(:login).should match(%r{.*<input class="medium input-text placeholder".*type="text".*})
|
22
|
+
# Input name/value
|
23
|
+
builder.text_field(:login).should match(%r{.*<input.*name="author\[login\]".*value="#{@author.login}"})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'active_support'
|
3
|
+
require 'action_pack'
|
4
|
+
require 'action_view'
|
5
|
+
require 'action_controller'
|
6
|
+
require 'action_dispatch'
|
7
|
+
require "foundation_rails_helper"
|
8
|
+
|
9
|
+
# Thanks to Justin French for formtastic spec
|
10
|
+
module FoundationRailsSpecHelper
|
11
|
+
include ActionPack
|
12
|
+
include ActionView::Context if defined?(ActionView::Context)
|
13
|
+
include ActionController::RecordIdentifier
|
14
|
+
include ActionView::Helpers::FormHelper
|
15
|
+
include ActionView::Helpers::FormTagHelper
|
16
|
+
include ActionView::Helpers::FormOptionsHelper
|
17
|
+
include ActionView::Helpers::UrlHelper
|
18
|
+
include ActionView::Helpers::TagHelper
|
19
|
+
include ActionView::Helpers::TextHelper
|
20
|
+
include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper)
|
21
|
+
include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper)
|
22
|
+
include ActionView::Helpers::DateHelper
|
23
|
+
include ActionView::Helpers::CaptureHelper
|
24
|
+
include ActionView::Helpers::AssetTagHelper
|
25
|
+
include ActiveSupport
|
26
|
+
include ActionController::PolymorphicRoutes if defined?(ActionController::PolymorphicRoutes)
|
27
|
+
|
28
|
+
def active_model_validator(kind, attributes, options = {})
|
29
|
+
validator = mock("ActiveModel::Validations::#{kind.to_s.titlecase}Validator", :attributes => attributes, :options => options)
|
30
|
+
validator.stub!(:kind).and_return(kind)
|
31
|
+
validator
|
32
|
+
end
|
33
|
+
|
34
|
+
def active_model_presence_validator(attributes, options = {})
|
35
|
+
active_model_validator(:presence, attributes, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def active_model_length_validator(attributes, options = {})
|
39
|
+
active_model_validator(:length, attributes, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def active_model_inclusion_validator(attributes, options = {})
|
43
|
+
active_model_validator(:inclusion, attributes, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def active_model_numericality_validator(attributes, options = {})
|
47
|
+
active_model_validator(:numericality, attributes, options)
|
48
|
+
end
|
49
|
+
|
50
|
+
class ::Author
|
51
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
52
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
53
|
+
|
54
|
+
def to_label
|
55
|
+
end
|
56
|
+
|
57
|
+
def persisted?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def mock_everything
|
62
|
+
# Resource-oriented styles like form_for(@post) will expect a path method for the object,
|
63
|
+
# so we're defining some here.
|
64
|
+
def author_path(*args); "/authors/1"; end
|
65
|
+
def authors_path(*args); "/authors"; end
|
66
|
+
def new_author_path(*args); "/authors/new"; end
|
67
|
+
|
68
|
+
@author = ::Author.new
|
69
|
+
@author.stub!(:class).and_return(::Author)
|
70
|
+
@author.stub!(:to_label).and_return('Fred Smith')
|
71
|
+
@author.stub!(:login).and_return('fred_smith')
|
72
|
+
@author.stub!(:age).and_return(27)
|
73
|
+
@author.stub!(:id).and_return(37)
|
74
|
+
@author.stub!(:new_record?).and_return(false)
|
75
|
+
@author.stub!(:errors).and_return(mock('errors', :[] => nil))
|
76
|
+
@author.stub!(:to_key).and_return(nil)
|
77
|
+
@author.stub!(:persisted?).and_return(nil)
|
78
|
+
@author.stub!(:name).and_return('Fred')
|
79
|
+
|
80
|
+
::Author.stub!(:scoped).and_return(::Author)
|
81
|
+
::Author.stub!(:find).and_return([@author])
|
82
|
+
::Author.stub!(:all).and_return([@author])
|
83
|
+
::Author.stub!(:where).and_return([@author])
|
84
|
+
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
85
|
+
::Author.stub!(:human_name).and_return('::Author')
|
86
|
+
::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Post,
|
87
|
+
:macro => :has_many) if column_name == :posts }
|
88
|
+
::Author.stub!(:content_columns).and_return([mock('column', :name => 'login'), mock('column', :name => 'created_at')])
|
89
|
+
::Author.stub!(:to_key).and_return(nil)
|
90
|
+
::Author.stub!(:persisted?).and_return(nil)
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.included(base)
|
94
|
+
base.class_eval do
|
95
|
+
attr_accessor :output_buffer
|
96
|
+
|
97
|
+
def protect_against_forgery?
|
98
|
+
false
|
99
|
+
end
|
100
|
+
|
101
|
+
# def _helpers
|
102
|
+
# FakeHelpersModule
|
103
|
+
# end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foundation_rails_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.alpha
|
5
|
+
prerelease: 4
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sébastien Gruhier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: &70151195626400 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70151195626400
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: actionpack
|
27
|
+
requirement: &70151195625760 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70151195625760
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec-rails
|
38
|
+
requirement: &70151195625300 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70151195625300
|
47
|
+
description: Rails 3 for zurb foundation CSS framework. Form builder, flash message,
|
48
|
+
...
|
49
|
+
email:
|
50
|
+
- sebastien.gruhier@xilinus.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .rbenv-gemsets
|
57
|
+
- CHANGELOG.md
|
58
|
+
- Gemfile
|
59
|
+
- LICENSE
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- foundation_rails_helper.gemspec
|
63
|
+
- lib/foundation_rails_helper.rb
|
64
|
+
- lib/foundation_rails_helper/action_view_extension.rb
|
65
|
+
- lib/foundation_rails_helper/flash_helper.rb
|
66
|
+
- lib/foundation_rails_helper/form_builder.rb
|
67
|
+
- lib/foundation_rails_helper/version.rb
|
68
|
+
- lib/railtie.rb
|
69
|
+
- spec/foundation_rails_helper/form_builder_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
homepage: http://github.com/sgruhier/foundation_rails_helper
|
72
|
+
licenses: []
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>'
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.3.1
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.10
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Rails 3 helpers for zurb foundation CSS framework
|
95
|
+
test_files:
|
96
|
+
- spec/foundation_rails_helper/form_builder_spec.rb
|
97
|
+
- spec/spec_helper.rb
|