module DocomoCss::EmbeddableStyle

Public Instance Methods

embed_style(style, options = {}) click to toggle source
# File lib/docomo_css/embeddable_style.rb, line 5
def embed_style(style, options = {})
  options = {:inject_unsupported_styles => true}.merge!(options)
  style = style.dup
  inject_unsupported_styles(style) if options[:inject_unsupported_styles]
  merge_style style
end
merge_style(other_style) click to toggle source
# File lib/docomo_css/embeddable_style.rb, line 12
def merge_style(other_style)
  return if other_style.empty?
  if self['style'] == nil
    self['style'] = other_style.to_s
  else
    self['style'] += ";" unless self['style'] =~ /;\Z/
    self['style'] += other_style.to_s
  end
end

Private Instance Methods

inject_unsupported_styles(style) click to toggle source
# File lib/docomo_css/embeddable_style.rb, line 24
def inject_unsupported_styles(style)
  if /^(h\d|p)$/ =~ name
    if (h = style.split('color', 'font-size')) && !h.empty? && !children.empty?
      children.wrap('<span>')
      children.first.merge_style h
    end
    if (h = style.split('background-color', 'background')) && !h.empty? && !children.empty?
      div = Nokogiri.make("<div>")
      div.merge_style(h)
      replace(div)
      div.add_child(self)
    end
  end
end