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 +4 -4
- data/README.md +2 -0
- data/app/views/hungryform/_form.html.erb +5 -12
- data/lib/hungryform-rails.rb +1 -1
- data/lib/hungryform/rails.rb +1 -1
- data/lib/hungryform/rails/action_view.rb +23 -13
- data/lib/hungryform/rails/engine.rb +1 -1
- data/lib/hungryform/rails/railtie.rb +4 -2
- data/lib/hungryform/rails/renderable.rb +11 -3
- data/lib/hungryform/rails/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f6b6e7094c00810270695e0294ed41fb03f4cec
|
4
|
+
data.tar.gz: c8ead7762f65a7c66ef783df184fc0c24b0d485e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+

|
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
|
-
|
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
|
-
|
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
|
%>
|
data/lib/hungryform-rails.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'hungryform/rails'
|
1
|
+
require 'hungryform/rails'
|
data/lib/hungryform/rails.rb
CHANGED
@@ -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],
|
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
|
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
|
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
|
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
|
38
|
+
def hungry_link_to_submit(form, name, **options, &block)
|
37
39
|
params = clean_params(form, options.delete(:params))
|
38
40
|
|
39
|
-
link_to
|
40
|
-
data: {
|
41
|
-
|
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
|
-
|
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
|
-
|
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
|
@@ -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
|
-
|
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
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hungryform
|