Sha256: d2d0745d570fc37b54ef0031a3432a173e6a50caee0098a7871cb50ec67be42a
Contents?: true
Size: 1007 Bytes
Versions: 3
Compression:
Stored size: 1007 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 .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` name = node.class.name.gsub(/.*::(.*?)$/, '\\1') name.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') name.gsub!(/([a-z\d])([A-Z])/, '\1_\2') name.downcase! end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
scss_lint-0.42.2 | lib/scss_lint/selector_visitor.rb |
scss_lint-0.42.1 | lib/scss_lint/selector_visitor.rb |
scss_lint-0.42.0 | lib/scss_lint/selector_visitor.rb |