Class: NtiReceiptBuilder::Presenters::Element
- Inherits:
-
Object
- Object
- NtiReceiptBuilder::Presenters::Element
- Defined in:
- lib/nti_receipt_builder/presenters/element.rb
Overview
Presents one variable or text layout element: a whitelisted inline style string and
a plain (un-escaped-by-us) display string. ERB's default auto-escaping in the render
partials is what actually escapes the text — this presenter never marks anything
html_safe.
Instance Method Summary collapse
- #css_style ⇒ Object
- #display_text ⇒ Object
- #height_mm ⇒ Object
- #id ⇒ Object
-
#initialize(element, resolved_variables) ⇒ Element
constructor
A new instance of Element.
- #type ⇒ Object
- #width_mm ⇒ Object
- #x_mm ⇒ Object
- #y_mm ⇒ Object
- #z_index ⇒ Object
Constructor Details
#initialize(element, resolved_variables) ⇒ Element
Returns a new instance of Element.
10 11 12 13 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 10 def initialize(element, resolved_variables) @element = element @resolved_variables = resolved_variables end |
Instance Method Details
#css_style ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 23 def css_style declarations = [ 'position: absolute', "left: #{x_mm}mm", "top: #{y_mm}mm", "width: #{width_mm}mm", "height: #{height_mm}mm", "z-index: #{z_index}" ] declarations.concat(style_declarations).join('; ') end |
#display_text ⇒ Object
35 36 37 38 39 40 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 35 def display_text case type when 'variable' then variable_display_text when 'text' then element['text'].to_s end end |
#height_mm ⇒ Object
20 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 20 def height_mm = element['height_mm'].to_f |
#id ⇒ Object
15 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 15 def id = element['id'] |
#type ⇒ Object
16 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 16 def type = element['type'] |
#width_mm ⇒ Object
19 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 19 def width_mm = element['width_mm'].to_f |
#x_mm ⇒ Object
17 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 17 def x_mm = element['x_mm'].to_f |
#y_mm ⇒ Object
18 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 18 def y_mm = element['y_mm'].to_f |
#z_index ⇒ Object
21 |
# File 'lib/nti_receipt_builder/presenters/element.rb', line 21 def z_index = element['z_index'] || 0 |