simple_form-magic_submit 1.1.0 → 1.2.0

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: 7c2b4fa35c2a5f39e90147adb06366b67464969a
4
- data.tar.gz: 9e1f739bc6b5b2dc629bbe9cf1ee7c7bd2e6ba7c
3
+ metadata.gz: 87ca804fae3f7a0ddea9b6c274811bbd608fe202
4
+ data.tar.gz: 32b03c1942686a0a57f30dd863476eb4dcc9e8cd
5
5
  SHA512:
6
- metadata.gz: d948b4dda764fb3fea94c1024b26b225a404b3f1c930a6826c9205f65c2f16dc699a003f343416101a333fb94772206c29e384b3fd1db6b468becce208732f53
7
- data.tar.gz: 75217ff98788cf714dc88a5b2125492c60409460c2bf1a59ec0de290145a3840bccf4c5148a59f3745944159a310bab2d1bad4c6430a201a6c0f8e40bcd39719
6
+ metadata.gz: 8b7a8c045917656bdedab912ec93ed8eae928763cdfb3987c0b2fb87c33819f4eaca774c1e1f510549df116601ed997133491e18e732e7eb9e88ce49a844d514
7
+ data.tar.gz: 44aa9d4b79cec36cf2cf7819d57638a7e5d9a0ccc0eaf3fbfe8370003da1e1c76efaa1c6390222193c83bd771eb901223c181d4d181a8bfcfc49e09705572176
data/README.md CHANGED
@@ -125,3 +125,8 @@ Each lookup will have `%{model}` interpolated to the name of the model.
125
125
  3. Commit your changes (`git commit -am 'Add some feature'`)
126
126
  4. Push to the branch (`git push origin my-new-feature`)
127
127
  5. Create new Pull Request
128
+
129
+ ## Thanks go to...
130
+
131
+ Victor Nahuel Chaves (https://github.com/nahue) for adding support for model-less forms.
132
+
@@ -22,28 +22,53 @@ module SimpleForm
22
22
  end
23
23
 
24
24
  private
25
+
26
+ def bound_to_model?
27
+ # if its a string means that its bound to a model.. but if its a symbol its not...
28
+ self.object_name.is_a?(String)# || self.object.present?
29
+ end
30
+
25
31
  def main_class(options = {})
26
32
  options.fetch(:destructive, false) ? 'btn-destructive' : 'btn-primary'
27
33
  end
28
-
34
+
29
35
  def controller_scope
36
+ # falls to default if the model isn't tied to a model
37
+ return "default" unless bound_to_model?
38
+
30
39
  template.controller.params[:controller].gsub('/', '.')
31
40
  end
32
41
 
33
42
  def object_scope
43
+ # returns empty string if no model is found to prevent exception
44
+ return "" unless bound_to_model?
45
+
34
46
  self.object.class.model_name.i18n_key.to_s
35
47
  end
36
48
 
37
49
  def translate_key(key = nil)
38
- key ||= self.object.errors.count > 0 ? :retry : :submit
39
- I18n.t("simple_form.magic_submit.#{controller_scope}.#{object_scope}.#{lookup_action}.#{key}",
40
- default: [
41
- :"simple_form.magic_submit.#{controller_scope}.#{lookup_action}.#{key}",
42
- :"simple_form.magic_submit.default.#{lookup_action}.#{key}",
43
- :"helpers.submit.#{lookup_action}"
44
- ],
45
- model: self.object.class.model_name.human.titlecase
46
- ).html_safe
50
+
51
+ if bound_to_model?
52
+ key ||= self.object.errors.count > 0 ? :retry : :submit
53
+
54
+ I18n.t("simple_form.magic_submit.#{controller_scope}.#{object_scope}.#{lookup_action}.#{key}",
55
+ default: [
56
+ :"simple_form.magic_submit.#{controller_scope}.#{lookup_action}.#{key}",
57
+ :"simple_form.magic_submit.default.#{lookup_action}.#{key}",
58
+ :"helpers.submit.#{lookup_action}"
59
+ ],
60
+ model: self.object.class.model_name.human.titlecase
61
+ ).html_safe
62
+ else
63
+ # we have no model errors... so we test if the post is get or already posted
64
+ key ||= template.request.get? ? :submit : :retry
65
+ I18n.t("simple_form.magic_submit.#{controller_scope}.#{object_scope}.#{lookup_action}.#{key}",
66
+ default: [
67
+ :"simple_form.magic_submit.#{controller_scope}.#{lookup_action}.#{key}",
68
+ :"simple_form.magic_submit.default.#{lookup_action}.#{key}",
69
+ :"helpers.submit.#{lookup_action}"
70
+ ]).html_safe
71
+ end
47
72
  end
48
73
 
49
74
  end
@@ -1,5 +1,5 @@
1
1
  module SimpleForm
2
2
  module MagicSubmit
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form-magic_submit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Subbotin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-08 00:00:00.000000000 Z
11
+ date: 2014-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_form
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.0.3
123
+ rubygems_version: 2.1.11
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Magic Submit Button for Simple Form