low_node 0.2.2 → 0.3.1

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: 75eb52cd5e606c086a9672c8675710979878a5b240428a619b3ab454ec8534f0
4
+ data.tar.gz: 476ce5d261f9034066b21223a31be47d137cf64d6ec3921605bcf5060b594ea4
5
5
  SHA512:
6
- metadata.gz: b7e69cb3cb98d4783dc1169a5cdd25d7ffb0b9f59fc3c0784fe7b470f4d2e1f32b0ff6d17561c54fa6f213bfae6e5ebe9a94b98b7a2416e5bad669f7a1533c34
7
- data.tar.gz: 7f7da73beded4646362345d7a6d87263f2b410f6621f7615ab7566b9ed32587985def92efec1dffcc77ef9ea290e18eb5627276157b11846665874fec9d6cde1
6
+ metadata.gz: 9712d807495ee5299d83fc6fcd17355d009978ba9c6bbc8709da9098decb858ff4d52e035505213bc28c745561537a161b24412d6175552618cd0c8ef1f96d4e
7
+ data.tar.gz: 889af9b4f7caca1f61a559743f3a2ba2792d177320a37d9d9a2a8258af5713d4ca088cdf07991e8eb11415bb85defa2a839fa438450f331be4b33bd85fbb0c75
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,24 +35,26 @@ 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
- Low::Events::ResponseEvent.new(response:)
47
+ response = Low::Factories::ResponseFactory.html(body: response_body(node:, event:))
48
+ Low::Events::ResponseEvent.new(response:).tap { it.branch }
48
49
  end
49
50
 
50
- def render_template(event:)
51
- self.new(event:).render_template(event:)
51
+ private
52
+
53
+ def response_body(node:, event:)
54
+ return node.render_template(event:) if @template
55
+ return node.render(event:) if node.method(:render).arity > 0
56
+
57
+ node.render
52
58
  end
53
59
  end
54
60
  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.1'
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.1
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: []