Created
June 27, 2012 15:44
-
-
Save robyurkowski/3004935 to your computer and use it in GitHub Desktop.
Customizing Menus in RefineryCMS 2.0
This file contains hidden or 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
::Refinery::Page.class_eval do | |
MENU_LOCATIONS = %w(utility main footer about) | |
validates :menu_location, :inclusion => {:in => MENU_LOCATIONS}, :allow_blank => true, :allow_nil => true | |
attr_accessible :menu_location | |
def to_refinery_menu_item | |
{ | |
:id => id, | |
:lft => lft, | |
:menu_match => menu_match, | |
:parent_id => parent_id, | |
:rgt => rgt, | |
:title => refinery_menu_title, | |
:type => self.class.name, | |
:url => url, | |
:menu_location => menu_location | |
} | |
end | |
class << self | |
MENU_LOCATIONS.each do |location| | |
define_method("in_#{location}_menu".to_sym) do | |
where(:menu_location => location) | |
end | |
end | |
end | |
end |
This file contains hidden or 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 | |
def render_menu(template) | |
render_cell :menu, template.to_sym, :menu => refinery_menu_pages | |
end | |
end |
This file contains hidden or 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
<% # ... %> | |
<div class='field'> | |
<%= f.label :menu_location %> | |
<%= f.select :menu_location, ::Refinery::Page::MENU_LOCATIONS.collect {|m| [m.capitalize, m]}, :include_blank => true %> | |
</div> | |
</div> | |
<%= render 'form_advanced_options_seo', :f => f %> | |
<% # ... %> |
This file contains hidden or 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
# Add this: | |
gem 'cells' |
This file contains hidden or 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
- #################### | |
- # app/views/refinery/_footer.html.haml | |
%footer#footer | |
= render_menu 'footer' | |
- #################### | |
- # app/cells/menu/main.html.haml | |
%nav#navigation | |
.container | |
%span.logo.ir Guru<span></span> | |
%ul | |
- @roots.each_with_index do |page, index| | |
%li{:class => css_for_item(index, page.children.present?).join(" ")} | |
= link_to refinery.url_for(page.url) do | |
= page.title | |
- if page.children.present? | |
<span></span> | |
- if page.children.present? | |
%div | |
%nav | |
- page.children.each do |child| | |
%span.title= child.title | |
- if child.children.present? | |
%ul | |
- child.children.each do |grandchild| | |
%li | |
= link_to grandchild.title, refinery.url_for(grandchild.url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment