erb_component 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee2b998e877e3c08de6cb4cbda5260c0c31d880ec3dd16ac384e15f6748bfecb
4
- data.tar.gz: d7ddde77ae4ed69ac45288207562d2e7c1138e8f88e61e30e561ee964b6872b7
3
+ metadata.gz: 047edea23f0069c76f0c151b62a2316678d3dd6930bba6d451f29fed1ff9624e
4
+ data.tar.gz: 2a33aca807d6852f69df70f0430e80b848968e91d0eced171826a1a99bfacdbe
5
5
  SHA512:
6
- metadata.gz: cfc2d6b77717d164d6acb71c6080b191fe2e1e5c7beb6b7c338aed4f2b69a23eae96720a55a1e1aab7cc442a723716807c23bd81d8f2c6690130ac134ce1d1e9
7
- data.tar.gz: 735687627b740aeb6f405daa7e6b723ba9ebd0778c23f9b5f1b6034fd8cfc3f96602bba69dea446fb8a6149930ecef494a3a8aa6ec2f30a0fb1ea26f1ad394d9
6
+ metadata.gz: e943437c69d2b2c2f85cd2b162018905401e7fddf64849449f1f5a18eefc62529194a367f263e25e4fb112509a4538e66673f13bf00f5f9d4fa13f16cf960633
7
+ data.tar.gz: 9f02bad3f0abe2e5afb1e345040d9dc1d07b6883d4080eb7dd250a570eda4036af7b3b09df66699b01716e338618dd7bb911b0162c0395c07adfe09acedbf55a
@@ -2,19 +2,27 @@ require "erb_component/version"
2
2
  require 'erb'
3
3
 
4
4
  class ErbComponent
5
- class Error < StandardError; end
5
+ class Error < StandardError;
6
+ end
6
7
 
7
- attr_reader :params, :path, :parent
8
+ attr_reader :req, :parent
8
9
 
9
- def initialize(opts = {})
10
- @params = opts[:params] || {}
11
- @path = opts[:path]
10
+ def initialize(req)
11
+ @req = req
12
12
  @parent = self.class.superclass == ErbComponent ? nil : self.class.superclass.new(opts)
13
13
  end
14
14
 
15
+ def path
16
+ @req.path
17
+ end
18
+
19
+ def params
20
+ @req.params
21
+ end
22
+
15
23
  def render
16
24
  str = ERB.new(template).result(binding)
17
- parent ? parent.render.gsub("{{VIEW}}", str) : str
25
+ parent ? parent.render.gsub("{{VIEW}}", str).gsub("{{view}}", str) : str
18
26
  end
19
27
 
20
28
  def self.render(opts = {})
@@ -31,12 +39,9 @@ class ErbComponent
31
39
  end
32
40
 
33
41
  def method_missing(m, *args, &block)
34
- possible_const = "#{self.class}::#{m}"
35
- clazz = if Kernel.const_defined?(possible_const)
36
- Kernel.const_get possible_const
37
- else
38
- Kernel.const_get m.to_s
39
- end
42
+ m = m.to_s
43
+ str = Kernel.const_defined?("#{self.class}::#{m}") ? "#{self.class}::#{m}" : m
44
+ clazz = Kernel.const_get(str)
40
45
  opts = {path: path, params: params}
41
46
  opts.merge!(args[0]) if args.size > 0
42
47
  component = clazz.new(opts)
@@ -1,3 +1,3 @@
1
1
  class ErbComponent
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
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.2
4
+ version: 0.1.3
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-18 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: React-style front-end components but for ERB?
14
14
  email: