low_node 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c438161e7c34024e9eed135ed7dfceec37c3e31fddcfe3241ea5186cd419b8a
4
- data.tar.gz: eb01c3f84b75aa25164ed95e61968d87325db5d620c17422db3fa9c6dc5cacc0
3
+ metadata.gz: ac55ce01d35523d45910268c02ce723e5baac95880791bc2ba776be62ec42896
4
+ data.tar.gz: 845688a5770bcb13e48c00e31b41fc9f6f77ea5f23e30b7fe7c6515675732b27
5
5
  SHA512:
6
- metadata.gz: b7e69cb3cb98d4783dc1169a5cdd25d7ffb0b9f59fc3c0784fe7b470f4d2e1f32b0ff6d17561c54fa6f213bfae6e5ebe9a94b98b7a2416e5bad669f7a1533c34
7
- data.tar.gz: 7f7da73beded4646362345d7a6d87263f2b410f6621f7615ab7566b9ed32587985def92efec1dffcc77ef9ea290e18eb5627276157b11846665874fec9d6cde1
6
+ metadata.gz: cae79c698dc5a1986ad920782fc2ca4fc445ed51e3eed3661dd5c501c3791a648c04d53264b01197404e3a53b682bf31f28985ddf4d206f7f202707c5b790ba5
7
+ data.tar.gz: f6eeca786d6dc6bab237b56ed8a260fe2a0efbd5ffbbb58bfa5e88949ee76524dff3c02460ba5535fe92584e3cccf77b4436e32733b981665ff0278d6318c2a6
data/lib/low_node.rb CHANGED
@@ -32,6 +32,15 @@ class LowNode
32
32
 
33
33
  def inherited(child)
34
34
  child.include LowType
35
+ increase_count
36
+ end
37
+
38
+ def count
39
+ @count ||= 0
40
+ end
41
+
42
+ def increase_count
43
+ @count = count + 1
35
44
  end
36
45
  end
37
46
  end
@@ -5,15 +5,19 @@ require_relative 'template'
5
5
  module Low
6
6
  module Templates
7
7
  module Renderer
8
- def render(event:)
8
+ def render(event: nil)
9
9
  nil
10
10
  end
11
11
 
12
- # When render() contains RBX/Antlers then LowLoad populates a template to render with instead.
12
+ # When render() contains RBX/Antlers then LowLoad builds a template to render with instead.
13
13
  def render_template(event:, parent_binding: nil, slot_node: nil, props: {})
14
14
  template = self.class.template
15
+
16
+ # NOTE: We currently set local variables on this local binding, not the receiver's binding.
17
+ # TODO: Should we create an "instance_binding" method on LowNode and use that binding instead?
15
18
  current_binding = binding
16
-
19
+ current_binding.local_variable_set(:event, event)
20
+
17
21
  # Pass in props from parent component as keyword arguments.
18
22
  template.params.each do |param|
19
23
  current_binding.local_variable_set(param, props[param]) if props[param]
@@ -31,25 +35,31 @@ module Low
31
35
  @template
32
36
  end
33
37
 
34
- def load_template(template:, params:, engine:, namespace:)
38
+ def build_template(template:, params:, engine:, namespace:)
35
39
  @template = Template.new(template:, params:, engine:, namespace:)
36
40
  end
37
41
 
38
42
  # TODO: Handle situation where node is tested in a unit test and args come in here; expose them to the template.
39
- def render(event:)
43
+ def render(event: nil)
40
44
  node = self.new(event:)
41
45
 
42
- # RBX/Antlers is rendered via template while valid Ruby is rendered as written.
43
- body = @template ? node.render_template(event:) : node.render(event:)
44
-
45
46
  # GOAL: Make return value configurable; ResponseEvent, Response, or body.
46
- response = Low::Factories::ResponseFactory.html(body:)
47
+ response = Low::Factories::ResponseFactory.html(body: body(node:, event:))
47
48
  Low::Events::ResponseEvent.new(response:)
48
49
  end
49
50
 
50
51
  def render_template(event:)
51
52
  self.new(event:).render_template(event:)
52
53
  end
54
+
55
+ private
56
+
57
+ def body(node:, event:)
58
+ return node.render_template(event:) if @template
59
+ return node.render(event:) if node.method(:render).arity > 0
60
+
61
+ node.render
62
+ end
53
63
  end
54
64
  end
55
65
  end
@@ -11,7 +11,7 @@ module Low
11
11
  @namespace = namespace
12
12
 
13
13
  @engine = engine
14
- @ast = engine.parse(template)
14
+ @ast = engine.ast(template)
15
15
  end
16
16
  end
17
17
  end
data/lib/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Low
4
4
  module Node
5
- VERSION = '0.2.2'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: low_node
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 4.0.6
111
+ rubygems_version: 4.0.10
112
112
  specification_version: 4
113
113
  summary: Flexible building blocks
114
114
  test_files: []