Skip to content

Instantly share code, notes, and snippets.

@kevinpfromnm
Created August 19, 2011 17:51
Show Gist options
  • Save kevinpfromnm/1157477 to your computer and use it in GitHub Desktop.
Save kevinpfromnm/1157477 to your computer and use it in GitHub Desktop.
dryml tag wrapping for jquery accordion widget
<!-- Expects a hash: with keys for the accordion divisions -> values an option list appropriate for tag
default tag is select-one-radio for belongs_to and check-many for other contexts
example usage: <hjq-accordion options="&Location.all.group_by(&:country)" /> provides an accordion with
check-many checkboxes grouped by country name if the context is a has_many :locations, :through ... type
of association.
-->
<def tag="hjq-accordion" attrs="id, options, tag"><%
id ||= "accordion"
tag ||= if (refl = this_field_reflection)
if refl.macro == :belongs_to
"select-one-radio"
else
"check-many"
end
end -%>>
<script>
jQuery(function() {
jQuery( "#<%= id %>" ).accordion();
});
</script>
<div id="#{id}">
<% for option in options.keys do -%>
<h3 param="accordion-heading"><a href="#"><%= option %></a></h3>
<div>
<call-tag tag="&tag" param="#{option}.sub(&apos;?&apos;, &apos;&apos;).sub(&apos;.&apos;, &apos;-&apos;)}-tag" options="&options[option]" selected="this" merge />
</div>
<% end -%>
</div>
</def>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment