Class: DrawioDsl::Formatters::StyleBuilder
- Inherits:
-
Object
- Object
- DrawioDsl::Formatters::StyleBuilder
- Defined in:
- lib/drawio_dsl/formatters/style_builder.rb
Overview
Build the style attribute for a HTML element
Constant Summary collapse
- MAPPINGS =
{ margin: 'margin', margin_top: 'margin-top', margin_bottom: 'margin-bottom', margin_left: 'margin-left', margin_right: 'margin-right', padding: 'padding', padding_top: 'padding-top', padding_bottom: 'padding-bottom', padding_left: 'padding-left', padding_right: 'padding-right', text_align: 'text-align', font_size: 'font-size', font_weight: 'font-weight', font_style: 'font-style', font_family: 'font-family', color: 'color' }.freeze
Instance Attribute Summary collapse
-
#custom ⇒ Object
readonly
Returns the value of attribute custom.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
Instance Method Summary collapse
- #customize(**opts) ⇒ Object
-
#initialize(**opts) ⇒ StyleBuilder
constructor
A new instance of StyleBuilder.
- #style ⇒ Object
- #style_attribute ⇒ Object
Constructor Details
#initialize(**opts) ⇒ StyleBuilder
Returns a new instance of StyleBuilder.
31 32 33 34 35 |
# File 'lib/drawio_dsl/formatters/style_builder.rb', line 31 def initialize(**opts) @style_parts = [] @defaults = opts @custom = {} end |
Instance Attribute Details
#custom ⇒ Object (readonly)
Returns the value of attribute custom.
29 30 31 |
# File 'lib/drawio_dsl/formatters/style_builder.rb', line 29 def custom @custom end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
28 29 30 |
# File 'lib/drawio_dsl/formatters/style_builder.rb', line 28 def defaults @defaults end |
Instance Method Details
#customize(**opts) ⇒ Object
37 38 39 40 41 |
# File 'lib/drawio_dsl/formatters/style_builder.rb', line 37 def customize(**opts) @custom = opts self end |
#style ⇒ Object
43 44 45 46 |
# File 'lib/drawio_dsl/formatters/style_builder.rb', line 43 def style build @style_parts.join(';') end |
#style_attribute ⇒ Object
48 49 50 51 |
# File 'lib/drawio_dsl/formatters/style_builder.rb', line 48 def style_attribute style_value = style style_value.empty? ? nil : " style=\"#{style_value}\"" end |