erb_component 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/erb_component/erb_component.rb +39 -12
- data/lib/erb_component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10aa5ea6bca7d3b177903d1aa535be7e306d7a0e939ca05fcb021ccbfff9d248
|
4
|
+
data.tar.gz: e0fcaeed8b0aae415ed31fc13d1911ed1fa0bdd5843218320adb9dbf5874046c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fda9e18ee25ee98d10641cb1f67e345a0cfffd1e10a2bef99b16b5b973009db8f13a98af0baf373c1e887116c41cb53a37fbc4caf2cad38a50accb694d87bc86
|
7
|
+
data.tar.gz: 263523df144487e5f25f6f03d48c27852f20ba787a650f23b5054e355cb322dddf762f306f4870dea21dc9dd7c201a1693ec2da5f38fbfdcd56266328062b028
|
@@ -7,22 +7,51 @@ class ErbComponent
|
|
7
7
|
|
8
8
|
attr_reader :req, :parent
|
9
9
|
|
10
|
-
def initialize(req)
|
10
|
+
def initialize(req, opts = {})
|
11
11
|
@req = req
|
12
|
-
|
12
|
+
begin
|
13
|
+
@parent = self.class.superclass == ErbComponent ? nil : self.class.superclass.new(req)
|
14
|
+
if @parent && !(parent.template['{{VIEW}}'] || parent.template['{{view}}'])
|
15
|
+
@parent = parent.parent
|
16
|
+
end
|
17
|
+
rescue ArgumentError
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
def path
|
16
22
|
@req.path
|
17
23
|
end
|
18
24
|
|
25
|
+
def path_hash
|
26
|
+
@path_hash ||= begin
|
27
|
+
split = path.split('/')
|
28
|
+
split.shift
|
29
|
+
|
30
|
+
res = {}
|
31
|
+
split.size.times do |i|
|
32
|
+
if split[i].to_i.to_s == split[i]
|
33
|
+
res[split[i - 1].singularize + "_id"] = split[i]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
res.with_indifferent_access
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
19
40
|
def params
|
20
|
-
@
|
41
|
+
@params ||= begin
|
42
|
+
res = @req.params
|
43
|
+
res.merge!(JSON.parse(req.body.read)) if req.post? || req.put? || req.patch?
|
44
|
+
res.with_indifferent_access
|
45
|
+
end
|
21
46
|
end
|
22
47
|
|
23
48
|
def render
|
24
49
|
str = ERB.new(template).result(binding)
|
25
|
-
|
50
|
+
if parent
|
51
|
+
parent.render.gsub("{{VIEW}}", str).gsub("{{view}}", str)
|
52
|
+
else
|
53
|
+
str
|
54
|
+
end
|
26
55
|
end
|
27
56
|
|
28
57
|
def self.render(opts = {})
|
@@ -41,9 +70,7 @@ class ErbComponent
|
|
41
70
|
end
|
42
71
|
|
43
72
|
def template
|
44
|
-
if template_file_path
|
45
|
-
File.read template_file_path
|
46
|
-
end
|
73
|
+
return File.read(template_file_path) if template_file_path
|
47
74
|
fail "not found: #{template_file_path}"
|
48
75
|
end
|
49
76
|
|
@@ -51,11 +78,11 @@ class ErbComponent
|
|
51
78
|
m = m.to_s
|
52
79
|
str = Kernel.const_defined?("#{self.class}::#{m}") ? "#{self.class}::#{m}" : m
|
53
80
|
clazz = Kernel.const_get(str)
|
54
|
-
|
55
|
-
|
56
|
-
|
81
|
+
if args.size > 0
|
82
|
+
component = clazz.new(req, *args)
|
83
|
+
else
|
84
|
+
component = clazz.new(req)
|
85
|
+
end
|
57
86
|
component.render
|
58
|
-
rescue
|
59
|
-
super
|
60
87
|
end
|
61
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erb_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur Karganyan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: React-style front-end components but for ERB?
|
14
14
|
email:
|