Looking for solution how to use SMACSS naming convention with jade, haml or slim template engine.
Expect following jade code :
.module
.child
.child
as output i'll get following:
<div class="module">
<div class="child"></div>
<div class="child"></div>
</div>
but i'd like to reach following result:
<div class="module">
<div class="module-child"></div>
<div class="module-child"></div>
</div>
is there any solution to manage it like i can do it in SASS for example, i mean avoid adding 'module-' string to each 'child' manually ?
UPDATE
Also acceptable solutions with Haml and Slim
This is the closest I got with jade (live playground here):
A mixin named
e
will output an element taken as a parameter (default isdiv
) with its attributes and content as is, except for the first class that'll be prefixed with the value of the variableparent
(or will be the value ofparent
itself if it hasn't any class)I prefer using default jade syntax for attributes, including class and id than passing many parameters to a mixin (this one doesn't need any if it's a div, as with
.sth text
'd output<div class="sth>text</div>
and+e.sth text
will output<div class="parent-sth>text</div>
)Mixin would be shorter if it didn't have to deal with other attributes (href, id, data-*, role, etc) Remaining problem: changing the value of
parent
has no effect when it's indented. It had with simpler previous attempts so I guess it's related to scope of variables. You theoretically don't want to change the prefix for child elements but in practice... Maybe as a second optional parameter?Things I had problem with while playing with jade:
&attributes(attributes)
. Thanks to jade-book issue on GitHubdelete
) in a place it'd be executed by jade