Skip to content

Instantly share code, notes, and snippets.

@yamadapc
Last active August 29, 2015 13:57
Show Gist options
  • Save yamadapc/9836055 to your computer and use it in GitHub Desktop.
Save yamadapc/9836055 to your computer and use it in GitHub Desktop.
I'm just playing with stylus; it's funny markup is the kind of thing which *should* be as dynamic as possible :P
/**
* Sets a selector to a variable.
*
* @example
*
* font-size-h1 = 10px
* from-variable(h1, font-size)
*
* would yield:
*
* h1 {
* font-size: 10px
* }
*
* The following would also result in the same CSS:
* // when the variable is != than the attribute
* fs-h1 = 10px
* from-variable(h1, font-size, variable: fs)
*
* // when the posfix is diferent from the selector
* font-size-something = 10px
* from-variable(h1, font-size, posfix: 'something')
*
* // when things are weird (here the selector would be h1, .h1)
* fs-something = 10px
* from-variable('h1, .h1', font-size, fs, 'something')
*/
from-variable(selector, attribute, variable=attribute, posfix=null)
value = variable + '-' + posfix // i.e. font-size + '-' + h1
{selector}
{attribute}: value
@yamadapc
Copy link
Author

... but... maybe I'm going against the flow...

I want programming to be static and markup to be dynamic o.O

@yamadapc
Copy link
Author

this could easily be a mixin too

with some clever seletor() hack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment