2006-12-22 10:28:17 +00:00
|
|
|
require 'sass/constant/string'
|
2006-12-23 21:23:27 +00:00
|
|
|
require 'sass/constant/number'
|
2006-12-23 21:51:44 +00:00
|
|
|
require 'sass/constant/color'
|
2006-12-22 10:28:17 +00:00
|
|
|
|
2007-03-01 05:52:47 +00:00
|
|
|
module Sass::Constant # :nodoc:
|
|
|
|
class Operation # :nodoc:
|
2007-01-28 17:24:08 +00:00
|
|
|
def initialize(operand1, operand2, operator)
|
2006-12-23 22:32:05 +00:00
|
|
|
@operand1 = operand1
|
|
|
|
@operand2 = operand2
|
|
|
|
@operator = operator
|
2006-12-22 10:28:17 +00:00
|
|
|
end
|
2008-04-08 06:09:17 +00:00
|
|
|
|
2006-12-23 22:32:05 +00:00
|
|
|
def to_s
|
|
|
|
self.perform.to_s
|
2006-12-22 10:28:17 +00:00
|
|
|
end
|
2008-04-08 06:09:17 +00:00
|
|
|
|
2006-12-23 22:32:05 +00:00
|
|
|
protected
|
2008-04-08 06:09:17 +00:00
|
|
|
|
2006-12-23 03:06:52 +00:00
|
|
|
def perform
|
2006-12-23 22:32:05 +00:00
|
|
|
literal1 = @operand1.perform
|
|
|
|
literal2 = @operand2.perform
|
|
|
|
begin
|
|
|
|
literal1.send(@operator, literal2)
|
2006-12-23 22:57:31 +00:00
|
|
|
rescue NoMethodError => e
|
2007-02-10 02:55:55 +00:00
|
|
|
raise e unless e.name.to_s == @operator.to_s
|
2007-01-31 04:30:30 +00:00
|
|
|
raise Sass::SyntaxError.new("Undefined operation: \"#{literal1} #{@operator} #{literal2}\"")
|
2006-12-23 22:32:05 +00:00
|
|
|
end
|
2006-12-22 10:28:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|