')
merge_style(element.children.first, property, value)
end
private
def self.wrap_all_children(element, tag)
new_parent = element.document.parse(tag).first
element.children.each {|f| new_parent.add_child(f)}
element.add_child(new_parent)
end
end
class BackGroundAdapter < GenericAdapter
def self.apply?(property)
property == 'background-color'
end
def self.apply(element, property, value)
div = Nokogiri.make("")
merge_style(div,property,value)
element.replace(div)
div.add_child(element)
end
end
class BorderAdapter < GenericAdapter
def self.apply?(property)
%w[border border-top border-bottom].include?(property)
end
def self.apply(element, property,value)
color = value.split(/\s/).last.split('#').last
thickness = value.match(/(\d+)px/)[1]
img = Galakei::Spacer.img_tag(:color => color, :height => thickness)
case property
when 'border'
element.after(img)
element.before(img)
when 'border-top'
element.before(img)
when 'border-bottom'
element.after(img)
end
rescue => err
Rails.logger.warn("could not insert spacer gif: #{err}")
end
end
end