Class: Exclaim::Ui
- Inherits:
-
Object
- Object
- Exclaim::Ui
- Defined in:
- lib/exclaim/ui.rb
Instance Attribute Summary collapse
-
#implementation_map ⇒ Object
readonly
Returns the value of attribute implementation_map.
-
#parsed_ui ⇒ Object
readonly
Returns the value of attribute parsed_ui.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
Instance Method Summary collapse
- #each_element(element_names = :ALL_ELEMENTS, &blk) ⇒ Object
-
#initialize(implementation_map: Exclaim::Implementations.example_implementation_map, should_escape_html: true) ⇒ Ui
constructor
A new instance of Ui.
- #parse_ui!(ui_config) ⇒ Object
- #render(env: {}) ⇒ Object
- #unique_bind_paths ⇒ Object
Constructor Details
#initialize(implementation_map: Exclaim::Implementations.example_implementation_map, should_escape_html: true) ⇒ Ui
Returns a new instance of Ui.
7 8 9 10 11 12 13 14 15 |
# File 'lib/exclaim/ui.rb', line 7 def initialize(implementation_map: Exclaim::Implementations.example_implementation_map, should_escape_html: true) @implementation_map = Exclaim::ImplementationMap.parse!(implementation_map) @should_escape_html = should_escape_html rescue Exclaim::Error raise rescue StandardError => e e.extend(Exclaim::InternalError) raise end |
Instance Attribute Details
#implementation_map ⇒ Object (readonly)
Returns the value of attribute implementation_map.
5 6 7 |
# File 'lib/exclaim/ui.rb', line 5 def implementation_map @implementation_map end |
#parsed_ui ⇒ Object
Returns the value of attribute parsed_ui.
5 6 7 |
# File 'lib/exclaim/ui.rb', line 5 def parsed_ui @parsed_ui end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
5 6 7 |
# File 'lib/exclaim/ui.rb', line 5 def renderer @renderer end |
Instance Method Details
#each_element(element_names = :ALL_ELEMENTS, &blk) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/exclaim/ui.rb', line 50 def each_element(element_names = :ALL_ELEMENTS, &blk) if parsed_ui.nil? = 'Cannot compute each_element without UI configured, ' \ 'must call Exclaim::Ui#parse_ui(ui_config) first' raise UiConfigurationError.new() end normalized_element_names = parse_element_names(element_names) if block_given? top_level_component = parsed_ui recurse_json_declarations(top_level_component, normalized_element_names, &blk) else to_enum(__callee__) end end |
#parse_ui!(ui_config) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/exclaim/ui.rb', line 17 def parse_ui!(ui_config) self.parsed_ui = Exclaim::UiConfiguration.parse!(@implementation_map, ui_config) rescue Exclaim::Error raise rescue StandardError => e e.extend(Exclaim::InternalError) raise end |
#render(env: {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/exclaim/ui.rb', line 26 def render(env: {}) if parsed_ui.nil? = 'Cannot render without UI configured, must call Exclaim::Ui#parse_ui(ui_config) first' raise RenderingError.new() end renderer.call(env: env) rescue Exclaim::Error raise rescue StandardError => e e.extend(Exclaim::InternalError) raise end |
#unique_bind_paths ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/exclaim/ui.rb', line 40 def unique_bind_paths if parsed_ui.nil? = 'Cannot compute unique_bind_paths without UI configured, ' \ 'must call Exclaim::Ui#parse_ui(ui_config) first' raise UiConfigurationError.new() end parsed_ui.config.reduce([]) { |all_paths, config_value| bind_paths(config_value, all_paths) }.uniq! end |