sass 3.3.0.alpha.88 → 3.3.0.alpha.93

Sign up to get free protection for your applications and to get access to all the features.
data/REVISION CHANGED
@@ -1 +1 @@
1
- c8154cc19b995b06961c60fb376d9c4821f8bde1
1
+ 655e8ae0d3bcab12d522eac27a7f7cb876475756
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.3.0.alpha.88
1
+ 3.3.0.alpha.93
@@ -1 +1 @@
1
- 18 February 2013 01:09:19 GMT
1
+ 23 February 2013 01:38:58 GMT
@@ -43,6 +43,10 @@ module Sass
43
43
  @content || (@parent && @parent.content)
44
44
  end
45
45
 
46
+ def global_env
47
+ @global_env ||= parent.nil? ? self : parent.global_env
48
+ end
49
+
46
50
  private
47
51
 
48
52
  class << self
@@ -103,7 +103,8 @@ module Sass
103
103
  unless Functions.callable?(ruby_name)
104
104
  opts(to_literal(args))
105
105
  else
106
- opts(Functions::EvaluationContext.new(environment.options).send(ruby_name, *args))
106
+ local_environment = Environment.new(environment.global_env, environment.options)
107
+ opts(Functions::EvaluationContext.new(local_environment).send(ruby_name, *args))
107
108
  end
108
109
  rescue ArgumentError => e
109
110
  # If this is a legitimate Ruby-raised argument error, re-raise it.
@@ -327,14 +327,21 @@ module Sass::Script
327
327
  class EvaluationContext
328
328
  include Functions
329
329
 
330
+
331
+ # The environment of the {Sass::Engine}
332
+ #
333
+ # @return [Environment]
334
+ attr_reader :environment
335
+
330
336
  # The options hash for the {Sass::Engine} that is processing the function call
331
337
  #
332
338
  # @return [{Symbol => Object}]
333
339
  attr_reader :options
334
340
 
335
- # @param options [{Symbol => Object}] See \{#options}
336
- def initialize(options)
337
- @options = options
341
+ # @param environment [Environment] See \{#environment}
342
+ def initialize(environment)
343
+ @environment = environment
344
+ @options = environment.options
338
345
  end
339
346
 
340
347
  # Asserts that the type of a given SassScript value
@@ -3,7 +3,7 @@ class Sass::Tree::Visitors::Perform < Sass::Tree::Visitors::Base
3
3
  # @param root [Tree::Node] The root node of the tree to visit.
4
4
  # @param environment [Sass::Environment] The lexical environment.
5
5
  # @return [Tree::Node] The resulting tree of static nodes.
6
- def self.visit(root, environment = Sass::Environment.new)
6
+ def self.visit(root, environment = nil)
7
7
  new(environment).send(:visit, root)
8
8
  end
9
9
 
@@ -11,6 +11,15 @@ module Sass::Script::Functions::UserFunctions
11
11
  def option(name)
12
12
  Sass::Script::String.new(@options[name.value.to_sym].to_s)
13
13
  end
14
+
15
+ def set_a_variable(name, value)
16
+ environment.set_var(name.value, value)
17
+ return Sass::Script::Null.new
18
+ end
19
+
20
+ def get_a_variable(name)
21
+ environment.var(name.value) || Sass::Script::String.new("undefined")
22
+ end
14
23
  end
15
24
 
16
25
  class SassEngineTest < Test::Unit::TestCase
@@ -1400,6 +1409,44 @@ bar
1400
1409
  SASS
1401
1410
  end
1402
1411
 
1412
+ def test_user_defined_function_variable_scope
1413
+ render(<<SASS)
1414
+ bar
1415
+ -no-op: set-a-variable(variable, 5)
1416
+ a: $variable
1417
+ SASS
1418
+ flunk("Exception not raised for test_user_defined_function_variable_scope")
1419
+ rescue Sass::SyntaxError => e
1420
+ assert_equal('Undefined variable: "$variable".', e.message)
1421
+ end
1422
+
1423
+ def test_user_defined_function_can_change_global_variable
1424
+ assert_equal(<<CSS, render(<<SASS))
1425
+ bar {
1426
+ a: 5; }
1427
+ CSS
1428
+ $variable: 0
1429
+ bar
1430
+ $local: 10
1431
+ -no-op: set-a-variable(variable, 5)
1432
+ a: $variable
1433
+ SASS
1434
+ end
1435
+
1436
+ def test_user_defined_function_cannot_read_local_variable
1437
+ assert_equal(<<CSS, render(<<SASS))
1438
+ bar {
1439
+ global: 0;
1440
+ local: undefined; }
1441
+ CSS
1442
+ $global: 0
1443
+ bar
1444
+ $local: 10
1445
+ global: get-a-variable(global)
1446
+ local: get-a-variable(local)
1447
+ SASS
1448
+ end
1449
+
1403
1450
  def test_control_directive_in_nested_property
1404
1451
  assert_equal(<<CSS, render(<<SASS))
1405
1452
  foo {
@@ -33,6 +33,10 @@ module Sass::Script::Functions::UserFunctions
33
33
  def _preceding_underscore
34
34
  Sass::Script::String.new("I'm another user-defined string!")
35
35
  end
36
+
37
+ def fetch_the_variable
38
+ environment.var('variable')
39
+ end
36
40
  end
37
41
 
38
42
  module Sass::Script::Functions
@@ -949,6 +953,11 @@ class SassFunctionTest < Test::Unit::TestCase
949
953
  assert_equal("I'm another user-defined string!", evaluate("-preceding-underscore()"))
950
954
  end
951
955
 
956
+ def test_user_defined_function_using_environment
957
+ environment = env('variable' => Sass::Script::String.new('The variable'))
958
+ assert_equal("The variable", evaluate("fetch_the_variable()", environment))
959
+ end
960
+
952
961
  def test_options_on_new_literals_fails
953
962
  assert_error_message(<<MSG, "call-options-on-new-literal()")
954
963
  The #options attribute is not set on this Sass::Script::String.
@@ -1194,13 +1203,18 @@ MSG
1194
1203
  end
1195
1204
 
1196
1205
  private
1206
+ def env(hash = {})
1207
+ env = Sass::Environment.new
1208
+ hash.each {|k, v| env.set_var(k, v)}
1209
+ env
1210
+ end
1197
1211
 
1198
- def evaluate(value)
1199
- Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
1212
+ def evaluate(value, environment = env)
1213
+ perform(value, environment).to_s
1200
1214
  end
1201
1215
 
1202
- def perform(value)
1203
- Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new)
1216
+ def perform(value, environment = env)
1217
+ Sass::Script::Parser.parse(value, 0, 0).perform(environment)
1204
1218
  end
1205
1219
 
1206
1220
  def assert_error_message(message, value)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass
3
3
  version: !ruby/object:Gem::Version
4
- hash: 592303037
4
+ hash: 592303031
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 3
9
9
  - 0
10
10
  - alpha
11
- - 88
12
- version: 3.3.0.alpha.88
11
+ - 93
12
+ version: 3.3.0.alpha.93
13
13
  platform: ruby
14
14
  authors:
15
15
  - Nathan Weizenbaum
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2013-02-17 00:00:00 -05:00
22
+ date: 2013-02-22 00:00:00 -05:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency