Sha256: bfae57d422e0d58538652e6befed2a374bc6327760f0f6f0c77339cd2e555229
Contents?: true
Size: 1.12 KB
Versions: 5
Compression:
Stored size: 1.12 KB
Contents
module Stylesheet class CssStyleDeclaration extend Forwardable def_delegators :@declarations_list, :length, :size, :[], :each, :<<, :push, :delete, :to_s include Enumerable attr_reader :declarations, :parent_rule def initialize(options={}) @declarations = Hash.new("") @parent_rule = options[:parent_rule] self.css_text = options[:css_text] end def css_text=(css_text) @declarations_list = [] re = /((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)\s*/ css_text.to_s.strip.chomp(";").scan(re).flatten.each do |declaration| next unless declaration.include?(":") property, value = declaration.split(":", 2) @declarations_list << declaration.strip @declarations[property.strip] = parse_value(value.strip) end end def css_text css_text = @declarations_list.join("; ") css_text += ";" if css_text != "" end alias_method :to_s, :css_text def method_missing(name, *args) @declarations[Inflector.dasherize(name.to_s)] end private def parse_value(value) value end end end
Version data entries
5 entries across 5 versions & 1 rubygems