Created
August 6, 2012 17:24
-
-
Save pigoz/3276913 to your computer and use it in GitHub Desktop.
composite-pattern-navigation menu
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
module ApplicationHelper | |
## ..snip | |
def build_taxon_subtree(root) | |
tree = Navigation::Tree("#{root.permalink}", root.name) | |
Spree::Taxon.where(:parent_id => root.id).all.each do |taxon| | |
count = Spree::Taxon.where(:parent_id => taxon.id).count | |
if count > 0 | |
tree.add(build_taxon_subtree(taxon)) | |
else | |
tree.add_leaf(taxon.name, seo_url(taxon)) | |
end | |
end | |
tree | |
end | |
def navigation_tree | |
root_catalogue, root_categories = \ | |
[Config::TAXONS[:catalogue], Config::TAXONS[:categories]].map do |ident| | |
Spree::Taxon.find_by_permalink!(ident) | |
end | |
Navigation::Root("main-menu").tap {|t| | |
t.add_leaf t('navbar.home'), root_path | |
Spree::Taxon.where(:parent_id => root_categories.id).all.each do |taxon| | |
t.add_leaf taxon.name, seo_url(taxon) | |
end | |
t.add build_taxon_subtree(root_catalogue) | |
t.add_leaf t('navbar.digital_store'), '/cms/digital_store' | |
t.add_leaf t('navbar.bookshop'), "/cms/bookshop" | |
t.add_leaf t('navbar.club'), "/cms/club" | |
t.add_leaf t('navbar.exibitions'), "/cms/exibitions", "separated" | |
t.add_leaf t('navbar.partners'), "/cms/partners", "separated" | |
t.add_leaf t('navbar.contact_us'), "/cms/contact_us", "separated" | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment