From 808dcec05fb6b884f2179a9f4e08359d0a7fe0ca Mon Sep 17 00:00:00 2001 From: nex3 Date: Sat, 23 Dec 2006 21:51:44 +0000 Subject: [PATCH] Color literal. git-svn-id: svn://hamptoncatlin.com/haml/trunk@253 7063305b-7217-0410-af8c-cdc13e5119b9 --- lib/sass/constant/operation.rb | 11 ++++++++++- test/sass/results/constants.css | 2 +- test/sass/templates/constants.sass | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/sass/constant/operation.rb b/lib/sass/constant/operation.rb index 91a99f91..f938fd4a 100644 --- a/lib/sass/constant/operation.rb +++ b/lib/sass/constant/operation.rb @@ -1,8 +1,15 @@ require 'sass/constant/string' require 'sass/constant/number' +require 'sass/constant/color' module Sass::Constant class Operation + # The regular expression matching numbers. + NUMBER = /^[0-9]*\.?[0-9]+$/ + + # The regular expression matching colors. + COLOR = /^\#(#{"[0-9a-f]" * 3}|#{"[0-9a-f]" * 6})/ + def initialize(operand1, operand2=nil, operator=nil) @operand1 = parse(operand1) @operand2 = parse(operand2) if operand2 @@ -11,8 +18,10 @@ module Sass::Constant def parse(value) case value - when /^[0-9]*\.?[0-9]+$/ # Number with one or zero decimal points + when NUMBER Sass::Constant::Number.new(value) + when COLOR + Sass::Constant::Color.new(value) else Sass::Constant::String.new(value) end diff --git a/test/sass/results/constants.css b/test/sass/results/constants.css index 71627f99..2a2e8719 100644 --- a/test/sass/results/constants.css +++ b/test/sass/results/constants.css @@ -1,2 +1,2 @@ -#main { width: 500px; background-color: #000; color: #fff; } +#main { width: 500px; background-color: #000; color: #ffffaf; } #main #sidebar { background-color: #00ff98; num-normal: 10; num-dec: 10.2; num-dec0: 99; num-neg: -10; esc: 10+12; } diff --git a/test/sass/templates/constants.sass b/test/sass/templates/constants.sass index 21544d3e..c383cd8c 100644 --- a/test/sass/templates/constants.sass +++ b/test/sass/templates/constants.sass @@ -1,6 +1,6 @@ !width = 500px !color = #00ff98 -!main_text = #fff +!main_text = #ffa !num = 10 !dec = 10.2 !dec_0 = 99.0