Skip to content

Instantly share code, notes, and snippets.

@fastdivision
Created February 20, 2013 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fastdivision/5000379 to your computer and use it in GitHub Desktop.
Save fastdivision/5000379 to your computer and use it in GitHub Desktop.
Scouter snippets
for selector in str.split(/[\s,+~>]+/)
# IDs
a = selectors.filter((element) -> element.indexOf('#') != -1)
# Classes, Attributes, Pseudo-Classes
b = selectors.filter((element) ->
element.match(/\[.+\]|(\.|:)[_a-zA-Z0-9-]/)?.length && element.indexOf('::') == -1
)
selectors = selectors.filter (i) -> !(a.concat(b).indexOf(i) > -1)
# Type Selectors, Pseudo-Elements
c = selectors
matches = selector.match(/\[.+\]|(#|\.|::|:)[_a-zA-Z0-9-]*|[_a-zA-Z0-9-]*/gi)
if matches
for match in matches
match = match.replace(/:not|\(|\)/gi, '')
selectors.push(match) if match.length
else
selectors.push(selector)
score = parseInt("#{a.length}#{b.length}#{c.length}", 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment