### Home Classes Methods

### In Files

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

### Parent

Object

### Methods

- ::visit
- #node_name
- #visit
- #visit_children
- #visit_if

### Class/Module Index

Quicksearch

- Sass
- 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::Generic
- Sass::Exec::Sass
- Sass::Exec::SassConvert
- Sass::Exec::Scss
- 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::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::ArgList
- Sass::Script::Bool
- Sass::Script::Color
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Interpolation
- Sass::Script::Lexer
- Sass::Script::List
- Sass::Script::Literal
- Sass::Script::Node
- Sass::Script::Null
- Sass::Script::Number
- Sass::Script::Operation
- Sass::Script::Parser
- Sass::Script::String
- Sass::Script::StringInterpolation
- Sass::Script::UnaryOperation
- Sass::Script::Variable
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Interpolation
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::SelectorPseudoClass
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::Shared
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- 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::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::MultibyteStringScanner
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object

No matching classes.

# Sass::Tree::Visitors::Base

The abstract base class for Sass visitors. Visitors should extend this class, then implement `visit_*` methods for each node they care about (e.g. `visit_rule` for {RuleNode} or `visit_for` for {ForNode}). These methods take the node in question as argument. They may `yield` to visit the child nodes of the current node.

Note: due to the unusual nature of {Sass::Tree::IfNode}, special care must be taken to ensure that it is properly handled. In particular, there is no built-in scaffolding for dealing with the return value of `@else` nodes.

@abstract

### Constants

NODE_NAME_RE

### Public Class Methods

visit(root) click to toggle source

Runs the visitor on a tree.

@param root [Tree::Node] The root node of the Sass tree. @return [Object] The return value of {#visit} for the root node.

    # File lib/sass/tree/visitors/base.rb, line 23
    def self.visit(root)
      new.send(:visit, root)
    end

### Protected Instance Methods

node_name(node) click to toggle source

Returns the name of a node as used in the `visit_*` method.

@param [Tree::Node] node The node. @return [String] The name.

    # File lib/sass/tree/visitors/base.rb, line 62
    def node_name(node)
      @@node_names ||= {}
      @@node_names[node.class.name] ||= node.class.name.gsub(NODE_NAME_RE, '\1').downcase
    end

visit(node) click to toggle source

Runs the visitor on the given node. This can be overridden by subclasses that need to do something for each node.

@param node [Tree::Node] The node to visit. @return [Object] The return value of the `visit_*` method for this node.

    # File lib/sass/tree/visitors/base.rb, line 34
    def visit(node)
      method = "visit_#{node_name node}"
      if self.respond_to?(method, true)
        self.send(method, node) {visit_children(node)}
      else
        visit_children(node)
      end
    end

visit_children(parent) click to toggle source

Visit the child nodes for a given node. This can be overridden by subclasses that need to do something with the child nodes' return values.

This method is run when `visit_*` methods `yield`, and its return value is returned from the `yield`.

@param parent [Tree::Node] The parent node of the children to visit. @return [Array<Object>] The return values of the `visit_*` methods for the children.

    # File lib/sass/tree/visitors/base.rb, line 52
    def visit_children(parent)
      parent.children.map {|c| visit(c)}
    end

visit_if(node) click to toggle source

`yield`s, then runs the visitor on the `@else` clause if the node has one. This exists to ensure that the contents of the `@else` clause get visited.

    # File lib/sass/tree/visitors/base.rb, line 69
    def visit_if(node)
      yield
      visit(node.else) if node.else
      node
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.