PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/scalate-jruby/src/main/resources/haml-3.0.25/lib/sass/script/variable.rb

http://github.com/scalate/scalate
Ruby | 48 lines | 28 code | 5 blank | 15 comment | 3 complexity | 1faeb25d8a76943507fce2554bf115ac MD5 | raw file
 1module Sass
 2  module Script
 3    # A SassScript parse node representing a variable.
 4    class Variable < Node
 5      # The name of the variable.
 6      #
 7      # @return [String]
 8      attr_reader :name
 9
10      # @param name [String] See \{#name}
11      def initialize(name)
12        @name = name
13        super()
14      end
15
16      # @return [String] A string representation of the variable
17      def inspect(opts = {})
18        return "!important" if name == "important"
19        "$#{dasherize(name, opts)}"
20      end
21      alias_method :to_sass, :inspect
22
23      # Returns an empty array.
24      #
25      # @return [Array<Node>] empty
26      # @see Node#children
27      def children
28        []
29      end
30
31      protected
32
33      # Evaluates the variable.
34      #
35      # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
36      # @return [Literal] The SassScript object that is the value of the variable
37      # @raise [Sass::SyntaxError] if the variable is undefined
38      def _perform(environment)
39        raise SyntaxError.new("Undefined variable: \"$#{name}\".") unless val = environment.var(name)
40        if val.is_a?(Number)
41          val = val.dup
42          val.original = nil
43        end
44        return val
45      end
46    end
47  end
48end