1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/lib/sass/constant/literal.rb
nex3 1d29067586 Fixing Sass color-parsing bug. Thanks to Polar Humenn for pointing this out.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@586 7063305b-7217-0410-af8c-cdc13e5119b9
2007-08-16 18:00:43 +00:00

53 lines
1.2 KiB
Ruby

# Let the subclasses see the superclass
module Sass::Constant; class Literal; end; end; # :nodoc:
require 'sass/constant/string'
require 'sass/constant/number'
require 'sass/constant/color'
class Sass::Constant::Literal # :nodoc:
# The regular expression matching numbers.
NUMBER = /^(-?\d*?\.?)(\d+)([^\d\s]*)$/
html_color_matcher = Sass::Constant::Color::HTML4_COLORS.keys.map { |c| "^#{c}$" }.join '|'
# The regular expression matching colors.
COLOR = /^\# (?: [\da-f]{3} | [\da-f]{6} ) | #{html_color_matcher}/ix
def self.parse(value)
case value
when NUMBER
Sass::Constant::Number.new(value)
when COLOR
Sass::Constant::Color.new(value)
else
Sass::Constant::String.new(value)
end
end
def initialize(value = nil)
self.parse(value) if value
end
def perform
self
end
def concat(other)
Sass::Constant::String.from_value("#{self.to_s} #{other.to_s}")
end
attr_reader :value
protected
def self.filter_value(value)
value
end
def self.from_value(value)
instance = self.new
instance.instance_variable_set('@value', self.filter_value(value))
instance
end
end