You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 18, 2021. It is now read-only.
Started using CCSS in a CoffeeScript framework i'm building (https://github.com/jussiry/houCe), and added some new features to it:
# multiselectors:
'div, li': ... -> div: ...
li: ...
div_and_li: ... -> div: ...
li: ...
# i_ (id) and c_ (class) prefixes to avoid typing strings:
i_name: ... -> '#name': ...
c_name: ... -> '.name': ...
# underscores as hyphens, as suggested in the other issue:
font_size: ... -> 'font-size': ...
And here's the iterator that adds these features:
ccss_extras = (obj)->
for orig_key, val of obj
ccss_extras val if typeof val is 'object'
# split multi definitions:
keys = orig_key.split(/,|_and_/).map('trim')
keys.each (k)->
# change i_plaa to '#plaa' and c_plaa to '.plaa'
if k[0..1] is 'i_' then k = '#'+k[2..-1]
else if k[0..1] is 'c_' then k = '.'+k[2..-1]
# font_size to font-size
if typeof val isnt 'object'
k = k.replace(/_/g,'-')
# set new key and delete old:
if k isnt orig_key
if typeof val is 'object'
obj[k] ?= {}
obj[k].merge val
else
obj[k] = val
delete obj[orig_key]
obj
Notice that the code uses merge function from Sugar.js. You can replace that with extend from JQuery or Underscore, if those are the libraries of your choice.