Sha256: b04b7595eee7d50ef8bd9fd73a16cb38a320b3ded806d3154d41ad50a162512f

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'nokogiri'
require 'css_parser_master'
require 'css_model'
require 'yaml'

module CSS
  module Element
    attr_accessor :parser
    attr_accessor :ruleset
    attr_accessor :rules
    attr_accessor :declarations

    def add_rule!(rule)
      @parser ||= CssParserMaster::Parser.new
      @declarations = {}  
            
      parser.add_block! rule                 
    end

    def add_declaration!(declaration)
      return if !declaration                     
      @declarations ||= {}  
      dec = declaration.kind_of?(Array) ? declaration[1] : declaration
      declarations[dec.property] = dec
    end
    alias_method :[]=, :add_declaration!

    def merge_declarations(selector)
      @order = 0
      
      selector.each_declaration do |decl|        
        add_declaration!(decl)
      end
    end

    def merge_style!
      style = attribute('style')        
      if style   
        s = style.to_s + ';'
        selector = CssParserMaster::Selector.new(name, s, 99999)
        merge_declarations(selector)
      end
    end
                                         
    # merge declarations by specificity
    def merge_declarations!   
      !parser and return

      @order = 0
      @declarations ||= {}

      parser.selector_declarations do |sel, decl|
        add_declaration!(decl)
      end   
    end   

    def duplicate?(decl)
      declarations.select{|d| d.property == decl.property}.empty?         
    end
  end
end 
     

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
html_css_decorator-0.1.2 lib/html_css_decorator.rb