Class: NtiReceiptBuilder::Renderer
- Inherits:
-
Object
- Object
- NtiReceiptBuilder::Renderer
- Defined in:
- lib/nti_receipt_builder/renderer.rb
Overview
The single entry point that assembles a template's visible layout elements into presenters. The designer preview and the printed receipt both call this — never two divergent render code paths.
Pass a receipt_object for real data; omit it and the configured variables class supplies samples, without calling any mapping method.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(template:, receipt_object: nil, variables_class: NtiReceiptBuilder.variables_class) ⇒ Renderer
constructor
A new instance of Renderer.
Constructor Details
#initialize(template:, receipt_object: nil, variables_class: NtiReceiptBuilder.variables_class) ⇒ Renderer
Returns a new instance of Renderer.
11 12 13 14 15 |
# File 'lib/nti_receipt_builder/renderer.rb', line 11 def initialize(template:, receipt_object: nil, variables_class: NtiReceiptBuilder.variables_class) @template = template @receipt_object = receipt_object @variables_class = variables_class end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nti_receipt_builder/renderer.rb', line 17 def call data = resolve_data resolved_variables = VariableResolver.new(data, definitions: variables_class.definitions).call collection_rows = collection_key ? data[collection_key] || [] : [] presenters = visible_elements .map { |element| build_presenter(element, resolved_variables, collection_rows) } .sort_by(&:z_index) RenderResult.new( elements: presenters, overflow: overflow?(presenters), content_height_mm: content_height_mm(presenters) ) end |