S
S
Skrolea2017-03-28 14:41:50
Pug
Skrolea, 2017-03-28 14:41:50

How to pass icon name to mixin?

Good afternoon.
I want to make a button mixin, which as a result will accept either text or an icon as input.

mixin button(spec)
 - spec = spec || {}
 - spec.__class = spec.__class || 'btn'
 - spec.text = spec.text || ''
  button(class=spec.__class)&attributes(attributes)
     span=spec.text

Accordingly, I invoke it
+button({__class:'btn btn-primary',text:'Читать'})
+button({__class:'btn-fab',text:'i.material-icons add'})

But since I'm passing the text (i.material-icons add) to the span, it comes out as text. What to do in this case?
Add one more parameter specifically for fab somehow or some kind of condition?
Example on codepen

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2017-03-28
@Skrolea

No, everything is easier if you carefully read the documentation :

mixin button(spec)
    - spec = spec || {}
    - spec.__class = spec.__class || 'btn'
    - spec.text = spec.text || ''
    button(class=spec.__class)&attributes(attributes)
        if block
            block
        else
            span=spec.text

+button({__class:'btn btn-primary', text:'Читать'})
+button({__class:'btn-fab'})
    i.material-icons add

In principle, the text parameter can be abandoned altogether.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question