hungryform-rails 0.0.4 → 0.0.5

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: 352c2e9eab241d7cd69e2be42d84cda9961e8f10
4
- data.tar.gz: 4c3b715e1c945e777710b4277f95a4350f1058a0
3
+ metadata.gz: 1360f77eb2ccee3eb12b09cd0014f1ee25df1f55
4
+ data.tar.gz: f8f8252375c4cd6f24b88832801717d9c1c9522e
5
5
  SHA512:
6
- metadata.gz: f228d423f2b55ffdd7f8125516ee61d05f83d7cf37364d10ba17a603427b8c8afc598f6fea63bb19c2ed822452131e8898bcfea592e7ff4ece5ba32d43eb7d78
7
- data.tar.gz: ab002ba6dd14ca41ef1cf1367ec0242f6d382fb121faf2a03b1576b60cbee95bb9affaa1a1ace3d0df6b52359c418c83afed93001ddceec65096e69d65cabbe8
6
+ metadata.gz: 5dfa2c3a39a452433b737528171134b1ea095a855abed53d6656e74dc7200d133ec1d95a6d8ac0bed3c057b865555ed96ebe69199c2b8a95ab64f36ac647e1c6
7
+ data.tar.gz: 594ebc2ebae6e554433984a3fc0738a6672b6cbbe21e98537aeee973731817aa91678bf5eba0c7b3d5db737589674319c085e76c3b9e047acc006ae2fd992ac8
@@ -1,12 +1,15 @@
1
- <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do
1
+ <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do -%>
2
2
 
3
- concat label_tag field.name, field.label << ("*" if field.required?).to_s
4
- concat hidden_field_tag field.name, 0
5
- concat check_box_tag field.name, 1, field.checked?, field.input_attributes
6
- unless field.error.empty?
7
- concat content_tag :span, field.error, class: 'error'
8
- end
9
-
10
- end %>
3
+ <div class="checkbox">
4
+ <%= label_tag '' do %>
5
+ <%= hidden_field_tag field.name, 0 %>
6
+ <%= check_box_tag field.name, 1, field.checked?, field.input_attributes %>
7
+ <%= field.label << ("*" if field.required?).to_s %>
8
+ <% end -%>
9
+ </div>
11
10
 
12
- <%= field.attributes.inspect %>
11
+ <% unless field.error.empty? -%>
12
+ <%= content_tag :span, field.error, class: 'error' %>
13
+ <% end -%>
14
+
15
+ <% end -%>
@@ -1,11 +1,47 @@
1
1
  <%= hidden_field_tag :form_action %>
2
2
 
3
- <h1><%= form.current_page.label %></h1>
3
+ <h1><%= form.current_page.title %></h1>
4
4
 
5
5
  <% form.current_page.elements.each do |el| %>
6
6
  <%= render partial: "#{views_prefix}/#{el.class.name.demodulize.underscore}", locals: { field: el, views_prefix: views_prefix } %>
7
7
  <% end %>
8
8
 
9
- <%= hungry_link_to_prev_page(form, "Prev", method: :post) if form.prev_page %>
10
- <%= hungry_link_to_next_page(form, "Next", method: :post) if form.next_page %>
11
- <%= hungry_link_to_submit(form, "Submit") if form.current_page == form.pages.last %>
9
+ <%=
10
+ # Previous page button
11
+ if form.prev_page
12
+ hungry_link_to_prev_page(
13
+ form,
14
+ "Prev",
15
+ {
16
+ class: HungryForm.configuration.rails.prev_button_class,
17
+ method: :post
18
+ }
19
+ )
20
+ end
21
+ -%>
22
+ <%=
23
+ # Next Page Button
24
+ if form.next_page
25
+ hungry_link_to_next_page(
26
+ form,
27
+ "Next",
28
+ {
29
+ class: HungryForm.configuration.rails.next_button_class,
30
+ method: :post
31
+ }
32
+ )
33
+ end
34
+ -%>
35
+ <%=
36
+ # Submit button
37
+ if form.current_page == form.pages.last
38
+ hungry_link_to_submit(
39
+ form,
40
+ "Submit",
41
+ {
42
+ class: HungryForm.configuration.rails.submit_button_class,
43
+ method: :post
44
+ }
45
+ )
46
+ end
47
+ %>
@@ -1,7 +1,7 @@
1
- <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do
1
+ <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do -%>
2
2
 
3
- field.elements.each do |el|
4
- concat render partial: "#{views_prefix}/#{el.class.name.demodulize.underscore}", locals: { field: el, views_prefix: views_prefix }
5
- end
3
+ <% field.elements.each do |el| -%>
4
+ <%= render partial: "#{views_prefix}/#{el.class.name.demodulize.underscore}", locals: { field: el, views_prefix: views_prefix } -%>
5
+ <% end -%>
6
6
 
7
- end %>
7
+ <% end -%>
@@ -1,11 +1,18 @@
1
- <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do
1
+ <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do -%>
2
2
 
3
- concat label_tag field.name, field.label << ("*" if field.required?).to_s
4
- field.options.each do |key, value|
5
- concat radio_button_tag key, value, field.value == value, field.input_attributes
6
- end
7
- unless field.error.empty?
8
- concat content_tag :span, field.error, class: 'error'
9
- end
3
+ <%= label_tag field.name, field.label << ("*" if field.required?).to_s %>
10
4
 
11
- end %>
5
+ <% field.options.each do |value, name| %>
6
+ <div class="radio">
7
+ <%= label_tag '' do %>
8
+ <%= radio_button_tag field.name, value, field.value == value, field.input_attributes %>
9
+ <%= name %>
10
+ <% end -%>
11
+ </div>
12
+ <% end -%>
13
+
14
+ <% unless field.error.empty? -%>
15
+ <%= content_tag :span, field.error, class: 'error' %>
16
+ <% end -%>
17
+
18
+ <% end -%>
@@ -1,9 +1,10 @@
1
- <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do
1
+ <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do -%>
2
2
 
3
- concat label_tag field.name, field.label << ("*" if field.required?).to_s
4
- concat select_tag field.name, options_for_select(field.options.invert, field.value), field.input_attributes
5
- unless field.error.empty?
6
- concat content_tag :span, field.error, class: 'error'
7
- end
3
+ <%= label_tag field.name, field.label << ("*" if field.required?).to_s %>
4
+ <%= select_tag field.name, options_for_select(field.options.invert, field.value), field.input_attributes %>
5
+
6
+ <% unless field.error.empty? -%>
7
+ <%= content_tag :span, field.error, class: 'error' %>
8
+ <% end -%>
8
9
 
9
- end %>
10
+ <% end -%>
@@ -1,9 +1,10 @@
1
- <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do
1
+ <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do -%>
2
2
 
3
- concat label_tag field.name, field.label << ("*" if field.required?).to_s
4
- concat text_area_tag field.name, field.value, field.input_attributes
5
- unless field.error.empty?
6
- concat content_tag :span, field.error, class: 'error'
7
- end
3
+ <%= label_tag field.name, field.label << ("*" if field.required?).to_s %>
4
+ <%= text_area_tag field.name, field.value, field.input_attributes %>
5
+
6
+ <% unless field.error.empty? -%>
7
+ <%= content_tag :span, field.error, class: 'error' %>
8
+ <% end -%>
8
9
 
9
- end %>
10
+ <% end -%>
@@ -1,9 +1,10 @@
1
- <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do
1
+ <%= content_tag :div, id: "#{field.name}_wrapper", class: field.wrapper_class, 'data-dependency' => field.dependency_json do -%>
2
2
 
3
- concat label_tag field.name, field.label << ("*" if field.required?).to_s
4
- concat text_field_tag field.name, field.value, field.input_attributes
5
- unless field.error.empty?
6
- concat content_tag :span, field.error, class: 'error'
7
- end
3
+ <%= label_tag field.name, field.label << ("*" if field.required?).to_s %>
4
+ <%= text_field_tag field.name, field.value, field.input_attributes %>
8
5
 
9
- end %>
6
+ <% unless field.error.empty? -%>
7
+ <%= content_tag :span, field.error, class: 'error' %>
8
+ <%end -%>
9
+
10
+ <% end -%>
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.required_ruby_version = '>= 2.0.0'
23
23
 
24
- spec.add_dependency 'hungryform', '~> 0.0', '>= 0.0.10'
24
+ spec.add_dependency 'hungryform', '~> 0.0', '>= 0.0.11'
25
25
  spec.add_dependency 'rails', '>= 3.2.1'
26
26
 
27
27
  spec.add_development_dependency "rspec", '~> 3.0'
@@ -7,8 +7,8 @@ module HungryForm
7
7
  options[:data][:rel] ||= form_rel(form)
8
8
  options[:class] = [options[:class], "hungryform"].compact.join(' ')
9
9
 
10
- views_prefix = options.delete(:views_prefix) || HungryForm.configuration.rails.elements_templates
11
-
10
+ views_prefix = options.delete(:elements_templates) || HungryForm.configuration.rails.elements_templates
11
+
12
12
  form_tag('', options) do
13
13
  render partial: "#{views_prefix}/form", locals: {
14
14
  form: form,
@@ -51,6 +51,7 @@ module HungryForm
51
51
 
52
52
  # Builds link_to params except for the link's name
53
53
  def link_params(form, options, action_options = {})
54
+ options = options.dup
54
55
  method = options.delete(:method) || 'get'
55
56
  params = clean_params(form, options.delete(:params))
56
57
 
@@ -4,14 +4,22 @@ module HungryForm
4
4
 
5
5
  module Configuration
6
6
  attr_accessor :rails
7
+
8
+ def self.extended(base)
9
+ base.rails = ActiveSupport::OrderedOptions.new
10
+
11
+ base.rails.elements_templates = 'hungryform'
12
+ base.rails.error_class = 'invalid'
13
+
14
+ [:next_button_class, :prev_button_class, :submit_button_class].each do |button|
15
+ base.rails.send(button, '')
16
+ end
17
+ end
7
18
  end
8
19
 
9
20
  initializer 'hungryform', before: :load_config_initializers do
10
21
  HungryForm::Elements::Base::Element.send :include, Renderable
11
-
12
22
  HungryForm.configuration.extend Configuration
13
- HungryForm.configuration.rails = ActiveSupport::OrderedOptions.new
14
- HungryForm.configuration.rails.elements_templates = 'hungryform'
15
23
  end
16
24
 
17
25
  initializer 'active_support' do
@@ -3,15 +3,18 @@ module HungryForm
3
3
  module Renderable
4
4
  def wrapper_class
5
5
  classes = []
6
- classes << configuration[:wrapper_class] if configuration.key?(:wrapper_class)
7
6
  classes << attributes[:wrapper_class] if attributes[:wrapper_class]
8
7
  classes << 'hidden' unless visible?
9
- classes << 'invalid' if self.is_a?(HungryForm::Elements::Base::ActiveElement) && self.error.present?
8
+
9
+ if self.is_a?(HungryForm::Elements::Base::ActiveElement) && self.error.present?
10
+ classes << HungryForm.configuration.rails.error_class || 'invalid'
11
+ end
12
+
10
13
  classes.join(' ') if classes.any?
11
14
  end
12
15
 
13
16
  def input_attributes
14
- attributes.except(*[configuration[:input_attributes_except], :wrapper_class].flatten)
17
+ attributes.except(*[configuration[:input_attributes_except], :wrapper_class, :checked].flatten)
15
18
  end
16
19
  end
17
20
  end
@@ -1,5 +1,5 @@
1
1
  module HungryForm
2
2
  module Rails
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -0,0 +1,15 @@
1
+ RSpec.shared_examples 'labeled active element' do
2
+ it 'has a label' do
3
+ render render_params
4
+ expect(rendered).to include '<label for="group_field_name">Field name</label>'
5
+ end
6
+
7
+ context 'when it is required' do
8
+ before(:each) { attributes[:required] = true }
9
+
10
+ it "has an asterisk" do
11
+ render render_params
12
+ expect(rendered).to include '<label for="group_field_name">Field name*</label>'
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,4 @@
1
1
  RSpec.shared_examples 'rendered active element' do
2
- it 'has a label' do
3
- render render_params
4
- expect(rendered).to include '<label for="group_field_name">Field name</label>'
5
- end
6
-
7
2
  context 'when it is required' do
8
3
  before(:each) { attributes[:required] = true }
9
4
 
@@ -13,11 +8,6 @@ RSpec.shared_examples 'rendered active element' do
13
8
  expect(rendered).to match /<div.*class="invalid"/
14
9
  end
15
10
 
16
- it "has an asterisk in a label" do
17
- render render_params
18
- expect(rendered).to include '<label for="group_field_name">Field name*</label>'
19
- end
20
-
21
11
  it "has an error message" do
22
12
  field.valid?
23
13
  render render_params
@@ -14,6 +14,7 @@ describe 'rendering text field' do
14
14
 
15
15
  it_behaves_like 'it is wrapped in a div'
16
16
  it_behaves_like 'rendered active element'
17
+ it_behaves_like 'labeled active element'
17
18
 
18
19
  it 'has an input' do
19
20
  render render_params
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hungryform-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Bazhutkin
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.0.10
22
+ version: 0.0.11
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.0.10
32
+ version: 0.0.11
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rails
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +148,7 @@ files:
148
148
  - spec/views/group_spec.rb
149
149
  - spec/views/html_spec.rb
150
150
  - spec/views/select_field_spec.rb
151
+ - spec/views/shared_examples/labeled_active_element.rb
151
152
  - spec/views/shared_examples/rendered_active_element.rb
152
153
  - spec/views/shared_examples/wrapped.rb
153
154
  - spec/views/text_area_spec.rb
@@ -188,6 +189,7 @@ test_files:
188
189
  - spec/views/group_spec.rb
189
190
  - spec/views/html_spec.rb
190
191
  - spec/views/select_field_spec.rb
192
+ - spec/views/shared_examples/labeled_active_element.rb
191
193
  - spec/views/shared_examples/rendered_active_element.rb
192
194
  - spec/views/shared_examples/wrapped.rb
193
195
  - spec/views/text_area_spec.rb