creationix / haml-js

Haml ported to server-side Javascript. This is a traditional server-side templating language. Tested with node-js
MIT License
902 stars 110 forks source link

Added optional attributes #73

Closed ttp closed 8 years ago

ttp commented 11 years ago

Usage:

%input{checked?: model.isChecked(), disabled?: model.isDisabled()}
%input{checked?: model.isChecked(), readonly?: model.isChangable()}

this adds these attributes only if model returns "not false" value

For now I have to duplicate such blocks with combinations of these attributes

:if (model.isChecked())
  %input{type: "checkbox", ..., checked: true}
:else
  %input{type: "checkbox", ...}
aaronblohowiak commented 11 years ago

please add tests.

ttp commented 11 years ago

@aaronblohowiak tests added

dblock commented 11 years ago

+1 this is super useful

bogn commented 11 years ago

It's definitely needed functionality. Adding CSS classes depending on some conditions is even more important. This really shouldn't be necessary:

            :if (app.identifier === App.Configuration.app_id)
              %li.active
                %a(href=app.url)= app.name
            :else
              %li
                %a(href=app.url)= app.name

and it will get out of hand quickly when the markup get's more complex.