express_admin 1.4.10 → 1.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/express_admin/shared/_tables.sass +5 -0
  3. data/app/components/express_admin/smart_table.rb +1 -1
  4. data/app/components/express_admin/widget_box.rb +5 -1
  5. data/app/helpers/express_admin/admin_helper.rb +2 -2
  6. data/lib/express_admin/standard_actions.rb +54 -7
  7. data/lib/express_admin/version.rb +1 -1
  8. data/test/controllers/standard_controller_test.rb +6 -0
  9. data/test/dummy/app/models/widget.rb +2 -0
  10. data/test/dummy/db/test.sqlite3 +0 -0
  11. data/test/dummy/test/components/definition_list_test.rb +1 -1
  12. data/test/dummy/test/components/definition_table_test.rb +1 -1
  13. data/test/dummy/test/components/flash_messages_test.rb +6 -9
  14. data/test/dummy/test/components/icon_link_test.rb +1 -1
  15. data/test/dummy/test/components/icon_test.rb +1 -1
  16. data/test/dummy/test/components/module_sidebar_test.rb +16 -22
  17. data/test/dummy/test/components/smart_form_test.rb +4 -4
  18. data/test/dummy/test/components/smart_table_test.rb +6 -9
  19. data/test/dummy/test/components/widget_box_test.rb +5 -5
  20. data/test/test_helper.rb +11 -9
  21. data/vendor/gems/express_templates/Gemfile.lock +1 -1
  22. data/vendor/gems/express_templates/express_templates-0.10.0.gem +0 -0
  23. data/vendor/gems/express_templates/lib/express_templates/components/all.rb +26 -0
  24. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/resourceful.rb +11 -15
  25. data/vendor/gems/express_templates/lib/express_templates/components/forms/basic_fields.rb +4 -4
  26. data/vendor/gems/express_templates/lib/express_templates/components/forms/checkbox.rb +1 -1
  27. data/vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb +6 -2
  28. data/vendor/gems/express_templates/lib/express_templates/components/forms/form_component.rb +16 -4
  29. data/vendor/gems/express_templates/lib/express_templates/components/forms/radio.rb +3 -3
  30. data/vendor/gems/express_templates/lib/express_templates/components.rb +1 -0
  31. data/vendor/gems/express_templates/lib/express_templates/version.rb +1 -1
  32. data/vendor/gems/express_templates/test/components/forms/basic_fields_test.rb +17 -9
  33. data/vendor/gems/express_templates/test/components/forms/checkbox_test.rb +13 -3
  34. data/vendor/gems/express_templates/test/components/forms/express_form_test.rb +12 -8
  35. data/vendor/gems/express_templates/test/components/forms/radio_test.rb +14 -2
  36. data/vendor/gems/express_templates/test/components/forms/select_test.rb +11 -3
  37. data/vendor/gems/express_templates/test/dummy/log/test.log +5511 -0
  38. data/vendor/gems/express_templates/test/test_helper.rb +3 -17
  39. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e25ebe07ee84728e3a8f4acca5974226f02d2f21
4
- data.tar.gz: 4a76de8d7ac61d45004c76f75b40e4fb7ed369d3
3
+ metadata.gz: dc5b5fd470148d183da2706152e9b7019eb2c6d9
4
+ data.tar.gz: b39194d97af745e8e35873dd0a9e9e44bfb356f7
5
5
  SHA512:
6
- metadata.gz: 490d110f3e7eaff50d813d3b7b1c7248e758635b1badeef9f44211c09d3efe64a0eb99902408ab67412a086c2bc03d7b3794587474b54eb216ec61342827b420
7
- data.tar.gz: 7ad9bbce99efb8503150a6e955d905733da5b14b30eb92a493241e3dc448e92fc3820fde08ceb470ff5a6d279cf7f75a78d2de4f622b2d0dce5b3958ed1df3c5
6
+ metadata.gz: 1411b21129cb3d05ba04f7f83bb13428e6145cab8702897079d5cbcb9304486ca516f9076b60c9b71e8f6edc48abe880e21010404d1d9ccd0081a2fe8427e49b
7
+ data.tar.gz: f0348de1c2da9faf4f5810c53449721a01c0f423d1af63e0048a80b01e4f5b9fa8cc226cc0a84b915a48bd60864231277edef22d7bea874f665a521740034be6
@@ -30,3 +30,8 @@
30
30
 
31
31
  @include breakpoint(large)
32
32
  height: 800px
33
+
34
+ .definition-table
35
+ tbody
36
+ td
37
+ padding: 0.5rem
@@ -101,7 +101,7 @@ module ExpressAdmin
101
101
  if config[:row_class].try(:respond_to?, :call)
102
102
  config[:row_class].call(item)
103
103
  else
104
- item.eql?(helpers.resource) ? 'current' : ''
104
+ item.eql?(resource) ? 'current' : ''
105
105
  end
106
106
  end
107
107
 
@@ -21,7 +21,11 @@ module ExpressAdmin
21
21
  end
22
22
 
23
23
  def box_title
24
- config[:title] || (helpers.resource.persisted? ? "Edit #{resource_name}" : "New #{resource_name}")
24
+ config[:title] || (resource.persisted? ? "Edit #{resource_name}" : "New #{resource_name}")
25
+ end
26
+
27
+ def resource
28
+ self.send(config[:id])
25
29
  end
26
30
  end
27
31
  end
@@ -56,9 +56,9 @@ module ExpressAdmin
56
56
  content_for?(:description) ? yield(:description) : 'Testapp'
57
57
  end
58
58
 
59
- def admin_javascript_and_css_includes
59
+ def admin_javascript_and_css_includes(admin_path = nil)
60
60
  current_module_path = current_module.to_s.underscore
61
- admin_path = current_module_path.eql?('admin') ? "admin" : "#{current_module_path}/admin"
61
+ admin_path ||= current_module_path.eql?('admin') ? "admin" : "#{current_module_path}/admin"
62
62
  a = []
63
63
  a << stylesheet_link_tag("#{admin_path}/application")
64
64
  a << stylesheet_link_tag("app_express/admin/application") if defined?(AppExpress)
@@ -24,11 +24,53 @@ module ExpressAdmin
24
24
  params.require(:#{base.resource_name}).permit!
25
25
  end
26
26
  RUBY
27
+
28
+ base.class_eval do
29
+
30
+ class_attribute :resource_class
31
+ self.resource_class = resource_name.classify.constantize
32
+
33
+ if self.resource_class.respond_to?(:commands)
34
+ self.resource_class.commands.each do |command|
35
+ define_command_method(command)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def manages(a_resource_class)
42
+ self.resource_class = a_resource_class
27
43
  end
28
44
 
29
45
  def resource_name
30
46
  self.to_s.demodulize.gsub(/Controller$/, '').singularize.underscore
31
47
  end
48
+
49
+ protected
50
+
51
+ def define_command_method(command)
52
+ define_method(command) do
53
+ load_resource
54
+ begin
55
+ resource.send(command)
56
+ respond_to do |format|
57
+ format.html { redirect_to :show, layout: defaults[:layout] }
58
+ format.js { render status: :ok } # maybe we should return enough info
59
+ #to alter display of available or enabled commands?
60
+
61
+ end
62
+ rescue => e
63
+ respond_to do |format|
64
+ format.html {
65
+ flash[:error] = e.to_s
66
+ redirect_to :show, layout: defaults[:layout]
67
+ }
68
+ format.js { render status: :bad_request, body: e.to_s }
69
+ end
70
+ end
71
+ end
72
+ end
73
+
32
74
  end
33
75
 
34
76
  module InstanceMethods
@@ -157,14 +199,19 @@ module ExpressAdmin
157
199
 
158
200
  def end_of_association_chain
159
201
  if nested?
160
- parent_resource.send(resource_name.pluralize)
202
+ parent_resource
161
203
  else
162
- resource_class
204
+ nil
163
205
  end
164
206
  end
165
207
 
166
208
  def load_collection
167
- self.instance_variable_set(collection_ivar, end_of_association_chain.all)
209
+ scope = if end_of_association_chain
210
+ end_of_association_chain.send(collection_name)
211
+ else
212
+ resource_class
213
+ end
214
+ self.instance_variable_set(collection_ivar, scope.all)
168
215
  end
169
216
 
170
217
  def collection_ivar
@@ -185,7 +232,7 @@ module ExpressAdmin
185
232
 
186
233
  def build_resource(*args)
187
234
  if nested?
188
- self.instance_variable_set(resource_ivar, end_of_association_chain.build(*args))
235
+ self.instance_variable_set(resource_ivar, end_of_association_chain.send(collection_name).build(*args))
189
236
  else
190
237
  self.instance_variable_set(resource_ivar, resource_class.new(*args))
191
238
  end
@@ -199,9 +246,9 @@ module ExpressAdmin
199
246
  "@#{resource_name}".to_sym
200
247
  end
201
248
 
202
- def resource_class
203
- self.class.to_s.gsub(/Controller$/, '').singularize.classify.constantize
204
- end
249
+ # def resource_class
250
+ # self.class.to_s.gsub(/Controller$/, '').singularize.classify.constantize
251
+ # end
205
252
 
206
253
  # Foo::WidgetsController -> widget
207
254
  def resource_name
@@ -1,3 +1,3 @@
1
1
  module ExpressAdmin
2
- VERSION = "1.4.10"
2
+ VERSION = "1.4.11"
3
3
  end
@@ -107,5 +107,11 @@ module ExpressAdmin
107
107
 
108
108
  # TODO: Implement later
109
109
  # test "for nested resources it should try to expose a current method for parent resources"
110
+
111
+ test ".define_command_method defines a command action method on the controller" do
112
+ refute widgets_controller.respond_to?(:foo)
113
+ widgets_controller.class.send(:define_command_method, :foo)
114
+ assert widgets_controller.respond_to?(:foo)
115
+ end
110
116
  end
111
117
  end
@@ -5,4 +5,6 @@ class Widget < ActiveRecord::Base
5
5
  has_many :tags, through: :widget_tags
6
6
  has_many :parts
7
7
 
8
+ attr :password
9
+
8
10
  end
Binary file
@@ -9,7 +9,7 @@ module ExpressAdmin
9
9
  end
10
10
 
11
11
  def helpers
12
- mock_action_view(assigns)
12
+ mock_action_view
13
13
  end
14
14
 
15
15
  def list_types
@@ -9,7 +9,7 @@ module ExpressAdmin
9
9
  end
10
10
 
11
11
  def helpers
12
- mock_action_view(assigns)
12
+ mock_action_view
13
13
  end
14
14
 
15
15
  def list_types
@@ -4,16 +4,13 @@ module Components
4
4
 
5
5
  class FlashMessagesTest < ActiveSupport::TestCase
6
6
 
7
- def assigns
8
- { flash: flash }
9
- end
10
-
11
- def flash
12
- {notice: "Message"}
13
- end
14
-
15
7
  def helpers
16
- view = mock_action_view(assigns)
8
+ mock_action_view do
9
+ def flash
10
+ {notice: "Message"}
11
+ end
12
+
13
+ end
17
14
  end
18
15
 
19
16
  def flashmsg
@@ -21,7 +21,7 @@ module ExpressAdmin
21
21
  end
22
22
 
23
23
  def helpers
24
- mock_action_view(assigns)
24
+ mock_action_view
25
25
  end
26
26
 
27
27
  def rendered_icon_link(*args)
@@ -9,7 +9,7 @@ module Components
9
9
  end
10
10
 
11
11
  def helpers
12
- mock_action_view(assigns)
12
+ mock_action_view
13
13
  end
14
14
 
15
15
  def rendered_icon(*args)
@@ -20,28 +20,22 @@ module Components
20
20
  }
21
21
  end
22
22
 
23
- def assigns
24
- { current_menu: current_menu,
25
- current_menu_name: current_menu_name,
26
- foo_path: 'foo',
27
- bar_path: 'bar',
28
- baz_path: 'baz'
29
- }
30
- end
31
-
32
- def current_menu
33
- MenuItem.new('Big Menu', 'menu_path', [
34
- MenuItem.new('Foo', 'foo_path',[]),
35
- MenuItem.new('Bar', 'bar_path', []),
36
- MenuItem.new('Baz', 'baz_path', [])])
37
- end
38
-
39
- def current_menu_name
40
- current_menu.title
41
- end
42
-
43
23
  def helpers
44
- mock_action_view(assigns)
24
+ mock_action_view do
25
+ def foo_path ; "foo" ; end
26
+ def bar_path ; "bar" ; end
27
+ def baz_path ; "baz" ; end
28
+ def current_menu
29
+ MenuItem.new('Big Menu', 'menu_path', [
30
+ MenuItem.new('Foo', 'foo_path',[]),
31
+ MenuItem.new('Bar', 'bar_path', []),
32
+ MenuItem.new('Baz', 'baz_path', [])])
33
+ end
34
+ def current_menu_name
35
+ current_menu.title
36
+ end
37
+
38
+ end
45
39
  end
46
40
 
47
41
  test "renders the correct current menu name as sidebar title" do
@@ -49,7 +43,7 @@ module Components
49
43
  end
50
44
 
51
45
  test "evals the correct path" do
52
- assert_equal "foo", helpers.instance_eval(current_menu.items.first.path)
46
+ assert_equal "foo", helpers.instance_eval(helpers.current_menu.items.first.path)
53
47
  end
54
48
 
55
49
  end
@@ -5,11 +5,11 @@ module ExpressAdmin
5
5
  class SmartFormTest < ActiveSupport::TestCase
6
6
 
7
7
  def resource_assigns
8
- {resource: Widget.new, collection: Widget.all, example_engine: ExampleEngine::MockRouteProxy.new}
8
+ {example_engine: ExampleEngine::MockRouteProxy.new}
9
9
  end
10
10
 
11
11
  def helpers
12
- view = mock_action_view(resource_assigns)
12
+ view = mock_action_view
13
13
  class << view
14
14
  def widget_path(widget_id)
15
15
  "/widgets/#{widget_id.to_param}"
@@ -27,7 +27,7 @@ module ExpressAdmin
27
27
  end
28
28
 
29
29
  def widget_form(*args)
30
- arbre {
30
+ arbre(widget: Widget.new) {
31
31
  smart_form(:widget, *args)
32
32
  }
33
33
  end
@@ -55,7 +55,7 @@ module ExpressAdmin
55
55
  end
56
56
 
57
57
  test "text field column3 is a text_area" do
58
- assert_match /<textarea.*rows="10".*name="widget\[column3\]"/, widget_form
58
+ assert_match /<textarea.*name="widget\[column3\]".*rows="10"/, widget_form
59
59
  end
60
60
 
61
61
  test "datetime field column4 is a datetime_field" do
@@ -5,20 +5,17 @@ module Components
5
5
 
6
6
  fixtures :widgets, :categories
7
7
 
8
- def resource_assigns
9
- {resource: Widget.new, collection: Widget.all}
10
- end
11
8
  def helpers
12
- view = mock_action_view(resource_assigns)
13
- class << view
9
+ view = mock_action_view do
14
10
  def widget_path(widget_id)
15
11
  "/widgets/#{widget_id.to_param}"
16
12
  end
17
13
  end
18
14
  view
19
15
  end
16
+
20
17
  def compiled_widget_table(*args)
21
- arbre {
18
+ arbre(widget: Widget.first, widgets: Widget.all) {
22
19
  smart_table(:widgets, *args)
23
20
  }
24
21
  end
@@ -65,7 +62,7 @@ module Components
65
62
  end
66
63
 
67
64
  def compiled_widget_table_with_proc_column
68
- arbre {
65
+ arbre(widget: Widget.first, widgets: Widget.all) {
69
66
  smart_table(:widgets, columns: {
70
67
  "This column will error" => -> (widget) { doesnt_work },
71
68
  "This column will be fine" => -> (widget) { widget.column2.upcase },
@@ -86,7 +83,7 @@ module Components
86
83
  end
87
84
 
88
85
  test 'attribute accessor appended with _link generates a link' do
89
- fragment = arbre {
86
+ fragment = arbre(widget: Widget.first, widgets: Widget.all) {
90
87
  smart_table(:widgets, columns: {
91
88
  'A link column' => :column3_link
92
89
  })
@@ -95,7 +92,7 @@ module Components
95
92
  end
96
93
 
97
94
  test 'timestamp accessor appeneded with _in_words generates code that uses time_ago_in_words' do
98
- fragment = arbre {
95
+ fragment = arbre(widget: Widget.first, widgets: Widget.all) {
99
96
  smart_table(:widgets, columns: {
100
97
  'Created' => :created_at_in_words
101
98
  })
@@ -5,25 +5,25 @@ module ExpressAdmin
5
5
  class WidgetBoxTest < ActiveSupport::TestCase
6
6
 
7
7
  def helpers
8
- mock_action_view(assigns)
8
+ mock_action_view
9
9
  end
10
10
 
11
11
  def assigns
12
- {resource: Widget.first}
12
+ {category: Category.first}
13
13
  end
14
14
 
15
15
  def rendered_widget_box(*args)
16
16
  arbre {
17
- widget_box(:test, *args)
17
+ widget_box(:category, *args)
18
18
  }
19
19
  end
20
20
 
21
21
  test "renders correct widget box title" do
22
- assert_match /<header class="title">Edit Test/, rendered_widget_box
22
+ assert_match /<header class="title">Edit Category/, rendered_widget_box
23
23
  end
24
24
 
25
25
  test "renders correct widget box title with param" do
26
- assert_match /<header class="title">Widget Box/, rendered_widget_box(title: "Widget Box")
26
+ assert_match /<header class="title">Category Box/, rendered_widget_box(title: "Category Box")
27
27
  end
28
28
 
29
29
  end
data/test/test_helper.rb CHANGED
@@ -56,21 +56,23 @@ end
56
56
 
57
57
  module ActiveSupport
58
58
  class TestCase
59
- def arbre(assigns = {}, &block)
60
- Arbre::Context.new assigns, helpers, &block
59
+ def arbre(additional_assigns = {}, &block)
60
+ Arbre::Context.new assigns.merge(additional_assigns), helpers, &block
61
61
  end
62
- def mock_action_view(assigns = {})
62
+ def assigns
63
+ @arbre_assigns ||={}
64
+ end
65
+ def helpers
66
+ mock_action_view
67
+ end
68
+ def mock_action_view &block
63
69
  controller = ActionView::TestCase::TestController.new
64
70
  ActionView::Base.send :include, ActionView::Helpers
65
71
  ActionView::Base.send :include, ActionView::Helpers::UrlHelper
66
72
  ActionView::Base.send :include, AdditionalHelpers
67
73
  view = ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
68
- eigenklass = class << view
69
- self
70
- end
71
- assigns.each do |helper_name,value|
72
- eigenklass.send(:define_method, helper_name) { value }
73
- end
74
+ eigenklass = class << view; self; end
75
+ eigenklass.class_eval &block unless block.nil?
74
76
  view
75
77
  end
76
78
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- express_templates (0.9.7)
4
+ express_templates (0.10.0)
5
5
  activesupport (~> 4.2)
6
6
  arbre (~> 1.0)
7
7
  parslet (~> 1.6)
@@ -0,0 +1,26 @@
1
+ module ExpressTemplates
2
+ module Components
3
+ class All < Container
4
+
5
+ has_argument :id, "Name of the collection", as: :collection_name, type: :symbol
6
+
7
+ contains -> (&block) {
8
+ prepended
9
+ collection.each do |item|
10
+ assigns[member_name] = item
11
+ block.call(self) if block
12
+ end
13
+ appended
14
+ }
15
+
16
+ def member_name
17
+ config[:collection_name].to_s.singularize.to_sym
18
+ end
19
+
20
+ def collection
21
+ self.send(config[:collection_name])
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -120,7 +120,7 @@ module ExpressTemplates
120
120
  config[:collection]
121
121
  end
122
122
  else
123
- helpers.collection
123
+ self.send(collection_name)
124
124
  end
125
125
  end
126
126
 
@@ -165,19 +165,15 @@ module ExpressTemplates
165
165
  end
166
166
 
167
167
  def path_namespace
168
- resource_class_name = resource_class.to_s
168
+ resource_class_name = resource.class.to_s
169
169
  resource_class_name.match(/::/) ?
170
170
  resource_class_name.split("::").first.try(:underscore) : nil
171
171
  end
172
172
 
173
- # accepts boolean to indicate whether to use an ivar or not
174
- # and also may accept a resource on which we call to_param
175
- def resource_path(ivar_or_resource = nil)
173
+ def resource_path(object = nil)
176
174
  if config[:resource_path]
177
- if config[:resource_path].respond_to?(:call) &&
178
- ivar_or_resource.respond_to?(:to_param) &&
179
- ![true, false].include?(ivar_or_resource)
180
- config[:resource_path].call(ivar_or_resource)
175
+ if config[:resource_path].respond_to?(:call) && object.respond_to?(:to_param)
176
+ config[:resource_path].call(object)
181
177
  else
182
178
  config[:resource_path]
183
179
  end
@@ -186,12 +182,7 @@ module ExpressTemplates
186
182
  helpers.resource.to_param.present? # skip on nil resource
187
183
  helpers.resource_path
188
184
  else
189
- if ivar_or_resource.respond_to?(:to_param) &&
190
- ![true, false].include?(ivar_or_resource)
191
- helpers.instance_eval("#{resource_path_helper}('#{ivar_or_resource.to_param}')")
192
- else
193
- helpers.instance_eval("#{resource_path_helper}(#{ivar_or_resource ? '@' : ''}#{resource_name})")
194
- end
185
+ helpers.send(resource_path_helper, object)
195
186
  end
196
187
  end
197
188
  end
@@ -207,6 +198,11 @@ module ExpressTemplates
207
198
  def resource_attributes
208
199
  resource_class.columns
209
200
  end
201
+
202
+ def resource
203
+ assigns.try(:[], resource_name.to_sym)
204
+ # self.send(resource_name)
205
+ end
210
206
  end
211
207
  end
212
208
  end
@@ -11,7 +11,7 @@ module ExpressTemplates
11
11
  class #{type.classify} < FormComponent
12
12
  contains {
13
13
  label_tag(label_name, label_text)
14
- #{type}_field resource_var, field_name.to_sym, input_attributes
14
+ #{type}_field_tag field_name_attribute, field_value, field_helper_options
15
15
  }
16
16
  end
17
17
  RUBY
@@ -24,20 +24,20 @@ RUBY
24
24
  # class Email < FormComponent
25
25
  # contains {
26
26
  # label_tag label_name, label_text
27
- # email_field resource_var, field_name.to_sym, input_attributes
27
+ # email_field field_name_attribute, field_value, field_helper_options
28
28
  # }
29
29
  # end
30
30
 
31
31
  class Textarea < FormComponent
32
32
  contains {
33
33
  label_tag(label_name, label_text)
34
- text_area resource_var, field_name.to_sym, input_attributes
34
+ text_area_tag field_name_attribute, field_value, field_helper_options
35
35
  }
36
36
  end
37
37
 
38
38
  class Hidden < FormComponent
39
39
  contains {
40
- hidden_field resource_var, field_name.to_sym, input_attributes
40
+ hidden_field_tag field_name_attribute, field_value, field_helper_options
41
41
  }
42
42
  end
43
43
  end
@@ -7,7 +7,7 @@ module ExpressTemplates
7
7
 
8
8
  contains {
9
9
  label_tag(label_name, label_text) if label_before?
10
- check_box(resource_var, field_name.to_sym, field_options, checked_value, unchecked_value)
10
+ check_box(resource_name, field_name.to_sym, field_options, checked_value, unchecked_value)
11
11
  label_tag(label_name, label_text) if label_after?
12
12
  }
13
13
 
@@ -8,12 +8,16 @@ module ExpressTemplates
8
8
 
9
9
  has_option :method, 'The form method', default: 'POST', attribute: true #, options: ['PUT', 'POST', 'GET', 'DELETE']
10
10
  has_option :action, 'The form action containing the resource path or url.'
11
+ has_option :on_success, 'Pass a form value indicating where to go on a successful submission.'
12
+ has_option :on_failure, 'Pass a form value indicating where to go on a failed submission.'
11
13
 
12
14
  prepends -> {
13
15
  div(style: 'display:none') {
14
16
  add_child helpers.utf8_enforcer_tag
15
17
  add_child helpers.send(:method_tag, resource.persisted? ? :put : :post)
16
- helpers.send(:token_tag)
18
+ add_child helpers.send(:token_tag)
19
+ hidden_field_tag :on_success, config[:on_success] if config[:on_success]
20
+ hidden_field_tag :on_failure, config[:on_failure] if config[:on_failure]
17
21
  }
18
22
  }
19
23
 
@@ -28,7 +32,7 @@ module ExpressTemplates
28
32
  end
29
33
 
30
34
  def form_action
31
- config[:action] || (resource.try(:persisted?) ? resource_path(true) : collection_path)
35
+ config[:action] || (resource.try(:persisted?) ? resource_path(resource) : collection_path)
32
36
  end
33
37
 
34
38
  end
@@ -15,16 +15,16 @@ module ExpressTemplates
15
15
  has_option :wrapper_class, 'Override the class of the wrapping div of a form component', default: 'field-wrapper'
16
16
  has_option :label, 'Override the inferred label of a form component'
17
17
 
18
+ def resource
19
+ self.send(resource_name)
20
+ end
21
+
18
22
  # Lookup the resource_name from the parent ExpressForm.
19
23
  def resource_name
20
24
  raise "FormComponent must have a parent form" unless parent_form
21
25
  parent_form.config[:id].to_s
22
26
  end
23
27
 
24
- def resource_var
25
- resource_name.to_sym
26
- end
27
-
28
28
  def resource_class
29
29
  parent_form.resource_class
30
30
  end
@@ -45,12 +45,24 @@ module ExpressTemplates
45
45
  (config[:id] || (@args.first.is_a?(String) && @args.first)).to_s
46
46
  end
47
47
 
48
+ def field_value
49
+ resource.send(field_name)
50
+ end
51
+
48
52
  # Return the field name attribute. Currently handles only simple attributes
49
53
  # on the resource. Does not handle attributes for associated resources.
50
54
  def field_name_attribute
51
55
  "#{resource_name.singularize}[#{field_name}]"
52
56
  end
53
57
 
58
+ def field_id_attribute
59
+ "#{resource_name.singularize}_#{field_name}"
60
+ end
61
+
62
+ def field_helper_options
63
+ {id: field_id_attribute}.merge(input_attributes||nil)
64
+ end
65
+
54
66
  # Search the parent graph until we find an ExpressForm. Returns nil if none found.
55
67
  def parent_form
56
68
  @my_form ||= parent