Merge branch 'master' into sassc
Conflicts: lib/sass/tree/comment_node.rb
This commit is contained in:
commit
04d30c599c
|
@ -185,10 +185,10 @@ END
|
|||
node.line = line.index
|
||||
node.filename = line.filename
|
||||
|
||||
unless node.is_a?(Tree::CommentNode)
|
||||
append_children(node, line.children, false)
|
||||
if node.is_a?(Tree::CommentNode)
|
||||
node.lines = line.children
|
||||
else
|
||||
node.children = line.children
|
||||
append_children(node, line.children, false)
|
||||
end
|
||||
return node
|
||||
end
|
||||
|
|
|
@ -2,17 +2,6 @@ require File.join(File.dirname(__FILE__), 'functions')
|
|||
module Sass
|
||||
module Script
|
||||
class Funcall # :nodoc:
|
||||
class EvaluationContext # :nodoc:
|
||||
|
||||
include Sass::Script::Functions
|
||||
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :name, :args
|
||||
|
||||
def initialize(name, args)
|
||||
|
@ -30,7 +19,7 @@ module Sass
|
|||
return Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})")
|
||||
end
|
||||
|
||||
return EvaluationContext.new(environment.options).send(name, *args)
|
||||
return Functions::EvaluationContext.new(environment.options).send(name, *args)
|
||||
rescue ArgumentError => e
|
||||
raise e unless e.backtrace.first =~ /:in `(#{name}|perform)'$/
|
||||
raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
|
||||
|
|
|
@ -44,8 +44,17 @@ module Sass::Script
|
|||
#
|
||||
# Example: <tt>abs(-10px) => 10px</tt>
|
||||
module Functions
|
||||
class EvaluationContext # :nodoc:
|
||||
include Sass::Script::Functions
|
||||
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
end
|
||||
|
||||
instance_methods.each { |m| undef_method m unless m.to_s =~ /^__/ }
|
||||
extend self
|
||||
|
||||
# Creates a Sass::Script::Color object from hue, saturation, and lightness.
|
||||
# As per the CSS3 spec (http://www.w3.org/TR/css3-color/#hsl-color),
|
||||
|
|
|
@ -65,10 +65,6 @@ module Sass
|
|||
@scanner.eos? && @tok.nil?
|
||||
end
|
||||
|
||||
def rest
|
||||
@scanner.rest
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def read_token
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Sass::Script::Literal # :nodoc:
|
||||
module Sass::Script
|
||||
class Literal # :nodoc:
|
||||
require 'sass/script/string'
|
||||
require 'sass/script/number'
|
||||
require 'sass/script/color'
|
||||
|
@ -77,4 +78,5 @@ class Sass::Script::Literal # :nodoc:
|
|||
def to_i
|
||||
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ module Sass::Script
|
|||
elsif other.is_a?(Color)
|
||||
other.plus(self)
|
||||
else
|
||||
Sass::Script::String.new(self.to_s + other.to_s)
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -77,17 +77,17 @@ module Sass::Script
|
|||
end
|
||||
|
||||
def gte(other)
|
||||
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
|
||||
raise NoMethodError.new(nil, :gte) unless other.is_a?(Number)
|
||||
operate(other, :>=)
|
||||
end
|
||||
|
||||
def lt(other)
|
||||
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
|
||||
raise NoMethodError.new(nil, :lt) unless other.is_a?(Number)
|
||||
operate(other, :<)
|
||||
end
|
||||
|
||||
def lte(other)
|
||||
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
|
||||
raise NoMethodError.new(nil, :lte) unless other.is_a?(Number)
|
||||
operate(other, :<=)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,15 +2,6 @@ require 'sass/script/literal'
|
|||
|
||||
module Sass::Script
|
||||
class String < Literal # :nodoc:
|
||||
INTERPOLATION = /(^|[^\\])\#\{([^}]*)\}/
|
||||
#TODO pass line & char context to perform
|
||||
def perform(environment)
|
||||
interpolated = @value.gsub(INTERPOLATION) do |match|
|
||||
"#{$1}#{Sass::Script.resolve($2, 0, 0, environment)}"
|
||||
end
|
||||
Sass::Script::String.new(interpolated)
|
||||
end
|
||||
|
||||
def to_s
|
||||
@value
|
||||
end
|
||||
|
|
|
@ -2,34 +2,27 @@ require 'sass/tree/node'
|
|||
|
||||
module Sass::Tree
|
||||
class CommentNode < Node
|
||||
attr_accessor :lines
|
||||
attr_accessor :value
|
||||
attr_accessor :silent
|
||||
|
||||
def initialize(value, silent)
|
||||
@lines = []
|
||||
@value = value[2..-1].strip
|
||||
@silent = silent
|
||||
super()
|
||||
end
|
||||
|
||||
def options=(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
self.value == other.value && super
|
||||
self.class == other.class && value == other.value && silent == other.silent && lines == other.lines
|
||||
end
|
||||
|
||||
def to_s(tabs = 0, parent_name = nil)
|
||||
return if (style == :compressed || @silent)
|
||||
|
||||
spaces = ' ' * (tabs - 1)
|
||||
spaces + "/* " + ([value] + children.map {|c| c.text}).
|
||||
spaces + "/* " + ([value] + lines.map {|l| l.text}).
|
||||
map{|l| l.sub(%r{ ?\*/ *$},'')}.join(style == :compact ? ' ' : "\n#{spaces} * ") + " */"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def _perform(environment)
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -92,7 +92,7 @@ class SassFunctionTest < Test::Unit::TestCase
|
|||
|
||||
def assert_rgb_hsl(rgb, hsl)
|
||||
hsl = hsl.map {|v| Sass::Script::Parser.parse v, 0, 0 }
|
||||
assert_equal(rgb, Sass::Script::Functions.hsl(*hsl).value)
|
||||
assert_equal(rgb, Sass::Script::Functions::EvaluationContext.new({}).hsl(*hsl).value)
|
||||
end
|
||||
|
||||
def evaluate(value)
|
||||
|
|
Loading…
Reference in New Issue