Module: Sass::Extras::Variables

Defined in:
lib/sass/extras/variables.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
# File 'lib/sass/extras/variables.rb', line 4

def self.included(base)
  base.declare :variable_get, [:name]
  base.declare :global_variable_get, [:name]
end

Instance Method Details

#global_variable_get($name) ⇒ Sass::Script::Value::Bool

Check whether a variable with the given name exists in the global scope (at the top level of the file).

Examples:

$a-false-value: false;
global-variable-get(a-false-value) => false

.foo {
  $some-var: false;
  global-variable-get(some-var) => null
}

Parameters:

  • $name (Sass::Script::Value::String)

    The name of the variable to check. The name should not include the ‘$`.

Returns:

  • (Sass::Script::Value::Bool)

    Whether the variable is defined in the global scope.



45
46
47
48
# File 'lib/sass/extras/variables.rb', line 45

def global_variable_get(name)
  assert_type name, :String, :name
  environment.global_env.var(name.value)
end

#variable_get($name) ⇒ Sass::Script::Value::Bool

Get the value of a variable with the given name, if it exists in the current scope or in the global scope.

Examples:

$a-false-value: false;
variable-get(a-false-value) => false

variable-get(nonexistent) => null

Parameters:

  • $name (Sass::Script::Value::String)

    The name of the variable to check. The name should not include the ‘$`.

Returns:

  • (Sass::Script::Value::Bool)

    Whether the variable is defined in the current scope.



23
24
25
26
# File 'lib/sass/extras/variables.rb', line 23

def variable_get(name)
  assert_type name, :String, :name
  environment.caller.var(name.value)
end