Class: Mxrb::Compiler::GalleryBundleCompiler
- Inherits:
-
Object
- Object
- Mxrb::Compiler::GalleryBundleCompiler
- Includes:
- ModelValues
- Defined in:
- lib/mxrb/compiler/gallery_bundle_compiler.rb
Overview
Compiles the official React Gallery widget with XPath, microflow, or nanoflow data sources.
Constant Summary collapse
- WIDGET_ID =
'com.mendix.widget.web.gallery.Gallery'
Instance Attribute Summary collapse
-
#data_source ⇒ Object
readonly
Returns the value of attribute data_source.
-
#entity_name ⇒ Object
readonly
Returns the value of attribute entity_name.
Instance Method Summary collapse
- #content_widgets ⇒ Object
- #data_source_id ⇒ Object
-
#initialize(source, page_name, widget) ⇒ GalleryBundleCompiler
constructor
A new instance of GalleryBundleCompiler.
- #render(content, nanoflow_reference: nil) ⇒ Object
- #supported? ⇒ Boolean
- #widget_key ⇒ Object
Constructor Details
#initialize(source, page_name, widget) ⇒ GalleryBundleCompiler
Returns a new instance of GalleryBundleCompiler.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mxrb/compiler/gallery_bundle_compiler.rb', line 15 def initialize(source, page_name, ) @source = source @page_name = page_name @widget = @index = document_index @values = property_values(['Object']) @data_source = WebListDataSource.new(source, ) @entity_name = data_source.entity @xpath_arguments = resolve_xpath_arguments end |
Instance Attribute Details
#data_source ⇒ Object (readonly)
Returns the value of attribute data_source.
13 14 15 |
# File 'lib/mxrb/compiler/gallery_bundle_compiler.rb', line 13 def data_source @data_source end |
#entity_name ⇒ Object (readonly)
Returns the value of attribute entity_name.
13 14 15 |
# File 'lib/mxrb/compiler/gallery_bundle_compiler.rb', line 13 def entity_name @entity_name end |
Instance Method Details
#content_widgets ⇒ Object
31 |
# File 'lib/mxrb/compiler/gallery_bundle_compiler.rb', line 31 def = array(@values['content']&.last&.fetch('Widgets', nil)) |
#data_source_id ⇒ Object
33 |
# File 'lib/mxrb/compiler/gallery_bundle_compiler.rb', line 33 def data_source_id = "p.#{Digest::SHA256.hexdigest()[0, 6].to_i(16)}" |
#render(content, nanoflow_reference: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mxrb/compiler/gallery_bundle_compiler.rb', line 35 def render(content, nanoflow_reference: nil) @nanoflow_reference = nanoflow_reference values = primitives(@values).merge( key: , '$widgetId': , datasource: raw(datasource), content: raw("TemplatedWidgetProperty({ children: () => #{content}, " \ "dataSourceId: #{JSON.generate(data_source_id)}, editable: false })"), itemSelection: raw(selection), class: css_class ) "React.createElement($Gallery, #{js_object(values)})" end |
#supported? ⇒ Boolean
26 27 28 29 |
# File 'lib/mxrb/compiler/gallery_bundle_compiler.rb', line 26 def supported? &.fetch('WidgetId', nil) == WIDGET_ID && @data_source.supported? && !entity_name.to_s.empty? && !@xpath_arguments.nil? end |
#widget_key ⇒ Object
32 |
# File 'lib/mxrb/compiler/gallery_bundle_compiler.rb', line 32 def = "p.#{@page_name}.#{@widget['Name']}" |