Sha256: 28b786052fddd6ee2352bf3055a43cd28307c13870f3da7f5e27a2ed4f8a5056

Contents?: true

Size: 921 Bytes

Versions: 14

Compression:

Stored size: 921 Bytes

Contents

module SCSSLint
  # Provides functionality for conveniently visiting a Selector sequence.
  module SelectorVisitor
    def visit_selector(node)
      visit_selector_node(node)
    end

  private

    def visit_selector_node(node)
      method = "visit_#{selector_node_name(node)}"
      send(method, node) if respond_to?(method, true)

      visit_members(node) if node.is_a?(Sass::Selector::AbstractSequence)
    end

    def visit_members(sequence)
      sequence.members.each do |member|
        visit_selector(member)
      end
    end

    def selector_node_name(node)
      # Converts the class name of a node into snake_case form, e.g.
      # `Sass::Selector::SimpleSequence` -> `simple_sequence`
      node.class.name.gsub(/.*::(.*?)$/, '\\1')
                      .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
                      .gsub(/([a-z\d])([A-Z])/, '\1_\2')
                      .downcase
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
scss-lint-0.32.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.31.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.30.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.29.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.28.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.27.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.26.2 lib/scss_lint/selector_visitor.rb
scss-lint-0.26.1 lib/scss_lint/selector_visitor.rb
scss-lint-0.26.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.25.1 lib/scss_lint/selector_visitor.rb
scss-lint-0.25.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.24.1 lib/scss_lint/selector_visitor.rb
scss-lint-0.24.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.23.1 lib/scss_lint/selector_visitor.rb