hungryform-rails 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1360f77eb2ccee3eb12b09cd0014f1ee25df1f55
4
- data.tar.gz: f8f8252375c4cd6f24b88832801717d9c1c9522e
3
+ metadata.gz: 6f6b6e7094c00810270695e0294ed41fb03f4cec
4
+ data.tar.gz: c8ead7762f65a7c66ef783df184fc0c24b0d485e
5
5
  SHA512:
6
- metadata.gz: 5dfa2c3a39a452433b737528171134b1ea095a855abed53d6656e74dc7200d133ec1d95a6d8ac0bed3c057b865555ed96ebe69199c2b8a95ab64f36ac647e1c6
7
- data.tar.gz: 594ebc2ebae6e554433984a3fc0738a6672b6cbbe21e98537aeee973731817aa91678bf5eba0c7b3d5db737589674319c085e76c3b9e047acc006ae2fd992ac8
6
+ metadata.gz: c2126f7fba756c965cd425c0040cba3a7b1bc4f0b85aa98c1780c0922175b61c709c4f528de31c08ed4a2764e2b2a1e3180865a6b5b0a54877a9f5602ccee7ce
7
+ data.tar.gz: 7ddbc91e5914e9777ea604ccfa4a0772ccbfd3de75aceb0ed040bf1a267223edc755053d444de3e6086e955412fbb04054ae041b39702d8df477c359b003f3f8
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  This gem is an adaptor between the [HungryForm](http://github.com/andrba/hungryform) gem and Rails.
4
4
 
5
+ ![image](https://cloud.githubusercontent.com/assets/2174682/7443144/f07081bc-f179-11e4-921d-cbb4ded02776.png)
6
+
5
7
  ##Installation:
6
8
 
7
9
  Add the hungryform gem to your Gemfile:
@@ -12,10 +12,8 @@
12
12
  hungry_link_to_prev_page(
13
13
  form,
14
14
  "Prev",
15
- {
16
- class: HungryForm.configuration.rails.prev_button_class,
17
- method: :post
18
- }
15
+ class: HungryForm.configuration.rails.prev_button_class,
16
+ method: :post
19
17
  )
20
18
  end
21
19
  -%>
@@ -25,10 +23,8 @@
25
23
  hungry_link_to_next_page(
26
24
  form,
27
25
  "Next",
28
- {
29
- class: HungryForm.configuration.rails.next_button_class,
30
- method: :post
31
- }
26
+ class: HungryForm.configuration.rails.next_button_class,
27
+ method: :post
32
28
  )
33
29
  end
34
30
  -%>
@@ -38,10 +34,7 @@
38
34
  hungry_link_to_submit(
39
35
  form,
40
36
  "Submit",
41
- {
42
- class: HungryForm.configuration.rails.submit_button_class,
43
- method: :post
44
- }
37
+ class: HungryForm.configuration.rails.submit_button_class
45
38
  )
46
39
  end
47
40
  %>
@@ -1 +1 @@
1
- require 'hungryform/rails'
1
+ require 'hungryform/rails'
@@ -8,4 +8,4 @@ require 'hungryform/rails/version'
8
8
  require 'hungryform/rails/railtie'
9
9
  require 'hungryform/rails/engine'
10
10
  require 'hungryform/rails/action_view'
11
- require 'hungryform/rails/renderable'
11
+ require 'hungryform/rails/renderable'
@@ -1,14 +1,16 @@
1
1
  module HungryForm
2
2
  module Rails
3
+ # View helpers
3
4
  module ActionView
4
5
  # Render a form
5
6
  def hungry_form_for(form, options = {})
6
7
  options[:data] ||= {}
7
8
  options[:data][:rel] ||= form_rel(form)
8
- options[:class] = [options[:class], "hungryform"].compact.join(' ')
9
+ options[:class] = [options[:class], 'hungryform'].compact.join(' ')
10
+
11
+ views_prefix = options.delete(:elements_templates) ||
12
+ HungryForm.configuration.rails.elements_templates
9
13
 
10
- views_prefix = options.delete(:elements_templates) || HungryForm.configuration.rails.elements_templates
11
-
12
14
  form_tag('', options) do
13
15
  render partial: "#{views_prefix}/form", locals: {
14
16
  form: form,
@@ -18,27 +20,31 @@ module HungryForm
18
20
  end
19
21
 
20
22
  # Render a link to the next page
21
- def hungry_link_to_next_page(form, name, options = {}, &block)
23
+ def hungry_link_to_next_page(form, name, **options, &block)
22
24
  link_to name, *link_params(form, options, action: :next), &block
23
25
  end
24
26
 
25
27
  # Render a link to the previous page
26
- def hungry_link_to_prev_page(form, name, options = {}, &block)
28
+ def hungry_link_to_prev_page(form, name, **options, &block)
27
29
  link_to name, *link_params(form, options, action: :prev), &block
28
30
  end
29
31
 
30
32
  # Render a link to a provided page
31
- def hungry_link_to_page(form, page, options = {}, &block)
33
+ def hungry_link_to_page(form, page, **options, &block)
32
34
  link_to page.label, *link_params(form, options, action: :page, page: page), &block
33
35
  end
34
36
 
35
37
  # Render a link that submits the form
36
- def hungry_link_to_submit(form, name, options = {}, &block)
38
+ def hungry_link_to_submit(form, name, **options, &block)
37
39
  params = clean_params(form, options.delete(:params))
38
40
 
39
- link_to name, url_for(params), options.reverse_merge(
40
- data: { form_method: :post, form_action: :submit, rel: form_rel(form) }
41
- ), &block
41
+ link_to(name, url_for(params), options.reverse_merge(
42
+ data: {
43
+ form_method: :post,
44
+ form_action: :submit,
45
+ rel: form_rel(form)
46
+ }
47
+ ), &block)
42
48
  end
43
49
 
44
50
  private
@@ -49,13 +55,17 @@ module HungryForm
49
55
  "hungry-form-#{form.__id__}"
50
56
  end
51
57
 
52
- # Builds link_to params except for the link's name
58
+ # Builds link_to params except for the link's name
53
59
  def link_params(form, options, action_options = {})
54
60
  options = options.dup
55
61
  method = options.delete(:method) || 'get'
56
62
  params = clean_params(form, options.delete(:params))
57
63
 
58
- params[:page] = method.to_s == 'get' ? get_page(form, action_options) : form.current_page.name
64
+ if method.to_s == 'get'
65
+ params[:page] = get_page(form, action_options)
66
+ else
67
+ params[:page] = form.current_page.name
68
+ end
59
69
 
60
70
  options.reverse_merge!(
61
71
  data: {
@@ -88,4 +98,4 @@ module HungryForm
88
98
  end
89
99
  end
90
100
  end
91
- end
101
+ end
@@ -3,4 +3,4 @@ module HungryForm
3
3
  class Engine < ::Rails::Engine
4
4
  end
5
5
  end
6
- end
6
+ end
@@ -1,7 +1,9 @@
1
1
  module HungryForm
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
-
4
+ # Configuration module on top of the HungryForm configuration
5
+ # Creates a "rails" accessor that contains all the rails
6
+ # specific configuration parameters used in this gem
5
7
  module Configuration
6
8
  attr_accessor :rails
7
9
 
@@ -29,4 +31,4 @@ module HungryForm
29
31
  end
30
32
  end
31
33
  end
32
- end
34
+ end
@@ -1,12 +1,16 @@
1
1
  module HungryForm
2
2
  module Rails
3
+ # This module adds view specific methods to every HungryForm element
3
4
  module Renderable
4
5
  def wrapper_class
5
6
  classes = []
6
7
  classes << attributes[:wrapper_class] if attributes[:wrapper_class]
7
8
  classes << 'hidden' unless visible?
8
9
 
9
- if self.is_a?(HungryForm::Elements::Base::ActiveElement) && self.error.present?
10
+ invalid = self.is_a?(HungryForm::Elements::Base::ActiveElement) &&
11
+ error.present?
12
+
13
+ if invalid
10
14
  classes << HungryForm.configuration.rails.error_class || 'invalid'
11
15
  end
12
16
 
@@ -14,8 +18,12 @@ module HungryForm
14
18
  end
15
19
 
16
20
  def input_attributes
17
- attributes.except(*[configuration[:input_attributes_except], :wrapper_class, :checked].flatten)
21
+ except_attrs = [
22
+ configuration[:input_attributes_except],
23
+ :wrapper_class, :checked
24
+ ]
25
+ attributes.except(*except_attrs.flatten)
18
26
  end
19
27
  end
20
28
  end
21
- end
29
+ end
@@ -1,5 +1,5 @@
1
1
  module HungryForm
2
2
  module Rails
3
- VERSION = "0.0.5"
3
+ VERSION = '0.0.6'
4
4
  end
5
- end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hungryform-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Bazhutkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-02 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hungryform