erb_form 0.1.0 → 0.1.1
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/lib/erb_form/builder.rb +10 -2
- data/lib/erb_form/version.rb +1 -1
- data/spec/test_app/Gemfile +2 -1
- data/spec/test_app/app/views/blogs/legacy_field.html.erb +1 -1
- data/spec/test_app/app/views/blogs/name_field.html.erb +1 -1
- data/spec/test_app/app/views/blogs/render_multiple_layouts.html.erb +6 -0
- data/spec/test_app/app/views/blogs/render_simple_form_with_options.html +11 -0
- data/spec/test_app/app/views/blogs/render_with_simple_form.html.erb +5 -0
- data/spec/test_app/app/views/blogs/simple_form_field.html.erb +6 -0
- data/spec/test_app/app/views/forms/default/legacy_field.html.erb +1 -1
- data/spec/test_app/app/views/forms/legacy/field.html.erb +1 -1
- data/spec/test_app/app/views/forms/legacy/name_field.html.erb +1 -1
- data/spec/test_app/config/initializers/simple_form.rb +1 -2
- data/spec/test_app/config/locales/simple_form.en.yml +10 -0
- data/spec/test_app/spec/views/blogs/render_multiple_layouts.html.erb_spec.rb +21 -0
- data/spec/test_app/spec/views/blogs/render_simple_form_with_options.html.erb_spec +40 -0
- data/spec/test_app/spec/views/blogs/render_with_simple_form.html.erb_spec.rb +40 -0
- metadata +18 -4
data/lib/erb_form/builder.rb
CHANGED
@@ -34,14 +34,17 @@ module ErbForm
|
|
34
34
|
output = template.render(:file => '/' + (field_template_path || 'a_non_existant_file_to_force_a_missing_template_error'), :locals => {
|
35
35
|
:form => self,
|
36
36
|
:attribute_name => attribute_name,
|
37
|
-
:
|
37
|
+
:error_options => simplify_options(:error, options),
|
38
|
+
:hint_options => simplify_options(:hint, options),
|
39
|
+
:input_options => simplify_options(:input, options),
|
40
|
+
:label_options => simplify_options(:label, options)
|
38
41
|
})
|
39
42
|
@prevent_recursion = false
|
40
43
|
output
|
41
44
|
end
|
42
45
|
|
43
46
|
def field_template_path(attribute_name)
|
44
|
-
|
47
|
+
field_layouts(attribute_name).detect { |template_file|
|
45
48
|
template.view_paths.exists?(template_file, '', false, {
|
46
49
|
:locale => [template.locale],
|
47
50
|
:formats => template.formats,
|
@@ -55,6 +58,11 @@ module ErbForm
|
|
55
58
|
backtrace = backtrace.collect { |line| line.scan(__FILE__).size > 0 ? nil : line }.compact!
|
56
59
|
end
|
57
60
|
end
|
61
|
+
|
62
|
+
def simplify_options(key, options = {})
|
63
|
+
newkey = key == :error ? :error_prefix : key
|
64
|
+
options[key].is_a?(Hash) ? options[key] : { newkey => (options[key]) }
|
65
|
+
end
|
58
66
|
end
|
59
67
|
|
60
68
|
class DoubleRenderError < StandardError;
|
data/lib/erb_form/version.rb
CHANGED
data/spec/test_app/Gemfile
CHANGED
@@ -2,7 +2,8 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'rails', '3.0.9'
|
4
4
|
gem 'sqlite3'
|
5
|
-
gem 'erb_form', '0.1.
|
5
|
+
gem 'erb_form', '0.1.1', :path => '../..'
|
6
|
+
gem 'simple_form', :git => 'git://github.com/plataformatec/simple_form'
|
6
7
|
|
7
8
|
group :development , :test do
|
8
9
|
gem 'rspec-rails'
|
@@ -5,8 +5,7 @@ SimpleForm.setup do |config|
|
|
5
5
|
# wrapper, change the order or even add your own to the
|
6
6
|
# stack. The options given below are used to wrap the
|
7
7
|
# whole input.
|
8
|
-
config.wrappers :default, :
|
9
|
-
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
|
8
|
+
config.wrappers :default, :tag => false do |b|
|
10
9
|
## Extensions enabled by default
|
11
10
|
# Any of these extensions can be disabled for a
|
12
11
|
# given input by passing: `f.input EXTENSION_NAME => false`.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "blogs/render_multiple_layouts" do
|
4
|
+
before(:each) do
|
5
|
+
assign(:blog, stub_model(Blog,
|
6
|
+
:name => "My name",
|
7
|
+
).as_new_record)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "when there is more than one type of field" do
|
11
|
+
it "renders the first field" do
|
12
|
+
render
|
13
|
+
rendered.should have_selector "div", :class => "blogs_name_field"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "renders the second field" do
|
17
|
+
render
|
18
|
+
rendered.should have_selector "div", :class => "forms_legacy_name_field"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "blogs/render_simple_form_with_options" do
|
4
|
+
before(:each) do
|
5
|
+
assign(:blog, stub_model(Blog,
|
6
|
+
:name => "",
|
7
|
+
:errors => {:name => ['must not be blank']}
|
8
|
+
).as_new_record)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "when there are simeple form helpers" do
|
12
|
+
it "finds the correct layout file" do
|
13
|
+
render
|
14
|
+
rendered.should have_selector "div", :class => "simple_form_field"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "renders the label" do
|
18
|
+
render
|
19
|
+
rendered.should have_selector "label", :class => "string required"
|
20
|
+
rendered.should have_selector "abbr", :title => "required"
|
21
|
+
rendered.should have_selector "label", :content => "My custom label"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "renders the input" do
|
25
|
+
render
|
26
|
+
rendered.should have_selector "input", :class => "string required"
|
27
|
+
rendered.should have_selector "input", :placeholder => "type your name here (in english)"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "renders the hint" do
|
31
|
+
render
|
32
|
+
rendered.should contain "My custom hint"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "renders the error" do
|
36
|
+
render
|
37
|
+
rendered.should contain "My custom error must not be blank"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "blogs/render_with_simple_form" do
|
4
|
+
before(:each) do
|
5
|
+
assign(:blog, stub_model(Blog,
|
6
|
+
:name => "",
|
7
|
+
:errors => {:name => ['must not be blank']}
|
8
|
+
).as_new_record)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "when there are simeple form helpers" do
|
12
|
+
it "finds the correct layout file" do
|
13
|
+
render
|
14
|
+
rendered.should have_selector "div", :class => "simple_form_field"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "renders the label" do
|
18
|
+
render
|
19
|
+
rendered.should have_selector "label", :class => "string required"
|
20
|
+
rendered.should have_selector "abbr", :title => "required"
|
21
|
+
rendered.should have_selector "label", :content => "My english label"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "renders the input" do
|
25
|
+
render
|
26
|
+
rendered.should have_selector "input", :class => "string required"
|
27
|
+
rendered.should have_selector "input", :placeholder => "type your name here (in english)"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "renders the hint" do
|
31
|
+
render
|
32
|
+
rendered.should contain "My hint in english"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "renders the error" do
|
36
|
+
render
|
37
|
+
rendered.should contain "Name must not be blank"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erb_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: simple_form
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153822240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 2.0.0.rc
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153822240
|
25
25
|
description: Wrap form helper methods in re-usable erb templates.
|
26
26
|
email:
|
27
27
|
- 23inhouse@gmail.com
|
@@ -53,6 +53,10 @@ files:
|
|
53
53
|
- spec/test_app/app/views/blogs/missing_attribute_template_error.html.erb
|
54
54
|
- spec/test_app/app/views/blogs/missing_layout_template_error.html.erb
|
55
55
|
- spec/test_app/app/views/blogs/name_field.html.erb
|
56
|
+
- spec/test_app/app/views/blogs/render_multiple_layouts.html.erb
|
57
|
+
- spec/test_app/app/views/blogs/render_simple_form_with_options.html
|
58
|
+
- spec/test_app/app/views/blogs/render_with_simple_form.html.erb
|
59
|
+
- spec/test_app/app/views/blogs/simple_form_field.html.erb
|
56
60
|
- spec/test_app/app/views/forms/default/field.html.erb
|
57
61
|
- spec/test_app/app/views/forms/default/legacy_field.html.erb
|
58
62
|
- spec/test_app/app/views/forms/default/name_field.html.erb
|
@@ -84,6 +88,9 @@ files:
|
|
84
88
|
- spec/test_app/spec/views/blogs/find_layouts.html.erb_spec.rb
|
85
89
|
- spec/test_app/spec/views/blogs/missing_attribute_template_error.html.erb_spec.rb
|
86
90
|
- spec/test_app/spec/views/blogs/missing_layout_template_error.html.erb_spec.rb
|
91
|
+
- spec/test_app/spec/views/blogs/render_multiple_layouts.html.erb_spec.rb
|
92
|
+
- spec/test_app/spec/views/blogs/render_simple_form_with_options.html.erb_spec
|
93
|
+
- spec/test_app/spec/views/blogs/render_with_simple_form.html.erb_spec.rb
|
87
94
|
homepage: ''
|
88
95
|
licenses: []
|
89
96
|
post_install_message:
|
@@ -126,6 +133,10 @@ test_files:
|
|
126
133
|
- spec/test_app/app/views/blogs/missing_attribute_template_error.html.erb
|
127
134
|
- spec/test_app/app/views/blogs/missing_layout_template_error.html.erb
|
128
135
|
- spec/test_app/app/views/blogs/name_field.html.erb
|
136
|
+
- spec/test_app/app/views/blogs/render_multiple_layouts.html.erb
|
137
|
+
- spec/test_app/app/views/blogs/render_simple_form_with_options.html
|
138
|
+
- spec/test_app/app/views/blogs/render_with_simple_form.html.erb
|
139
|
+
- spec/test_app/app/views/blogs/simple_form_field.html.erb
|
129
140
|
- spec/test_app/app/views/forms/default/field.html.erb
|
130
141
|
- spec/test_app/app/views/forms/default/legacy_field.html.erb
|
131
142
|
- spec/test_app/app/views/forms/default/name_field.html.erb
|
@@ -157,3 +168,6 @@ test_files:
|
|
157
168
|
- spec/test_app/spec/views/blogs/find_layouts.html.erb_spec.rb
|
158
169
|
- spec/test_app/spec/views/blogs/missing_attribute_template_error.html.erb_spec.rb
|
159
170
|
- spec/test_app/spec/views/blogs/missing_layout_template_error.html.erb_spec.rb
|
171
|
+
- spec/test_app/spec/views/blogs/render_multiple_layouts.html.erb_spec.rb
|
172
|
+
- spec/test_app/spec/views/blogs/render_simple_form_with_options.html.erb_spec
|
173
|
+
- spec/test_app/spec/views/blogs/render_with_simple_form.html.erb_spec.rb
|