Number literal.

git-svn-id: svn://hamptoncatlin.com/haml/trunk@251 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2006-12-23 21:23:27 +00:00
parent b81a91672d
commit e794493bc8
5 changed files with 38 additions and 6 deletions

View File

@ -0,0 +1,13 @@
module Sass::Constant
class Number
def initialize(value)
value = value.to_f
value = value.to_i if value % 1 == 0.0
@value = value
end
def to_s
@value.to_s
end
end
end

View File

@ -1,4 +1,5 @@
require 'sass/constant/string'
require 'sass/constant/number'
module Sass::Constant
class Operation
@ -9,14 +10,19 @@ module Sass::Constant
end
def parse(value)
Sass::Constant::String.new(value)
case value
when /^[0-9]*\.?[0-9]+$/ # Number with one or zero decimal points
Sass::Constant::Number.new(value)
else
Sass::Constant::String.new(value)
end
end
def perform
if @operator
else
#if @operator
#else
@operand1.to_s
end
#end
end
end
end

View File

@ -126,7 +126,9 @@ module Sass
end
def parse_constant(line)
name, value = line.scan(/^#{Regexp.escape(CONSTANT_CHAR.chr)}([^\s=]+)\s*=\s*(.+)/)[0]
not_in_name = Sass::Constant::SYMBOLS.keys + [ Sass::Constant::ESCAPE_CHAR, '='[0] ]
not_in_name.map! { |c| "\\#{c.chr}" }
name, value = line.scan(/^#{Regexp.escape(CONSTANT_CHAR.chr)}([^\s#{not_in_name.join}]+)\s*=\s*(.+)/)[0]
raise "Invalid constant assignment:\n#{line}" unless name && value
@constants[name] = Sass::Constant.parse(value, @constants)
nil

View File

@ -1,2 +1,2 @@
#main { width: 500px; background-color: #000; color: #fff; }
#main #sidebar { background-color: #00ff98; }
#main #sidebar { background-color: #00ff98; num-normal: 10; num-dec: 10.2; num-dec0: 99; num-neg: -10; esc: 10+12; }

View File

@ -1,6 +1,11 @@
!width = 500px
!color = #00ff98
!main_text = #fff
!num = 10
!dec = 10.2
!dec_0 = 99.0
!neg = -10
!esc= 10\+12
#main
:width= !width
@ -8,3 +13,9 @@
:color= !main_text
#sidebar
:background-color= !color
:num
:normal= !num
:dec= !dec
:dec0= !dec_0
:neg= !neg
:esc= !esc