Class: GenerativeUI::Renderer
- Inherits:
-
Object
- Object
- GenerativeUI::Renderer
show all
- Defined in:
- lib/generative_ui/renderer.rb
Instance Method Summary
collapse
Constructor Details
#initialize(catalog: :default) ⇒ Renderer
Returns a new instance of Renderer.
5
6
7
|
# File 'lib/generative_ui/renderer.rb', line 5
def initialize(catalog: :default)
@catalog_spec = catalog
end
|
Instance Method Details
#call(component_set) ⇒ Object
18
19
20
|
# File 'lib/generative_ui/renderer.rb', line 18
def call(component_set)
render_component_instance(component_set, component_set.root)
end
|
#catalog ⇒ Object
14
15
16
|
# File 'lib/generative_ui/renderer.rb', line 14
def catalog
@catalog ||= Catalog.coerce(@catalog_spec)
end
|
#catalog=(value) ⇒ Object
9
10
11
12
|
# File 'lib/generative_ui/renderer.rb', line 9
def catalog=(value)
@catalog_spec = value
@catalog = nil
end
|
#render_component(definition:, attributes:, additional_properties:) ⇒ Object
30
31
32
|
# File 'lib/generative_ui/renderer.rb', line 30
def render_component(definition:, attributes:, additional_properties:)
raise NotImplementedError, "#{self.class} must implement #render_component"
end
|
#render_component_instance(component_set, component) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/generative_ui/renderer.rb', line 22
def render_component_instance(component_set, component)
definition = catalog.fetch(component.name)
raise ArgumentError, "Unknown generative component: #{component.name}" unless definition
attributes, additional_properties = materialized_attributes(component_set, component, definition)
render_component(definition:, attributes:, additional_properties:)
end
|