Sha256: f85e8e4d2b04f5d5e9d28af72e6ba4b873cd86e0356258fab6cf822d171632a4

Contents?: true

Size: 1.01 KB

Versions: 13

Compression:

Stored size: 1.01 KB

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
              .reject { |member| member.is_a?(String) } # Skip newlines in multi-line comma seqs
              .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

13 entries across 13 versions & 3 rubygems

Version Path
scss_lint-0.41.0 lib/scss_lint/selector_visitor.rb
scss_lint-0.40.1 lib/scss_lint/selector_visitor.rb
scss_lint-0.40.0 lib/scss_lint/selector_visitor.rb
scss_lint-0.39.0 lib/scss_lint/selector_visitor.rb
scss_lint-0.38.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.38.0 lib/scss_lint/selector_visitor.rb
scss-lint-bliss-1.0.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.37.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.36.1 lib/scss_lint/selector_visitor.rb
scss-lint-0.36.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.35.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.34.0 lib/scss_lint/selector_visitor.rb
scss-lint-0.33.0 lib/scss_lint/selector_visitor.rb