### Home Classes Methods

### In Files

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

### Parent

Sass::Tree::Visitors::Base

### Namespace

- CLASS Sass::Tree::Visitors::Cssize::Bubble

### Methods

- ::new
- ::visit
- #parent
- #visit
- #visit_atroot
- #visit_children
- #visit_children_without_parent
- #visit_directive
- #visit_extend
- #visit_import
- #visit_keyframerule
- #visit_media
- #visit_prop
- #visit_root
- #visit_rule
- #visit_supports
- #visit_trace
- #with_parent

### 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::Cssize

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

### Constants

Extend

  A simple struct wrapping up information about a single `@extend` instance. A single {ExtendNode} can have multiple Extends if either the parent node or the extended selector is a comma sequence.

  @attr extender [Sass::Selector::Sequence]

      The selector of the CSS rule containing the `@extend`.

  @attr target [Array<Sass::Selector::Simple>] The selector being `@extend`ed. @attr node [Sass::Tree::ExtendNode] The node that produced this extend. @attr directives [Array<Sass::Tree::DirectiveNode>]

      The directives containing the `@extend`.

  @attr result [Symbol]

      The result of this extend. One of `:not_found` (the target doesn't exist
      in the document), `:failed_to_unify` (the target exists but cannot be
      unified with the extender), or `:succeeded`.

### Public Class Methods

new() click to toggle source

    # File lib/sass/tree/visitors/cssize.rb, line 16
    def initialize
      @parents = []
      @extends = Sass::Util::SubsetMap.new
    end

visit(root) click to toggle source

@param root [Tree::Node] The root node of the tree to visit. @return [(Tree::Node, Sass::Util::SubsetMap)] The resulting tree of static nodes

    *and* the extensions defined for this tree

    # File lib/sass/tree/visitors/cssize.rb, line 6
    def self.visit(root); super; end

### Protected Instance Methods

parent() click to toggle source

Returns the immediate parent of the current node. @return [Tree::Node]

    # File lib/sass/tree/visitors/cssize.rb, line 12
    def parent
      @parents.last
    end

visit(node) click to toggle source

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

    # File lib/sass/tree/visitors/cssize.rb, line 22
    def visit(node)
      super(node)
    rescue Sass::SyntaxError => e
      e.modify_backtrace(:filename => node.filename, :line => node.line)
      raise e
    end

visit_atroot(node) click to toggle source

    # File lib/sass/tree/visitors/cssize.rb, line 168
    def visit_atroot(node)
      # If there aren't any more directives or rules that this @at-root needs to
      # exclude, we can get rid of it and just evaluate the children.
      if @parents.none? {|n| node.exclude_node?(n)}
        results = visit_children_without_parent(node)
        results.each {|c| c.tabs += node.tabs if bubblable?(c)}
        if !results.empty? && bubblable?(results.last)
          results.last.group_end = node.group_end
        end
        return results
      end

      # If this @at-root excludes the immediate parent, return it as-is so that it
      # can be bubbled up by the parent node.
      return Bubble.new(node) if node.exclude_node?(parent)

      # Otherwise, duplicate the current parent and move it into the @at-root
      # node. As above, returning an @at-root node signals to the parent directive
      # that it should be bubbled upwards.
      bubble(node)
    end

visit_children(parent) click to toggle source

Keeps track of the current parent node.

    # File lib/sass/tree/visitors/cssize.rb, line 30
    def visit_children(parent)
      with_parent parent do
        parent.children = visit_children_without_parent(parent)
        parent
      end
    end

visit_children_without_parent(node) click to toggle source

Like {visit_children}, but doesn’t set {parent}.

@param node [Sass::Tree::Node] @return [Array<Sass::Tree::Node>] the flattened results of

    visiting all the children of `node`

    # File lib/sass/tree/visitors/cssize.rb, line 42
    def visit_children_without_parent(node)
      node.children.map {|c| visit(c)}.flatten
    end

visit_directive(node) click to toggle source

Bubbles a directive up through RuleNodes.

    # File lib/sass/tree/visitors/cssize.rb, line 223
    def visit_directive(node)
      return node unless node.has_children
      if parent.is_a?(Sass::Tree::RuleNode)
        # @keyframes shouldn't include the rule nodes, so we manually create a
        # bubble that doesn't have the parent's contents for them.
        return node.normalized_name == '@keyframes' ? Bubble.new(node) : bubble(node)
      end

      yield

      # Since we don't know if the mere presence of an unknown directive may be
      # important, we should keep an empty version around even if all the contents
      # are removed via @at-root. However, if the contents are just bubbled out,
      # we don't need to do so.
      directive_exists = node.children.any? do |child|
        next true unless child.is_a?(Bubble)
        next false unless child.node.is_a?(Sass::Tree::DirectiveNode)
        child.node.resolved_value == node.resolved_value
      end

      # We know empty @keyframes directives do nothing.
      if directive_exists || node.name == '@keyframes'
        []
      else
        empty_node = node.dup
        empty_node.children = []
        [empty_node]
      end + debubble(node.children, node)
    end

visit_extend(node) click to toggle source

Registers an extension in the `@extends` subset map.

    # File lib/sass/tree/visitors/cssize.rb, line 125
    def visit_extend(node)
      parent.resolved_rules.populate_extends(@extends, node.resolved_selector, node,
        @parents.select {|p| p.is_a?(Sass::Tree::DirectiveNode)})
      []
    end

visit_import(node) click to toggle source

Modifies exception backtraces to include the imported file.

    # File lib/sass/tree/visitors/cssize.rb, line 132
    def visit_import(node)
      visit_children_without_parent(node)
    rescue Sass::SyntaxError => e
      e.modify_backtrace(:filename => node.children.first.filename)
      e.add_backtrace(:filename => node.filename, :line => node.line)
      raise e
    end

visit_keyframerule(node) click to toggle source

    # File lib/sass/tree/visitors/cssize.rb, line 214
    def visit_keyframerule(node)
      return node unless node.has_children

      yield

      debubble(node.children, node)
    end

visit_media(node) click to toggle source

Bubbles the `@media` directive up through RuleNodes and merges it with other `@media` directives.

    # File lib/sass/tree/visitors/cssize.rb, line 255
    def visit_media(node)
      return bubble(node) if parent.is_a?(Sass::Tree::RuleNode)
      return Bubble.new(node) if parent.is_a?(Sass::Tree::MediaNode)

      yield

      debubble(node.children, node) do |child|
        next child unless child.is_a?(Sass::Tree::MediaNode)
        # Copies of `node` can be bubbled, and we don't want to merge it with its
        # own query.
        next child if child.resolved_query == node.resolved_query
        next child if child.resolved_query = child.resolved_query.merge(node.resolved_query)
      end
    end

visit_prop(node) click to toggle source

Converts nested properties into flat properties and updates the indentation of the prop node based on the nesting level.

    # File lib/sass/tree/visitors/cssize.rb, line 151
    def visit_prop(node)
      if parent.is_a?(Sass::Tree::PropNode)
        node.resolved_name = "#{parent.resolved_name}-#{node.resolved_name}"
        node.tabs = parent.tabs + (parent.resolved_value.empty? ? 0 : 1) if node.style == :nested
      end

      yield

      result = node.children.dup
      if !node.resolved_value.empty? || node.children.empty?
        node.send(:check!)
        result.unshift(node)
      end

      result
    end

visit_root(node) click to toggle source

In Ruby 1.8, ensures that there’s only one `@charset` directive and that it’s at the top of the document.

@return [(Tree::Node, Sass::Util::SubsetMap)] The resulting tree of static nodes

    *and* the extensions defined for this tree

    # File lib/sass/tree/visitors/cssize.rb, line 64
    def visit_root(node)
      yield

      if parent.nil?
        # In Ruby 1.9 we can make all @charset nodes invisible
        # and infer the final @charset from the encoding of the final string.
        if Sass::Util.ruby1_8?
          charset = node.children.find {|c| c.is_a?(Sass::Tree::CharsetNode)}
          node.children.reject! {|c| c.is_a?(Sass::Tree::CharsetNode)}
          node.children.unshift charset if charset
        end

        imports_to_move = []
        import_limit = nil
        i = -1
        node.children.reject! do |n|
          i += 1
          if import_limit
            next false unless n.is_a?(Sass::Tree::CssImportNode)
            imports_to_move << n
            next true
          end

          if !n.is_a?(Sass::Tree::CommentNode) &&
              !n.is_a?(Sass::Tree::CharsetNode) &&
              !n.is_a?(Sass::Tree::CssImportNode)
            import_limit = i
          end

          false
        end

        if import_limit
          node.children = node.children[0...import_limit] + imports_to_move +
            node.children[import_limit..-1]
        end
      end

      return node, @extends
    rescue Sass::SyntaxError => e
      e.sass_template ||= node.template
      raise e
    end

visit_rule(node) click to toggle source

Updates the indentation of the rule node based on the nesting level. The selectors were resolved in {Perform}.

    # File lib/sass/tree/visitors/cssize.rb, line 195
    def visit_rule(node)
      yield

      rules = node.children.select {|c| bubblable?(c)}
      props = node.children.reject {|c| bubblable?(c) || c.invisible?}

      unless props.empty?
        node.children = props
        rules.each {|r| r.tabs += 1} if node.style == :nested
        rules.unshift(node)
      end

      rules = debubble(rules)
      unless parent.is_a?(Sass::Tree::RuleNode) || rules.empty? || !bubblable?(rules.last)
        rules.last.group_end = true
      end
      rules
    end

visit_supports(node) click to toggle source

Bubbles the `@supports` directive up through RuleNodes.

    # File lib/sass/tree/visitors/cssize.rb, line 271
    def visit_supports(node)
      return node unless node.has_children
      return bubble(node) if parent.is_a?(Sass::Tree::RuleNode)

      yield

      debubble(node.children, node)
    end

visit_trace(node) click to toggle source

Asserts that all the traced children are valid in their new location.

    # File lib/sass/tree/visitors/cssize.rb, line 141
    def visit_trace(node)
      visit_children_without_parent(node)
    rescue Sass::SyntaxError => e
      e.modify_backtrace(:mixin => node.name, :filename => node.filename, :line => node.line)
      e.add_backtrace(:filename => node.filename, :line => node.line)
      raise e
    end

with_parent(parent) click to toggle source

Runs a block of code with the current parent node replaced with the given node.

@param parent [Tree::Node] The new parent for the duration of the block. @yield A block in which the parent is set to `parent`. @return [Object] The return value of the block.

    # File lib/sass/tree/visitors/cssize.rb, line 52
    def with_parent(parent)
      @parents.push parent
      yield
    ensure
      @parents.pop
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.