Class: Mxrb::Compiler::GenericWidgetBundleCompiler
- Inherits:
-
Object
- Object
- Mxrb::Compiler::GenericWidgetBundleCompiler
- Includes:
- ModelValues
- Defined in:
- lib/mxrb/compiler/generic_widget_bundle_compiler.rb
Overview
Compiles schema-described pluggable widgets whose properties use the standard client contracts. rubocop:disable Metrics
Instance Attribute Summary collapse
-
#component_name ⇒ Object
readonly
Returns the value of attribute component_name.
-
#module_path ⇒ Object
readonly
Returns the value of attribute module_path.
Instance Method Summary collapse
-
#initialize(source, page_name, widget, scope:, entity:, render_widgets: nil, key_prefix: 'p', action_property: nil) ⇒ GenericWidgetBundleCompiler
constructor
A new instance of GenericWidgetBundleCompiler.
- #render ⇒ Object
- #supported? ⇒ Boolean
Constructor Details
#initialize(source, page_name, widget, scope:, entity:, render_widgets: nil, key_prefix: 'p', action_property: nil) ⇒ GenericWidgetBundleCompiler
Returns a new instance of GenericWidgetBundleCompiler.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mxrb/compiler/generic_widget_bundle_compiler.rb', line 15 def initialize(source, page_name, , scope:, entity:, render_widgets: nil, key_prefix: 'p', action_property: nil) @source = source @page_name = page_name @widget = @scope = scope @entity = entity.to_s @render_widgets = @key_prefix = key_prefix @action_property = action_property @index = source.document_index @widget_type = @values = property_values(['Object']) @list_data_source = @values.values.find { _1.first == 'DataSource' }&.last @component_name = .to_s.split('.').last @module_path = .to_s.tr('.', '/') end |
Instance Attribute Details
#component_name ⇒ Object (readonly)
Returns the value of attribute component_name.
13 14 15 |
# File 'lib/mxrb/compiler/generic_widget_bundle_compiler.rb', line 13 def component_name @component_name end |
#module_path ⇒ Object (readonly)
Returns the value of attribute module_path.
13 14 15 |
# File 'lib/mxrb/compiler/generic_widget_bundle_compiler.rb', line 13 def module_path @module_path end |
Instance Method Details
#render ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/mxrb/compiler/generic_widget_bundle_compiler.rb', line 38 def render properties = @values.each_with_object({}) do |(key, pair), result| compiled = compile_property(pair) result[key.to_sym] = compiled unless compiled.equal?(:undefined) end properties.merge!(key: , '$widgetId': , class: css_class) "React.createElement($#{@component_name}, #{javascript(properties)})" end |
#supported? ⇒ Boolean
33 34 35 36 |
# File 'lib/mxrb/compiler/generic_widget_bundle_compiler.rb', line 33 def supported? present_identifier?(@component_name) && package_module? && @values.values.all? { supported_property?(_1) } end |