activeadmin_decorator 0.2.0 → 0.3.0
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 +4 -0
- data/lib/activeadmin/decorator.rb +14 -2
- data/lib/activeadmin_decorator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aa3d5c6a44294b75d34898242260a457d281767f805e171b34f96fa0c22a441
|
4
|
+
data.tar.gz: ed311ac3f20aebac9af7e5a10e4e0ac576c2da717edaa0df8e061bedd56ab0b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d39774cfbfafec1065209ce73b89ba98caeb2221385f70f4ecf1628a6466a225834b03bc5fc83a4ee38d45098b15710953cab11b0342de38204b6c5d4d6053d9
|
7
|
+
data.tar.gz: 9a06ba36f44a9476eed1e7a4241d3d5eba2fd4ec4ff06632a3f5ca6949ad7b43117d795171b5afaa86693a609038ad085dc7e78bc0b17641b7418f0a408f984b
|
data/README.md
CHANGED
@@ -39,6 +39,9 @@ end
|
|
39
39
|
Each decorated association will be available as a method on the decorator,
|
40
40
|
you can still access the original association with `model.association_name`.
|
41
41
|
|
42
|
+
The association decorator class name will be auto-detected from the relation result and current decorator name if not given.
|
43
|
+
Example for `:comments` association on `Decorators::UserDecorator` it will be `Decorators::CommentDecorator`.
|
44
|
+
|
42
45
|
### ArbreDecorator
|
43
46
|
|
44
47
|
With `ActiveAdmin::ArbreDecorator` you can keep your show/index blocks in AA clean and use Arbre DSL in decorator:
|
@@ -52,6 +55,7 @@ class UserDecorator < ActiveAdmin::ArbreDecorator
|
|
52
55
|
end
|
53
56
|
end
|
54
57
|
```
|
58
|
+
This is done by using including `Arbre::Element::BuilderMethods` and new `arbre_context`.
|
55
59
|
|
56
60
|
Also included: `ActionView::Helpers` and `Rails.application.routes.url_helpers`,
|
57
61
|
so you can:
|
@@ -16,7 +16,7 @@ module ActiveAdmin
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# use in decorator to decorate association
|
19
|
-
def decorates_association(association, relation: association, with:
|
19
|
+
def decorates_association(association, relation: association, with: nil)
|
20
20
|
define_method(association) do
|
21
21
|
associated =
|
22
22
|
case relation
|
@@ -24,10 +24,13 @@ module ActiveAdmin
|
|
24
24
|
when Proc then relation.call(model)
|
25
25
|
else raise ArgumentError, "relation must be a Symbol or Proc"
|
26
26
|
end
|
27
|
-
with = with.constantize if with.is_a?(String)
|
28
27
|
if associated.is_a?(ActiveRecord::Relation)
|
28
|
+
with ||= decorator_class_name_for(associated.klass)
|
29
|
+
with = with.constantize if with.is_a?(String)
|
29
30
|
associated = associated.map { |item| with.new(item) }
|
30
31
|
else
|
32
|
+
with ||= decorator_class_name_for(associated.class)
|
33
|
+
with = with.constantize if with.is_a?(String)
|
31
34
|
associated = with.new(associated)
|
32
35
|
end
|
33
36
|
associated
|
@@ -38,5 +41,14 @@ module ActiveAdmin
|
|
38
41
|
def model = __getobj__
|
39
42
|
|
40
43
|
def nil? = model.nil?
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# autodetect decorator class name for association
|
48
|
+
def decorator_class_name_for(klass)
|
49
|
+
@prefix ||= self.class.name.split('::')[0...-1].freeze
|
50
|
+
@suffix ||= self.class.name.split('::')[-1].sub(/^#{model.class.name}/, '').freeze
|
51
|
+
[*@prefix, klass].join('::').concat(@suffix)
|
52
|
+
end
|
41
53
|
end
|
42
54
|
end
|