Skip to content

Instantly share code, notes, and snippets.

@al2o3cr
Created September 12, 2009 21:39
Show Gist options
  • Save al2o3cr/185988 to your computer and use it in GitHub Desktop.
Save al2o3cr/185988 to your computer and use it in GitHub Desktop.
<def tag="js-wrapper" attrs="convert">
<set-scoped vals="&[]">
<do param="default" />
<% if convert %>
<%= "[#{scope.vals.*.inspect.join(', ')}]" %>
<% else %>
<% scope.retval = scope.vals %>
<% end %>
</set-scoped>
</def>
<def tag="hash-param" attrs="key">
<set-scoped retval="">
<% value = parameters.default %>
<% value = scope.retval if value.blank? %>
<% scope.vals << Hash[key, value] %>
</set-scoped>
</def>
<def tag="array-param">
<set-scoped retval="">
<% value = parameters.default %>
<% value = scope.retval if value.blank? %>
<% scope.vals << value %>
</set-scoped>
</def>
<js-wrapper convert>
<array-param>Foo</array-param>
<hash-param key="Bar">Baz</hash-param>
<array-param>Blah</array-param>
<hash-param key="more">
<js-wrapper>
<array-param>Foo2</array-param>
<hash-param key="Bar2">Baz2</hash-param>
<array-param>
<js-wrapper>
<hash-param key="Bar3">Baz3</hash-param>
<array-param>Blah4</array-param>
</js-wrapper>
</array-param>
</js-wrapper>
</hash-param>
</js-wrapper>
Result:
["Foo", {"Bar"=>"Baz"}, "Blah", {"more"=>["Foo2", {"Bar2"=>"Baz2"}, [{"Bar3"=>"Baz3"}, "Blah4"]]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment