class DraftjsExporter::StyleState

Attributes

style_map[R]
styles[R]

Public Class Methods

new(style_map) click to toggle source
# File lib/draftjs_exporter/style_state.rb, line 6
def initialize(style_map)
  @styles = []
  @style_map = style_map
end

Public Instance Methods

apply(command) click to toggle source
# 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() click to toggle source
# File lib/draftjs_exporter/style_state.rb, line 24
def element_attributes
  return {} unless styles.any?
  { style: styles_css }
end
hyphenize(string) click to toggle source
# File lib/draftjs_exporter/style_state.rb, line 37
def hyphenize(string)
  string.to_s.gsub(/[A-Z]/) { |match| "-#{match.downcase}" }
end
styles_css() click to toggle source
# File lib/draftjs_exporter/style_state.rb, line 29
def styles_css
  styles.map { |style|
    style_map.fetch(style)
  }.inject({}, :merge).map { |key, value|
    "#{hyphenize(key)}: #{value};"
  }.join
end
text?() click to toggle source
# File lib/draftjs_exporter/style_state.rb, line 20
def text?
  styles.empty?
end