Class: DraftjsExporter::StyleState
- Inherits:
-
Object
- Object
- DraftjsExporter::StyleState
- Defined in:
- lib/draftjs_exporter/style_state.rb
Instance Attribute Summary collapse
-
#style_map ⇒ Object
readonly
Returns the value of attribute style_map.
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
Instance Method Summary collapse
- #apply(command) ⇒ Object
- #element_attributes ⇒ Object
-
#initialize(style_map) ⇒ StyleState
constructor
A new instance of StyleState.
- #styles_css ⇒ Object
- #text? ⇒ Boolean
Constructor Details
#initialize(style_map) ⇒ StyleState
Returns a new instance of StyleState.
6 7 8 9 |
# File 'lib/draftjs_exporter/style_state.rb', line 6 def initialize(style_map) @styles = [] @style_map = style_map end |
Instance Attribute Details
#style_map ⇒ Object (readonly)
Returns the value of attribute style_map.
4 5 6 |
# File 'lib/draftjs_exporter/style_state.rb', line 4 def style_map @style_map end |
#styles ⇒ Object (readonly)
Returns the value of attribute styles.
4 5 6 |
# File 'lib/draftjs_exporter/style_state.rb', line 4 def styles @styles end |
Instance Method Details
#apply(command) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/draftjs_exporter/style_state.rb', line 11 def apply(command) case command.name when :start_inline_style styles.push(command.data) when :stop_inline_style styles.delete(command.data) end end |
#element_attributes ⇒ Object
24 25 26 27 |
# File 'lib/draftjs_exporter/style_state.rb', line 24 def element_attributes return {} unless styles.any? { style: styles_css } end |
#styles_css ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/draftjs_exporter/style_state.rb', line 29 def styles_css styles.map { |style| style_map.fetch(style) }.inject({}, :merge).map { |key, value| "#{key}: #{value};" }.join end |
#text? ⇒ Boolean
20 21 22 |
# File 'lib/draftjs_exporter/style_state.rb', line 20 def text? styles.empty? end |