erb_component 0.1.7 → 0.1.8

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
  SHA256:
3
- metadata.gz: 10aa5ea6bca7d3b177903d1aa535be7e306d7a0e939ca05fcb021ccbfff9d248
4
- data.tar.gz: e0fcaeed8b0aae415ed31fc13d1911ed1fa0bdd5843218320adb9dbf5874046c
3
+ metadata.gz: d4becb713a71333702f1e9666fca7490a928b957269cf5129fd78e6670d73edd
4
+ data.tar.gz: e74b2838a3144406b64f07807d40da29bd52d1a833bcec7e9525c028941fa298
5
5
  SHA512:
6
- metadata.gz: fda9e18ee25ee98d10641cb1f67e345a0cfffd1e10a2bef99b16b5b973009db8f13a98af0baf373c1e887116c41cb53a37fbc4caf2cad38a50accb694d87bc86
7
- data.tar.gz: 263523df144487e5f25f6f03d48c27852f20ba787a650f23b5054e355cb322dddf762f306f4870dea21dc9dd7c201a1693ec2da5f38fbfdcd56266328062b028
6
+ metadata.gz: 294198283f9d87a012b24fb7ae8e5d62ee1769180478170547daeed9f07069c76160801076c5b8247d20333aac57c2fb277a1a9fc9858e9c57691a8e1dc98dce
7
+ data.tar.gz: 18fec35a95417996d5b9e3590186acd3540e69c2ddedee49409d17ee1cdd5c842cce39bec3d487bba7011bf9b178686e988f0bb249e15136ad13c1c5a1c70c19
@@ -9,6 +9,7 @@ class ErbComponent
9
9
 
10
10
  def initialize(req, opts = {})
11
11
  @req = req
12
+ @template = opts[:template]
12
13
  begin
13
14
  @parent = self.class.superclass == ErbComponent ? nil : self.class.superclass.new(req)
14
15
  if @parent && !(parent.template['{{VIEW}}'] || parent.template['{{view}}'])
@@ -41,6 +42,7 @@ class ErbComponent
41
42
  @params ||= begin
42
43
  res = @req.params
43
44
  res.merge!(JSON.parse(req.body.read)) if req.post? || req.put? || req.patch?
45
+ res.merge!(path_hash)
44
46
  res.with_indifferent_access
45
47
  end
46
48
  end
@@ -58,6 +60,10 @@ class ErbComponent
58
60
  new(opts).render
59
61
  end
60
62
 
63
+ def self.call(req, opts = {})
64
+ new(req, opts).render
65
+ end
66
+
61
67
  def template_file_path
62
68
  file_name = "#{self.class.name.underscore}.erb"
63
69
  if File.exists? "components/#{file_name}"
@@ -70,11 +76,13 @@ class ErbComponent
70
76
  end
71
77
 
72
78
  def template
79
+ return @template if @template
73
80
  return File.read(template_file_path) if template_file_path
74
81
  fail "not found: #{template_file_path}"
75
82
  end
76
83
 
77
84
  def method_missing(m, *args, &block)
85
+ return super unless m.to_s[0].upcase == m.to_s[0]
78
86
  m = m.to_s
79
87
  str = Kernel.const_defined?("#{self.class}::#{m}") ? "#{self.class}::#{m}" : m
80
88
  clazz = Kernel.const_get(str)
@@ -1,3 +1,3 @@
1
1
  class ErbComponent
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  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.7
4
+ version: 0.1.8
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-28 00:00:00.000000000 Z
11
+ date: 2019-12-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: React-style front-end components but for ERB?
14
14
  email: