### Home Classes Methods

### In Files

- lib/sass/tree/visitors/perform.rb

### Parent

Sass::Tree::Visitors::Base

### Methods

- ::new
- ::perform_arguments
- ::perform_splat
- ::visit
- #visit
- #visit_atroot
- #visit_children
- #visit_comment
- #visit_content
- #visit_cssimport
- #visit_debug
- #visit_directive
- #visit_each
- #visit_error
- #visit_extend
- #visit_for
- #visit_function
- #visit_if
- #visit_import
- #visit_media
- #visit_mixin
- #visit_mixindef
- #visit_prop
- #visit_return
- #visit_root
- #visit_rule
- #visit_supports
- #visit_variable
- #visit_warn
- #visit_while
- #with_environment

### Class/Module Index

Quicksearch

- Sass
- Sass::BaseEnvironment
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::ReadOnlyEnvironment
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Script::Value::String
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::Cssize::Bubble
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

No matching classes.

# Sass::Tree::Visitors::Perform

A visitor for converting a dynamic Sass tree into a static Sass tree.

### Public Class Methods

new(env) click to toggle source

@comment

    rubocop:enable MethodLength

    # File lib/sass/tree/visitors/perform.rb, line 151
    def initialize(env)
      @environment = env
    end

perform_arguments(callable, args, splat, environment) click to toggle source

@api private @comment

    rubocop:disable MethodLength

    # File lib/sass/tree/visitors/perform.rb, line 14
    def perform_arguments(callable, args, splat, environment)
      desc = "#{callable.type.capitalize} #{callable.name}"
      downcase_desc = "#{callable.type} #{callable.name}"

      # All keywords are contained in splat.keywords for consistency,
      # even if there were no splats passed in.
      old_keywords_accessed = splat.keywords_accessed
      keywords = splat.keywords
      splat.keywords_accessed = old_keywords_accessed

      begin
        unless keywords.empty?
          unknown_args = Sass::Util.array_minus(keywords.keys,
            callable.args.map {|var| var.first.underscored_name})
          if callable.splat && unknown_args.include?(callable.splat.underscored_name)
            raise Sass::SyntaxError.new("Argument $#{callable.splat.name} of #{downcase_desc} " +
                                        "cannot be used as a named argument.")
          elsif unknown_args.any?
            description = unknown_args.length > 1 ? 'the following arguments:' : 'an argument named'
            raise Sass::SyntaxError.new("#{desc} doesn't have #{description} " +
                                        "#{unknown_args.map {|name| "$#{name}"}.join ', '}.")
          end
        end
      rescue Sass::SyntaxError => keyword_exception
      end

      # If there's no splat, raise the keyword exception immediately. The actual
      # raising happens in the ensure clause at the end of this function.
      return if keyword_exception && !callable.splat

      splat_sep = :comma
      if splat
        args += splat.to_a
        splat_sep = splat.separator
      end

      if args.size > callable.args.size && !callable.splat
        extra_args_because_of_splat = splat && args.size - splat.to_a.size <= callable.args.size

        takes = callable.args.size
        passed = args.size
        message = "#{desc} takes #{takes} argument#{'s' unless takes == 1} " +
          "but #{passed} #{passed == 1 ? 'was' : 'were'} passed."
        raise Sass::SyntaxError.new(message) unless extra_args_because_of_splat
        # TODO: when the deprecation period is over, make this an error.
        Sass::Util.sass_warn("WARNING: #{message}\n" +
          environment.stack.to_s.gsub(/^/, " " * 8) + "\n" +
          "This will be an error in future versions of Sass.")
      end

      env = Sass::Environment.new(callable.environment)
      callable.args.zip(args[0...callable.args.length]) do |(var, default), value|
        if value && keywords.has_key?(var.name)
          raise Sass::SyntaxError.new("#{desc} was passed argument $#{var.name} " +
                                      "both by position and by name.")
        end

        value ||= keywords.delete(var.name)
        value ||= default && default.perform(env)
        raise Sass::SyntaxError.new("#{desc} is missing argument #{var.inspect}.") unless value
        env.set_local_var(var.name, value)
      end

      if callable.splat
        rest = args[callable.args.length..-1] || []
        arg_list = Sass::Script::Value::ArgList.new(rest, keywords, splat_sep)
        arg_list.options = env.options
        env.set_local_var(callable.splat.name, arg_list)
      end

      yield env
    rescue StandardError => e
    ensure
      # If there's a keyword exception, we don't want to throw it immediately,
      # because the invalid keywords may be part of a glob argument that should be
      # passed on to another function. So we only raise it if we reach the end of
      # this function *and* the keywords attached to the argument list glob object
      # haven't been accessed.
      #
      # The keyword exception takes precedence over any Sass errors, but not over
      # non-Sass exceptions.
      if keyword_exception &&
          !(arg_list && arg_list.keywords_accessed) &&
          (e.nil? || e.is_a?(Sass::SyntaxError))
        raise keyword_exception
      elsif e
        raise e
      end
    end

perform_splat(splat, performed_keywords, kwarg_splat, environment) click to toggle source

@api private @return [Sass::Script::Value::ArgList]

    # File lib/sass/tree/visitors/perform.rb, line 106
    def perform_splat(splat, performed_keywords, kwarg_splat, environment)
      args, kwargs, separator = [], nil, :comma

      if splat
        splat = splat.perform(environment)
        separator = splat.separator || separator
        if splat.is_a?(Sass::Script::Value::ArgList)
          args = splat.to_a
          kwargs = splat.keywords
        elsif splat.is_a?(Sass::Script::Value::Map)
          kwargs = arg_hash(splat)
        else
          args = splat.to_a
        end
      end
      kwargs ||= Sass::Util::NormalizedMap.new
      kwargs.update(performed_keywords)

      if kwarg_splat
        kwarg_splat = kwarg_splat.perform(environment)
        unless kwarg_splat.is_a?(Sass::Script::Value::Map)
          raise Sass::SyntaxError.new("Variable keyword arguments must be a map " +
                                      "(was #{kwarg_splat.inspect}).")
        end
        kwargs.update(arg_hash(kwarg_splat))
      end

      Sass::Script::Value::ArgList.new(args, kwargs, separator)
    end

visit(root, environment = nil) click to toggle source

@param root [Tree::Node] The root node of the tree to visit. @param environment [Sass::Environment] The lexical environment. @return [Tree::Node] The resulting tree of static nodes.

    # File lib/sass/tree/visitors/perform.rb, line 7
    def visit(root, environment = nil)
      new(environment).send(:visit, root)
    end

### Protected Instance Methods

visit(node) click to toggle source

If an exception is raised, this adds proper metadata to the backtrace.

    # File lib/sass/tree/visitors/perform.rb, line 156
    def visit(node)
      return super(node.dup) unless @environment
      @environment.stack.with_base(node.filename, node.line) {super(node.dup)}
    rescue Sass::SyntaxError => e
      e.modify_backtrace(:filename => node.filename, :line => node.line)
      raise e
    end

visit_atroot(node) click to toggle source

Sets a variable that indicates that the first level of rule nodes shouldn’t include the parent selector by default.

    # File lib/sass/tree/visitors/perform.rb, line 440
    def visit_atroot(node)
      if node.query
        parser = Sass::SCSS::StaticParser.new(run_interp(node.query),
          node.filename, node.options[:importer], node.line)
        node.resolved_type, node.resolved_value = parser.parse_static_at_root_query
      else
        node.resolved_type, node.resolved_value = :without, ['rule']
      end

      old_at_root_without_rule = @at_root_without_rule
      old_in_keyframes = @in_keyframes
      @at_root_without_rule = true if node.exclude?('rule')
      @in_keyframes = false if node.exclude?('keyframes')
      yield
    ensure
      @in_keyframes = old_in_keyframes
      @at_root_without_rule = old_at_root_without_rule
    end

visit_children(parent) click to toggle source

Keeps track of the current environment.

    # File lib/sass/tree/visitors/perform.rb, line 165
    def visit_children(parent)
      with_environment Sass::Environment.new(@environment, parent.options) do
        parent.children = super.flatten
        parent
      end
    end

visit_comment(node) click to toggle source

Removes this node from the tree if it’s a silent comment.

    # File lib/sass/tree/visitors/perform.rb, line 193
    def visit_comment(node)
      return [] if node.invisible?
      node.resolved_value = run_interp_no_strip(node.value)
      node.resolved_value.gsub!(/\\([\\#])/, '\1')
      node
    end

visit_content(node) click to toggle source

    # File lib/sass/tree/visitors/perform.rb, line 373
    def visit_content(node)
      content, content_env = @environment.content
      return [] unless content
      @environment.stack.with_mixin(node.filename, node.line, '@content') do
        trace_node = Sass::Tree::TraceNode.from_node('@content', node)
        content_env = Sass::Environment.new(content_env)
        content_env.caller = Sass::Environment.new(@environment)
        with_environment(content_env) do
          trace_node.children = content.map {|c| visit(c.dup)}.flatten
        end
        trace_node
      end
    rescue Sass::SyntaxError => e
      e.modify_backtrace(:mixin => '@content', :line => node.line)
      e.add_backtrace(:line => node.line)
      raise e
    end

visit_cssimport(node) click to toggle source

    # File lib/sass/tree/visitors/perform.rb, line 521
    def visit_cssimport(node)
      node.resolved_uri = run_interp([node.uri])
      if node.query && !node.query.empty?
        parser = Sass::SCSS::StaticParser.new(run_interp(node.query),
          node.filename, node.options[:importer], node.line)
        node.resolved_query ||= parser.parse_media_query_list
      end
      yield
    end

visit_debug(node) click to toggle source

Prints the expression to STDERR.

    # File lib/sass/tree/visitors/perform.rb, line 201
    def visit_debug(node)
      res = node.expr.perform(@environment)
      if res.is_a?(Sass::Script::Value::String)
        res = res.value
      else
        res = res.to_sass
      end
      if node.filename
        Sass::Util.sass_warn "#{node.filename}:#{node.line} DEBUG: #{res}"
      else
        Sass::Util.sass_warn "Line #{node.line} DEBUG: #{res}"
      end
      []
    end

visit_directive(node) click to toggle source

    # File lib/sass/tree/visitors/perform.rb, line 497
    def visit_directive(node)
      node.resolved_value = run_interp(node.value)
      old_in_keyframes, @in_keyframes = @in_keyframes, node.normalized_name == "@keyframes"
      with_environment Sass::Environment.new(@environment) do
        node.children = node.children.map {|c| visit(c)}.flatten
        node
      end
    ensure
      @in_keyframes = old_in_keyframes
    end

visit_each(node) click to toggle source

Runs the child nodes once for each value in the list.

    # File lib/sass/tree/visitors/perform.rb, line 228
    def visit_each(node)
      list = node.list.perform(@environment)

      with_environment Sass::SemiGlobalEnvironment.new(@environment) do
        list.to_a.map do |value|
          if node.vars.length == 1
            @environment.set_local_var(node.vars.first, value)
          else
            node.vars.zip(value.to_a) do |(var, sub_value)|
              @environment.set_local_var(var, sub_value || Sass::Script::Value::Null.new)
            end
          end
          node.children.map {|c| visit(c)}
        end.flatten
      end
    end

visit_error(node) click to toggle source

Throws the expression as an error.

    # File lib/sass/tree/visitors/perform.rb, line 217
    def visit_error(node)
      res = node.expr.perform(@environment)
      if res.is_a?(Sass::Script::Value::String)
        res = res.value
      else
        res = res.to_sass
      end
      raise Sass::SyntaxError.new(res)
    end

visit_extend(node) click to toggle source

Runs SassScript interpolation in the selector, and then parses the result into a {Sass::Selector::CommaSequence}.

    # File lib/sass/tree/visitors/perform.rb, line 247
    def visit_extend(node)
      parser = Sass::SCSS::StaticParser.new(run_interp(node.selector),
        node.filename, node.options[:importer], node.line)
      node.resolved_selector = parser.parse_selector
      node
    end

visit_for(node) click to toggle source

Runs the child nodes once for each time through the loop, varying the variable each time.

    # File lib/sass/tree/visitors/perform.rb, line 255
    def visit_for(node)
      from = node.from.perform(@environment)
      to = node.to.perform(@environment)
      from.assert_int!
      to.assert_int!

      to = to.coerce(from.numerator_units, from.denominator_units)
      direction = from.to_i > to.to_i ? -1 : 1
      range = Range.new(direction * from.to_i, direction * to.to_i, node.exclusive)

      with_environment Sass::SemiGlobalEnvironment.new(@environment) do
        range.map do |i|
          @environment.set_local_var(node.var,
            Sass::Script::Value::Number.new(direction * i,
              from.numerator_units, from.denominator_units))
          node.children.map {|c| visit(c)}
        end.flatten
      end
    end

visit_function(node) click to toggle source

Loads the function into the environment.

    # File lib/sass/tree/visitors/perform.rb, line 276
    def visit_function(node)
      env = Sass::Environment.new(@environment, node.options)

      if node.normalized_name == 'calc' || node.normalized_name == 'element' ||
          node.name == 'expression' || node.name == 'url'
        Sass::Util.sass_warn DEPRECATION WARNING on line #{node.line}#{" of #{node.filename}" if node.filename}:Naming a function "#{node.name}" is disallowed and will be an error in future versions of Sass.This name conflicts with an existing CSS function with special parse rules.
      end

      @environment.set_local_function(node.name,
        Sass::Callable.new(node.name, node.args, node.splat, env,
                           node.children, !:has_content, "function"))
      []
    end

visit_if(node) click to toggle source

Runs the child nodes if the conditional expression is true; otherwise, tries the else nodes.

    # File lib/sass/tree/visitors/perform.rb, line 296
    def visit_if(node)
      if node.expr.nil? || node.expr.perform(@environment).to_bool
        with_environment Sass::SemiGlobalEnvironment.new(@environment) do
          node.children.map {|c| visit(c)}
        end.flatten
      elsif node.else
        visit(node.else)
      else
        []
      end
    end

visit_import(node) click to toggle source

Returns a static DirectiveNode if this is importing a CSS file, or parses and includes the imported Sass file.

    # File lib/sass/tree/visitors/perform.rb, line 310
    def visit_import(node)
      if (path = node.css_import?)
        resolved_node = Sass::Tree::CssImportNode.resolved("url(#{path})")
        resolved_node.source_range = node.source_range
        return resolved_node
      end
      file = node.imported_file
      if @environment.stack.frames.any? {|f| f.is_import? && f.filename == file.options[:filename]}
        handle_import_loop!(node)
      end

      begin
        @environment.stack.with_import(node.filename, node.line) do
          root = file.to_tree
          Sass::Tree::Visitors::CheckNesting.visit(root)
          node.children = root.children.map {|c| visit(c)}.flatten
          node
        end
      rescue Sass::SyntaxError => e
        e.modify_backtrace(:filename => node.imported_file.options[:filename])
        e.add_backtrace(:filename => node.filename, :line => node.line)
        raise e
      end
    end

visit_media(node) click to toggle source

    # File lib/sass/tree/visitors/perform.rb, line 508
    def visit_media(node)
      parser = Sass::SCSS::StaticParser.new(run_interp(node.query),
        node.filename, node.options[:importer], node.line)
      node.resolved_query ||= parser.parse_media_query_list
      yield
    end

visit_mixin(node) click to toggle source

Runs a mixin.

    # File lib/sass/tree/visitors/perform.rb, line 345
    def visit_mixin(node)
      @environment.stack.with_mixin(node.filename, node.line, node.name) do
        mixin = @environment.mixin(node.name)
        raise Sass::SyntaxError.new("Undefined mixin '#{node.name}'.") unless mixin

        if node.children.any? && !mixin.has_content
          raise Sass::SyntaxError.new(%{Mixin "#{node.name}" does not accept a content block.})
        end

        args = node.args.map {|a| a.perform(@environment)}
        keywords = Sass::Util.map_vals(node.keywords) {|v| v.perform(@environment)}
        splat = self.class.perform_splat(node.splat, keywords, node.kwarg_splat, @environment)

        self.class.perform_arguments(mixin, args, splat, @environment) do |env|
          env.caller = Sass::Environment.new(@environment)
          env.content = [node.children, @environment] if node.has_children

          trace_node = Sass::Tree::TraceNode.from_node(node.name, node)
          with_environment(env) {trace_node.children = mixin.tree.map {|c| visit(c)}.flatten}
          trace_node
        end
      end
    rescue Sass::SyntaxError => e
      e.modify_backtrace(:mixin => node.name, :line => node.line)
      e.add_backtrace(:line => node.line)
      raise e
    end

visit_mixindef(node) click to toggle source

Loads a mixin into the environment.

    # File lib/sass/tree/visitors/perform.rb, line 336
    def visit_mixindef(node)
      env = Sass::Environment.new(@environment, node.options)
      @environment.set_local_mixin(node.name,
        Sass::Callable.new(node.name, node.args, node.splat, env,
                           node.children, node.has_content, "mixin"))
      []
    end

visit_prop(node) click to toggle source

Runs any SassScript that may be embedded in a property.

    # File lib/sass/tree/visitors/perform.rb, line 392
    def visit_prop(node)
      node.resolved_name = run_interp(node.name)
      val = node.value.perform(@environment)
      node.resolved_value = val.to_s
      node.value_source_range = val.source_range if val.source_range
      yield
    end

visit_return(node) click to toggle source

Returns the value of the expression.

    # File lib/sass/tree/visitors/perform.rb, line 401
    def visit_return(node)
      throw :_sass_return, node.expr.perform(@environment)
    end

visit_root(node) click to toggle source

Sets the options on the environment if this is the top-level root.

    # File lib/sass/tree/visitors/perform.rb, line 185
    def visit_root(node)
      yield
    rescue Sass::SyntaxError => e
      e.sass_template ||= node.template
      raise e
    end

visit_rule(node) click to toggle source

Runs SassScript interpolation in the selector, and then parses the result into a {Sass::Selector::CommaSequence}.

    # File lib/sass/tree/visitors/perform.rb, line 407
    def visit_rule(node)
      old_at_root_without_rule = @at_root_without_rule
      parser = Sass::SCSS::StaticParser.new(run_interp(node.rule),
        node.filename, node.options[:importer], node.line)
      if @in_keyframes
        keyframe_rule_node = Sass::Tree::KeyframeRuleNode.new(parser.parse_keyframes_selector)
        keyframe_rule_node.options = node.options
        keyframe_rule_node.line = node.line
        keyframe_rule_node.filename = node.filename
        keyframe_rule_node.source_range = node.source_range
        keyframe_rule_node.has_children = node.has_children
        with_environment Sass::Environment.new(@environment, node.options) do
          keyframe_rule_node.children = node.children.map {|c| visit(c)}.flatten
        end
        keyframe_rule_node
      else
        @at_root_without_rule = false
        node.parsed_rules ||= parser.parse_selector
        node.resolved_rules = node.parsed_rules.resolve_parent_refs(
          @environment.selector, !old_at_root_without_rule)
        node.stack_trace = @environment.stack.to_s if node.options[:trace_selectors]
        with_environment Sass::Environment.new(@environment, node.options) do
          @environment.selector = node.resolved_rules
          node.children = node.children.map {|c| visit(c)}.flatten
        end
        node
      end
    ensure
      @at_root_without_rule = old_at_root_without_rule
    end

visit_supports(node) click to toggle source

    # File lib/sass/tree/visitors/perform.rb, line 515
    def visit_supports(node)
      node.condition = node.condition.deep_copy
      node.condition.perform(@environment)
      yield
    end

visit_variable(node) click to toggle source

Loads the new variable value into the environment.

    # File lib/sass/tree/visitors/perform.rb, line 460
    def visit_variable(node)
      env = @environment
      env = env.global_env if node.global
      if node.guarded
        var = env.var(node.name)
        return [] if var && !var.null?
      end

      val = node.expr.perform(@environment)
      if node.expr.source_range
        val.source_range = node.expr.source_range
      else
        val.source_range = node.source_range
      end
      env.set_var(node.name, val)
      []
    end

visit_warn(node) click to toggle source

Prints the expression to STDERR with a stylesheet trace.

    # File lib/sass/tree/visitors/perform.rb, line 479
    def visit_warn(node)
      res = node.expr.perform(@environment)
      res = res.value if res.is_a?(Sass::Script::Value::String)
      msg = "WARNING: #{res}\n         "
      msg << @environment.stack.to_s.gsub("\n", "\n         ") << "\n"
      Sass::Util.sass_warn msg
      []
    end

visit_while(node) click to toggle source

Runs the child nodes until the continuation expression becomes false.

    # File lib/sass/tree/visitors/perform.rb, line 489
    def visit_while(node)
      children = []
      with_environment Sass::SemiGlobalEnvironment.new(@environment) do
        children += node.children.map {|c| visit(c)} while node.expr.perform(@environment).to_bool
      end
      children.flatten
    end

with_environment(env) click to toggle source

Runs a block of code with the current environment replaced with the given one.

@param env [Sass::Environment] The new environment for the duration of the block. @yield A block in which the environment is set to `env`. @return [Object] The return value of the block.

    # File lib/sass/tree/visitors/perform.rb, line 177
    def with_environment(env)
      old_env, @environment = @environment, env
      yield
    ensure
      @environment = old_env
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.