Class: Hokusai::Node
- Inherits:
-
Object
- Object
- Hokusai::Node
- Extended by:
- Forwardable
- Defined in:
- ui/src/hokusai/node.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#portal ⇒ Object
readonly
Returns the value of attribute portal.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
- .parse(template, name = "root", parent = nil) ⇒ Object
- .provide(node, key, value) ⇒ Object
- .provides ⇒ Object
Instance Method Summary collapse
- #add_props_from_block(parent, context: nil) ⇒ Object
- #add_styles(klass) ⇒ Object
- #destroy ⇒ Object
- #emit(name, **args) ⇒ Object
-
#initialize(ast, portal = nil) ⇒ Node
constructor
A new instance of Node.
- #mount(klass) ⇒ Object
Constructor Details
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
11 12 13 |
# File 'ui/src/hokusai/node.rb', line 11 def ast @ast end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
11 12 13 |
# File 'ui/src/hokusai/node.rb', line 11 def @meta end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
11 12 13 |
# File 'ui/src/hokusai/node.rb', line 11 def node @node end |
#portal ⇒ Object (readonly)
Returns the value of attribute portal.
11 12 13 |
# File 'ui/src/hokusai/node.rb', line 11 def portal @portal end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
11 12 13 |
# File 'ui/src/hokusai/node.rb', line 11 def uuid @uuid end |
Class Method Details
.parse(template, name = "root", parent = nil) ⇒ Object
24 25 26 27 28 |
# File 'ui/src/hokusai/node.rb', line 24 def self.parse(template, name = "root", parent = nil) ast = Ast.parse(template, name) new(ast, parent) end |
.provide(node, key, value) ⇒ Object
19 20 21 22 |
# File 'ui/src/hokusai/node.rb', line 19 def self.provide(node, key, value) provides[node.uuid] ||= {} provides[node.uuid][key] = value end |
.provides ⇒ Object
15 16 17 |
# File 'ui/src/hokusai/node.rb', line 15 def self.provides @provides ||= {} end |
Instance Method Details
#add_props_from_block(parent, context: nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'ui/src/hokusai/node.rb', line 73 def add_props_from_block(parent, context: nil) if local_portal = portal if block = parent local_portal.ast.props.each do |_, prop| method = prop.value.method case prop.computed? when true if prop.value.args.size > 0 && context value = context.send_target(block, prop.value) elsif context&.table&.[](method) value = context.table[method] else value = block.instance_eval(method) end else value = method end .set_prop(prop.name.to_sym, value) end end end end |
#add_styles(klass) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'ui/src/hokusai/node.rb', line 59 def add_styles(klass) return if portal.nil? portal.ast.style_list.each do |style_name| style = klass.styles_get[style_name] raise Hokusai::Error.new("Style #{style_name} doesn't exist in the styles for this block #{klass} - #{klass.styles_get.keys}") if style.nil? style.each do |key, value| .set_prop(key.to_sym, value) end end end |
#destroy ⇒ Object
41 42 43 44 45 46 47 |
# File 'ui/src/hokusai/node.rb', line 41 def destroy # meta.children?&.each do |child| # child.node.destroy # end # # ast.destroy end |
#emit(name, **args) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'ui/src/hokusai/node.rb', line 49 def emit(name, **args) if node = portal if event = node.event(name) .publisher.notify(event.value.name, **args) else raise Hokusai::Error.new("Invocation failed: @#{name} doesn't exist on #{node.type}") end end end |
#mount(klass) ⇒ Object
37 38 39 |
# File 'ui/src/hokusai/node.rb', line 37 def mount(klass) NodeMounter.new(self, klass).mount end |