class StyleInliner::NodeStyleFolding
Constants
- CORRESPONDENCE_TABLES
Public Class Methods
new(node, replace_properties_to_attributes: true)
click to toggle source
@param node [Nokogiri::XML::Node] @param replace_properties_to_attributes [false, true]
# File lib/style_inliner/node_style_folding.rb, line 62 def initialize(node, replace_properties_to_attributes: true) @node = node @replace_properties_to_attributes = replace_properties_to_attributes end
Public Instance Methods
call()
click to toggle source
# File lib/style_inliner/node_style_folding.rb, line 67 def call update_css_compatible_attributes if @replace_properties_to_attributes update_style_attribute end
Private Instance Methods
correspondence_table()
click to toggle source
@return [Hash{String => String}]
# File lib/style_inliner/node_style_folding.rb, line 75 def correspondence_table CORRESPONDENCE_TABLES[@node.name] end
declaration_block()
click to toggle source
@return [StyleInliner::RuleSet]
# File lib/style_inliner/node_style_folding.rb, line 80 def declaration_block @declaration_block ||= DeclarationBlock.new(RuleSet.decode(@node["style"])) end
preprocess_attribute_value(property_value)
click to toggle source
@param property_value [String] @return [String]
# File lib/style_inliner/node_style_folding.rb, line 86 def preprocess_attribute_value(property_value) property_value.gsub(/url\(['|"](.*)['|"]\)/, '\1').gsub(/;$|\s*!important/, '').strip end
update_css_compatible_attributes()
click to toggle source
# File lib/style_inliner/node_style_folding.rb, line 90 def update_css_compatible_attributes correspondence_table.each do |property_name, attribute_name| if @node[attribute_name].nil? && !declaration_block.get_property(property_name).empty? @node[attribute_name] = preprocess_attribute_value(declaration_block.get_property(property_name)) declaration_block.delete_property(property_name) end end end
update_style_attribute()
click to toggle source
# File lib/style_inliner/node_style_folding.rb, line 99 def update_style_attribute if (value = declaration_block.to_s).empty? @node.remove_attribute("style") else @node["style"] = value end end