PageRenderTime 24ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/scalate-jruby/src/main/resources/haml-3.0.25/lib/sass/tree/variable_node.rb

http://github.com/scalate/scalate
Ruby | 39 lines | 25 code | 3 blank | 11 comment | 5 complexity | 876ae3e80947d4447326c136b568ea72 MD5 | raw file
 1module Sass
 2  module Tree
 3    # A dynamic node representing a variable definition.
 4    #
 5    # @see Sass::Tree
 6    class VariableNode < Node
 7      # @param name [String] The name of the variable
 8      # @param expr [Script::Node] The parse tree for the initial variable value
 9      # @param guarded [Boolean] Whether this is a guarded variable assignment (`||=`)
10      def initialize(name, expr, guarded)
11        @name = name
12        @expr = expr
13        @guarded = guarded
14        super()
15      end
16
17      protected
18
19      # @see Node#to_src
20      def to_src(tabs, opts, fmt)
21        "#{'  ' * tabs}$#{dasherize(@name, opts)}: #{@expr.to_sass(opts)}#{' !default' if @guarded}#{semi fmt}\n"
22      end
23
24      # Loads the new variable value into the environment.
25      #
26      # @param environment [Sass::Environment] The lexical environment containing
27      #   variable and mixin values
28      def _perform(environment)
29        return [] if @guarded && !environment.var(@name).nil?
30        val = @expr.perform(environment)
31        if @expr.context == :equals && val.is_a?(Sass::Script::String)
32          val = Sass::Script::String.new(val.value)
33        end
34        environment.set_var(@name, val)
35        []
36      end
37    end
38  end
39end