pug - Passing Jade Mixins as Parameters to other Jade Mixins -
i'm designing website client using principles of atomic design. i'm creating organism may contain different molecules within it. question is, can organism take molecule mixins arguments? this, example:
molecule1
mixin molecule-1(args) .somediv(class= args.class) p= args.text
molecule2
mixin molecule-2(args) .someotherdiv(class= args.class) p= args.text a(href='#')= args.linktext
organism
mixin organism(slides) include path/to/molecule-1.jade include path/to/molecule-2.jade .container each slide in slides slide
page
include path/to/organism.jade include path/to/molecule-1.jade include path/to/organism.jade +organism({slides:[+molecule-1({class: 'someclass', text: 'sometext'}), +molecule-2({class: 'someotherclass', text: 'sometext', linktext: 'somelink'})]})
which yield
<div class='container'> <div class='somediv someclass'> <p>sometext</p> </div> <div class='someotherdiv someotherclass'> <p>sometext</p> <a href='#'>somelink</a> </div> </div>
or have pass in each individual attribute organism so:
organism
mixin organism(slides) include path/to/molecule-1.jade include path/to/molecule-2.jade .container each slide in slides if slide.type === 'molecule1' +molecule-1({class: slide.class, text: slide.text}) else if slide.type === 'molecule2' +molecule-2({class: slide.class, text: slide.text, linktext: slide.linktext})
in other words, there more elegant solution problem latter way of doing things?
here's got work. think need if
statement in organism
figure out molecule render, , type
attribute in each object, can pass object straight appropriate molecule mixin.
you can use rest arguments syntax (...slides) pass in unspecified number of arguments.
include path/to/molecule-1.jade include path/to/molecule-2.jade mixin organism(...slides) .container each slide in slides if slide.type == "m1" +molecule-1(slide) else if slide.type == "m2" +molecule-2(slide) +organism({type:"m1", class:"class1", text:"some text"}, {type:"m2", class:"class2", text:"some more text", linktext:"link"})
you can make organism
call little more readable splitting out molecule objects variables if want.
- var moleculeobj1 = {type:"m1", class:"class1", text:"some text"}; - var moleculeobj2 = {type:"m2", class:"class2", text:"some more text", linktext:"link"}; +organism(moleculeobj1, moleculeobj2)
Comments
Post a Comment