ilex 0.1.4 → 0.1.5
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/CHANGELOG.md +15 -0
- data/Gemfile.lock +1 -1
- data/lib/ilex/component.rb +12 -6
- data/lib/ilex/component_warden.rb +26 -6
- data/lib/ilex/context.rb +28 -7
- data/lib/ilex/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: fbd721cabba89d7f34b23841b6afcfd3d38b79bb35d947a620161e67e6f38cfd
|
4
|
+
data.tar.gz: 3aca8a08c6ae10f7918bcb239bbe103cd03073d18e1c30fc746a509c30c127f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb7d4800158d6b0dfb093ffd0f44abbb6009bc8bb8c706125e108fe89c5dbff0e16c50a1d8502b12c846416f8986a61d6b7a5fa9c5e52a5ca0f0600ae8df2816
|
7
|
+
data.tar.gz: af85c50eedefbbe3ce29849e07c80f38de08037277a57bc71477bd04d67326d8f8af7ae973fb18ddd93d0b13e11c15acf09d588389a46ad65b843f9808dc84a2
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,21 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
4
4
|
|
5
|
+
### [0.1.5](https://github.com/joshleblanc/cedar/compare/v0.1.4...v0.1.5) (2021-04-17)
|
6
|
+
|
7
|
+
|
8
|
+
### Features
|
9
|
+
|
10
|
+
* add helpers for rendering namespaced components ([3b0a5af](https://github.com/joshleblanc/cedar/commit/3b0a5af421e4b4c9a3b45b07b11647df65908552))
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* allow appending helpers with _component ([7097420](https://github.com/joshleblanc/cedar/commit/7097420d3529533910fd5174af175aae15c16aa0))
|
16
|
+
* appease intellisense with unused splat ([854c8a8](https://github.com/joshleblanc/cedar/commit/854c8a8c7f121d4f531bb5a6d56b487f29772bb8))
|
17
|
+
* component content wasn't rendering ([041efb2](https://github.com/joshleblanc/cedar/commit/041efb21cbc0760ac94d1fa0093dc57d5185d0d0))
|
18
|
+
* override arbre render method ([235763b](https://github.com/joshleblanc/cedar/commit/235763b5820fbcbf7faaee934e14c90f381b128a))
|
19
|
+
|
5
20
|
### [0.1.4](https://github.com/joshleblanc/cedar/compare/v0.1.3...v0.1.4) (2021-04-16)
|
6
21
|
|
7
22
|
|
data/Gemfile.lock
CHANGED
data/lib/ilex/component.rb
CHANGED
@@ -19,19 +19,25 @@ module Ilex
|
|
19
19
|
module Component
|
20
20
|
include Arbre::HTML
|
21
21
|
|
22
|
-
def render(&blk)
|
22
|
+
def render(*args, &blk)
|
23
23
|
define_method :call do
|
24
24
|
ctx = Context.new(self)
|
25
25
|
ctx.instance_eval(&blk).to_s
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def find_component(name)
|
30
|
-
if
|
31
|
-
|
29
|
+
def find_component(name, base_module = nil)
|
30
|
+
target = if base_module
|
31
|
+
base_module
|
32
32
|
else
|
33
|
-
|
34
|
-
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
if target.const_defined?(name)
|
37
|
+
target.const_get(name)
|
38
|
+
else
|
39
|
+
if target.superclass.respond_to?(:find_component)
|
40
|
+
target.superclass.find_component(name)
|
35
41
|
else
|
36
42
|
adjusted_name = name.chomp("Component").underscore
|
37
43
|
raise(NameError, "undefined local variable or method `#{adjusted_name}` for #{self}")
|
@@ -10,22 +10,28 @@ module Ilex
|
|
10
10
|
class ComponentWarden
|
11
11
|
def initialize(component, string)
|
12
12
|
@component = component
|
13
|
-
@
|
13
|
+
@input = string.to_s
|
14
14
|
|
15
|
-
@collection = @
|
16
|
-
@
|
15
|
+
@collection = @input.end_with? "_collection"
|
16
|
+
@nested = @input.include? "__"
|
17
|
+
|
18
|
+
process_input!(@input)
|
17
19
|
end
|
18
20
|
|
19
21
|
def collection?
|
20
22
|
@collection
|
21
23
|
end
|
22
24
|
|
25
|
+
def nested?
|
26
|
+
@nested
|
27
|
+
end
|
28
|
+
|
23
29
|
def component_name
|
24
30
|
"#{@input}_component".camelize
|
25
31
|
end
|
26
32
|
|
27
33
|
def component_class
|
28
|
-
@component_class ||= @component.class.find_component(component_name)
|
34
|
+
@component_class ||= @component.class.find_component(component_name, @base_module)
|
29
35
|
end
|
30
36
|
|
31
37
|
def exists?
|
@@ -36,9 +42,23 @@ module Ilex
|
|
36
42
|
return nil unless exists?
|
37
43
|
|
38
44
|
if collection?
|
39
|
-
component_class.with_collection(*args
|
45
|
+
component_class.with_collection(*args)
|
40
46
|
else
|
41
|
-
component_class.new(*args
|
47
|
+
component_class.new(*args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def process_input!(input)
|
54
|
+
@input.chomp! "_collection"
|
55
|
+
@input.chomp! "_component"
|
56
|
+
|
57
|
+
if nested?
|
58
|
+
parts = @input.split("__")
|
59
|
+
@input = parts.pop
|
60
|
+
|
61
|
+
@base_module = parts.map(&:camelize).join("::").constantize
|
42
62
|
end
|
43
63
|
end
|
44
64
|
end
|
data/lib/ilex/context.rb
CHANGED
@@ -7,32 +7,53 @@ module Ilex
|
|
7
7
|
# tags
|
8
8
|
class Context < Arbre::Context
|
9
9
|
|
10
|
-
def initialize(component)
|
11
|
-
super({}, component)
|
12
|
-
|
10
|
+
def initialize(component, &blk)
|
13
11
|
@component = component
|
14
|
-
|
12
|
+
|
15
13
|
|
16
14
|
# Copy all of the instance variables from the component to the context,
|
17
15
|
# so we have access to them when rendering
|
18
16
|
@component.instance_variables.each do |iv|
|
19
17
|
instance_variable_set(iv, @component.instance_variable_get(iv))
|
20
18
|
end
|
19
|
+
|
20
|
+
super({}, component, &blk)
|
21
21
|
end
|
22
22
|
|
23
23
|
def content
|
24
24
|
@component.send :content
|
25
25
|
end
|
26
26
|
|
27
|
+
def component_wardens
|
28
|
+
@component_wardens ||= ComponentWardens.new(@component)
|
29
|
+
end
|
30
|
+
|
31
|
+
# This is overriding arbre::rails::rendering
|
32
|
+
# It performs the same actions, but returns html_safe on a passed block
|
33
|
+
#
|
34
|
+
# Not 100% sure this is needed, but view_components won't render their
|
35
|
+
# contents without it, when rendered in an arbre tree
|
36
|
+
def render(*args)
|
37
|
+
rendered = helpers.render(*args) do
|
38
|
+
yield.html_safe if block_given?
|
39
|
+
end
|
40
|
+
case rendered
|
41
|
+
when Arbre::Context
|
42
|
+
current_arbre_element.add_child rendered
|
43
|
+
else
|
44
|
+
text_node rendered
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
27
48
|
def respond_to_missing?(method, include_all)
|
28
|
-
@component.respond_to?(method) ||
|
49
|
+
@component.respond_to?(method) || component_wardens[method].exists? || super
|
29
50
|
end
|
30
51
|
|
31
52
|
def method_missing(method, *args, &content_block)
|
32
53
|
if @component.respond_to?(method)
|
33
54
|
@component.send(method, *args, &content_block)
|
34
|
-
elsif
|
35
|
-
render
|
55
|
+
elsif component_wardens[method].exists?
|
56
|
+
render component_wardens[method].new(*args), &content_block
|
36
57
|
else
|
37
58
|
super
|
38
59
|
end
|
data/lib/ilex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ilex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua LeBlanc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: arbre
|