effective_resources 0.7.12 → 0.7.13

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: 9a6b2c73dd66b692135a690dc812d2dba68b4597
4
- data.tar.gz: 16f8e2a01244f8b050a803199aec7133babfa717
3
+ metadata.gz: 287350db2bd99d6ee44fb82d7a31ff7a138b13d6
4
+ data.tar.gz: b624b6db3fdb2ae627fc201a36c53ec615f10bf3
5
5
  SHA512:
6
- metadata.gz: bb8cf1b6bf38f2e8bb5648ff8e7853236925f362631bfcea009839d5e2a8f32e849b1040a514fac477c08190791edbfb1db1aed53e317045927836905b4b1de1
7
- data.tar.gz: f12eb117c2ed212cae9a7335c57d92100c1828dcee1f736e3fe0eb8a5151645b028d7240c84721588a0a061bdd9adc90cb1a25458d2304f4a6c81bc394f737a6
6
+ metadata.gz: 8083ed649eee3b427b455487e21485ec01c8e46f242404eb6e551b470a165ed9d2793ec9f07ad1fa4b6eefbabf15d26583ea8559adcf60e2512ad78c08c0032c
7
+ data.tar.gz: fe26139eb7170c782064ab0c82d0dd0ad56114657f40972ef2e0bb33816a8b0111196983a1050483b01fb0da7638179d4345b6719c91ec08449aee712dc61f78
data/README.md CHANGED
@@ -158,6 +158,23 @@ Call `simple_form_save(f)` like follows:
158
158
 
159
159
  to render just the `Save` button, with appropriate data-disable, title, etc.
160
160
 
161
+ ### Effective Form with
162
+
163
+ ```ruby
164
+
165
+ = effective_form_with(model: user, url: user_settings_path) do |f|
166
+ = effective_submit(f)
167
+ = effective_save(f)
168
+
169
+ = effective_save(f) do
170
+ = f.save 'Save'
171
+ = f.save 'Another'
172
+
173
+ = effective_save(f, 'Save It')
174
+
175
+ = effective_submit(f) do
176
+ = f.save 'Will be appended'
177
+
161
178
  ## License
162
179
 
163
180
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
@@ -23,18 +23,28 @@ module EffectiveResourcesHelper
23
23
  end
24
24
  end
25
25
 
26
+ # Group by class and render
27
+ buttons = actions.group_by { |_, opts| opts[:class] }.flat_map do |_, btns|
28
+ btns.map { |name, opts| form.save(name, opts) }
29
+ end.join.html_safe
30
+
31
+ effective_save(form) do
32
+ (block_given? ? capture(&block) : ''.html_safe) + buttons
33
+ end
34
+
35
+ end
36
+
37
+ def effective_save(form, label = 'Save', &block) # effective_bootstrap
26
38
  wrapper = (form.layout == :horizontal) ? { class: 'form-group form-actions row' } : { class: 'form-group form-actions' }
27
39
 
28
40
  content_tag(:div, wrapper) do
29
- buttons = actions.group_by { |_, opts| opts[:class] }.flat_map do |_, grouped|
30
- grouped.map { |name, opts| form.save(name, opts) } + ['']
31
- end
32
-
33
- if block_given?
34
- buttons = [capture(&block), ''] + buttons
35
- end
41
+ icon('spinner') + (block_given? ? capture(&block) : form.save(label, class: 'btn btn-primary'))
42
+ end
43
+ end
36
44
 
37
- ([icon('spinner'), '', ''] + buttons).join(' ').html_safe
45
+ def effective_save_button(form, label = 'Save', &block)
46
+ content_tag(:div, class: 'form-actions') do
47
+ icon('spinner') + (block_given? ? capture(&block) : form.save(label, class: 'btn btn-primary'))
38
48
  end
39
49
  end
40
50
 
@@ -8,7 +8,7 @@ module Effective
8
8
  @_routes ||= (
9
9
  matches = [[namespace, plural_name].compact.join('/'), [namespace, name].compact.join('/')]
10
10
 
11
- Rails.application.routes.routes.select do |route|
11
+ routes_engine.routes.routes.select do |route|
12
12
  matches.any? { |match| match == route.defaults[:controller] }
13
13
  end.inject({}) do |h, route|
14
14
  h[route.defaults[:action].to_sym] = route; h
@@ -16,6 +16,16 @@ module Effective
16
16
  )
17
17
  end
18
18
 
19
+ # Effective::Resource.new('effective/order', namespace: :admin)
20
+ def routes_engine
21
+ case class_name
22
+ when 'Effective::Order'
23
+ EffectiveOrders::Engine
24
+ else
25
+ Rails.application
26
+ end
27
+ end
28
+
19
29
  # Effective::Resource.new('admin/posts').action_path_helper(:edit) => 'edit_admin_posts_path'
20
30
  # This will return empty for create, update and destroy
21
31
  def action_path_helper(action)
@@ -41,7 +41,7 @@ module Effective
41
41
  klass = class_name.safe_constantize
42
42
 
43
43
  if klass.present?
44
- @namespaces = names[0...index]
44
+ @namespaces ||= names[0...index]
45
45
  @model_klass = klass
46
46
  return klass
47
47
  end
@@ -24,7 +24,7 @@ module Effective
24
24
  end
25
25
 
26
26
  def namespaced_class_name # 'Admin::Effective::Post'
27
- (Array(namespaces).map { |name| name.classify } + [class_name]) * '::'
27
+ (Array(namespaces).map { |name| name.to_s.classify } + [class_name]) * '::'
28
28
  end
29
29
 
30
30
  def namespace # 'admin/things'
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.7.12'.freeze
2
+ VERSION = '0.7.13'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.12
4
+ version: 0.7.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-07 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.0
19
+ version: 4.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.0
26
+ version: 4.0.0
27
27
  description: Make any controller an effective resource controller.
28
28
  email:
29
29
  - info@codeandeffect.com