Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

adding a especial attribute _dynamic #65

Open
wants to merge 1 commit into from

1 participant

@rhuelga

for example using it one can make options be selected or not dynamically by this way:

  • var dyn = { selected:'selected', checked: false } %option{value:"spain", _dynamic:dyn} some text

will produce

some text

Kanzeon Adding dynamic attributes to tags by using a especial attribute _dynamic
using it one can make options be selected or not by this way:

- var dyn = { selected:'selected', checked: false }
%option{value:"spain", _dynamic:dyn}
  some text

will produce

<option value="spain" selected="selected">some text</option>
b3ea94f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 5, 2012
  1. Adding dynamic attributes to tags by using a especial attribute _dynamic

    Kanzeon authored
    using it one can make options be selected or not by this way:
    
    - var dyn = { selected:'selected', checked: false }
    %option{value:"spain", _dynamic:dyn}
      some text
    
    will produce
    
    <option value="spain" selected="selected">some text</option>
This page is out of date. Refresh to see the latest.
View
8 lib/haml.js
@@ -13,8 +13,14 @@ var Haml;
}
function render_attribs(attribs) {
- var key, value, result = [];
+ var key, value, result = [], b, d;
for (key in attribs) {
+ if ( key == '_dynamic' ) {
+ d = attribs[key];
+ result.push( '"; for(k in ' + d + '){ if('+ d + '[k]){ _$output = _$output + " " + k + "=\\"" +' +
+ d + '[k] + "\\""; }}; _$output = _$output + "');
+ continue;
+ }
if (key !== '_content' && attribs.hasOwnProperty(key)) {
switch (attribs[key]) {
case 'undefined':
View
3  test/dynamic_attribs.haml
@@ -0,0 +1,3 @@
+- var dy = { checked: false, selected: 'selected' }
+%option{name:"the-option", _dynamic:dy }
+ the option label
View
1  test/dynamic_attribs.html
@@ -0,0 +1 @@
+<option name="the-option" selected="selected">the option label</option>
Something went wrong with that request. Please try again.