Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type = (item) ->
- Object::toString.call(item)[8...-1].toLowerCase()
- toDash = (string) ->
- string.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()
- split = (string) ->
- string = string.trim()
- pattern = /('[^']+'|"[^"]+"|[^,]+)/g
- matches = string.match pattern
- match.trim() for match in matches
- module.exports.css = css = (stylesheet, object=false) ->
- output = {} # keys: selectors, values: property-value object
- for selector, kvs of stylesheet
- output[selector] = {}
- for k, v of kvs
- if type(v) isnt "object"
- output[selector][toDash(k)] = v
- else
- rule = {}
- rule[k] = v
- for selector_, kvs_ of css(rule, true)
- selectors = split(selector)
- selector_s = split(selector_)
- combined_selectors = []
- for k1 in selectors
- for k2 in selector_s
- if "&" in k2
- key = k2.replace "&", k1
- else
- key = "#{k1} #{k2}"
- combined_selectors.push key
- output[combined_selectors.join " , "] = kvs_
- if object
- output
- else
- lines = JSON.stringify(output, undefined, 2).split "\n"
- (line[2..] for line in lines[1...-1]).join("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement