Created
August 19, 2011 17:51
-
-
Save kevinpfromnm/1157477 to your computer and use it in GitHub Desktop.
dryml tag wrapping for jquery accordion widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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('?', '').sub('.', '-')}-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