mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Provide access to the Sass::Engine options from the Sass::Environment and during Sass function evaluation. This enables some cleverness to occur during compilation.
This commit is contained in:
parent
beb9ba7215
commit
0c7f7b6d4e
5 changed files with 24 additions and 4 deletions
|
@ -94,7 +94,7 @@ module Sass
|
|||
:load_paths => ['.']
|
||||
}.merge! options
|
||||
@template = template
|
||||
@environment = Environment.new
|
||||
@environment = Environment.new(nil, @options)
|
||||
@environment.set_var("important", Script::String.new("!important"))
|
||||
end
|
||||
|
||||
|
|
|
@ -2,10 +2,15 @@ module Sass
|
|||
class Environment
|
||||
attr_reader :parent
|
||||
|
||||
def initialize(parent = nil)
|
||||
def initialize(parent = nil, options = nil)
|
||||
@vars = {}
|
||||
@mixins = {}
|
||||
@parent = parent
|
||||
@options = options
|
||||
end
|
||||
|
||||
def options
|
||||
@options || (parent && parent.options) || {}
|
||||
end
|
||||
|
||||
def self.inherited_hash(name)
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
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)
|
||||
|
@ -18,7 +30,7 @@ module Sass
|
|||
return Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})")
|
||||
end
|
||||
|
||||
return Functions.send(name, *args)
|
||||
return 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}'")
|
||||
|
|
|
@ -19,6 +19,9 @@ module Sass::Script
|
|||
# and then left as static CSS files.
|
||||
# Any dynamic CSS should be left in <style> tags in the HTML.
|
||||
#
|
||||
# Within a sass function you can call the options method to gain access to the
|
||||
# options hash that was used to create the Sass::Engine that is processing the function call.
|
||||
#
|
||||
# The following functions are provided:
|
||||
# * +hsl+ - converts an <tt>hsl(hue, saturation, lightness)</tt> triplet into a color.
|
||||
#
|
||||
|
|
|
@ -96,7 +96,7 @@ class SassFunctionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def evaluate(value)
|
||||
Sass::Script::Parser.parse(value, 0, 0).perform({}).to_s
|
||||
Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
|
||||
end
|
||||
|
||||
def assert_error_message(message, value)
|
||||
|
|
Loading…
Reference in a new issue