view_delegates 0.1.0 → 0.2.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 -3
- data/lib/view_delegates/poros/view_delegate.rb +29 -5
- data/lib/view_delegates/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: 5ae035f744ed2500538cec3961ed5b0cadc1ae4f47c3b006e165490d2e951ef0
|
4
|
+
data.tar.gz: 23a68255593a6609f5d1bba32a1765026806392601271ffe5897a9c92e63fa01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f15b7a9992a52d920af7d4e24f990fdda381438d1d89bc5eba3975b8d0d34467e679a2630935cfafdb136eb73234e99663e960fd75484697d23632ce252bb42
|
7
|
+
data.tar.gz: 8797505d4f520d790f03c9070db41c306ebe426d5f3a3140de5b725e4e427b878eec0f7558b9b6dd0168fe807a08f4f7a38f8d014d2061d197c226a8802cf766
|
data/README.md
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
# ViewDelegates
|
3
3
|
ViewDelegates makes easy to write reusable view components with decoupled functionality from
|
4
4
|
the active record models
|
5
|
-
|
5
|
+
# Requirements
|
6
|
+
Only tested with ruby 2.5 and rails 5.1.6, should work with any rails version over 5.0
|
7
|
+
but i don't know about the ruby version. Could'nt made travis work
|
8
|
+
#Usage
|
6
9
|
Create a ruby class implementing this gem base class
|
7
10
|
ViewDelegates::ViewDelegate. I recommend to place the view delegates
|
8
11
|
under a folder on your applications app named '/view_delegates'. Then
|
@@ -44,8 +47,6 @@ To know where your class will look for your view, open your console and call .vi
|
|
44
47
|
|
45
48
|
```
|
46
49
|
|
47
|
-
## Usage
|
48
|
-
How to use my plugin.
|
49
50
|
|
50
51
|
## Installation
|
51
52
|
Add this line to your application's Gemfile:
|
@@ -19,6 +19,9 @@ module ViewDelegates
|
|
19
19
|
@@ar_models.each do |t|
|
20
20
|
send("#{t}=", view_data[t]) if view_data[t]
|
21
21
|
end
|
22
|
+
@@properties.each do |t|
|
23
|
+
send("#{t}=", view_data[t]) if view_data[t]
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
# Renders as a string the view passed as params
|
@@ -40,6 +43,20 @@ module ViewDelegates
|
|
40
43
|
locals: locals)
|
41
44
|
end
|
42
45
|
class << self
|
46
|
+
|
47
|
+
def new *args
|
48
|
+
if defined? @@polymorph_function
|
49
|
+
command = (super(*args))
|
50
|
+
klazz = command.instance_eval(&@@polymorph_function)
|
51
|
+
if klazz == self
|
52
|
+
super(*args)
|
53
|
+
else
|
54
|
+
klazz.new(*args)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
super
|
58
|
+
end
|
59
|
+
end
|
43
60
|
def cache(option, size: 50)
|
44
61
|
if option
|
45
62
|
render_method = instance_method :render
|
@@ -64,17 +81,24 @@ module ViewDelegates
|
|
64
81
|
|
65
82
|
# Marks a method as a view local
|
66
83
|
# @param [Symbol] method
|
67
|
-
def view_local(
|
68
|
-
|
84
|
+
def view_local(*methods)
|
85
|
+
methods.each do |method|
|
86
|
+
@@view_locals << method
|
87
|
+
end
|
69
88
|
end
|
70
89
|
|
71
90
|
# View properties
|
72
91
|
# @param [Symbol] method
|
73
|
-
def property(
|
74
|
-
|
75
|
-
|
92
|
+
def property(*methods)
|
93
|
+
methods.each do |method|
|
94
|
+
@@properties << method
|
95
|
+
attr_accessor method
|
96
|
+
end
|
76
97
|
end
|
77
98
|
|
99
|
+
def polymorph &block
|
100
|
+
@@polymorph_function = block
|
101
|
+
end
|
78
102
|
# The models this delegate will use
|
79
103
|
# @param [method] method The variable name this model will use
|
80
104
|
# @param [Array] properties The model properties to extract
|