Created
February 28, 2011 19:24
-
-
Save jonpaul/847853 to your computer and use it in GitHub Desktop.
issue rendering partial to side_body for all pages#
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
<% | |
# provide a default array for collecting CSS for sections | |
css = [] | |
# if 'sections' is passed in as a local_assigns, all of this is ignored. | |
if local_assigns[:sections].blank? | |
# always have a title | |
sections = [{:yield => :body_content_title, :fallback => page_title, :title => true}] | |
# append sections from this page. | |
@page.parts.inject(sections) do |s, part| | |
# we have some default yields, body_content_left and body_content_right | |
# these map to 'body' and 'side_body' fields in default Refinery. | |
section = {:fallback => part.body} | |
section[:yield] = case (title_symbol = part.title.to_s.gsub(/\ /, '').underscore.to_sym) | |
when :body then :body_content_left | |
when :side_body then :body_content_right | |
else title_symbol | |
end | |
# add section to the list unless we were specifically requested not to. | |
# otherwise, add css saying it's been removed. | |
unless (local_assigns[:hide_sections]||=[]).include?(section[:yield]) | |
s << section | |
else | |
css << "no_#{section[:yield]}" | |
end | |
end unless @page.nil? or @page.parts.blank? | |
# Ensure that even without @page.parts we still have body_content_left and body_content_right | |
all_yields = sections.collect{|s| s[:yield]} | |
sections << {:yield => :body_content_left} unless all_yields.include?(:body_content_left) | |
sections << {:yield => :body_content_right} unless all_yields.include?(:body_content_right) | |
end | |
# you can add more sections to the list using something like this: | |
# sections |= [{:yield => :something_else, :fallback => another_method, :id => 'something'}] | |
sections.each do |section| | |
section[:html] = yield(section[:yield]) if section[:yield].present? | |
if section[:html].blank? and !local_assigns[:show_empty_sections] and | |
!local_assigns[:remove_automatic_sections] and section.keys.include?(:fallback) and | |
section[:fallback].present? | |
section[:html] = raw(section[:fallback]) | |
end | |
dom_id = section[:id] || section[:yield] | |
if section[:html].present? | |
if section[:title] | |
section[:html] = "<h1 id='#{dom_id}'>#{section[:html]}</h1>" | |
else | |
section[:html] = "<section id='#{dom_id}'>#{section[:html]}</section>" | |
end | |
else | |
css << "no_#{dom_id}" | |
end | |
end | |
-%> | |
<section id='body_content'<%= " class='#{css.join(' ')}'" if css.present? %>> | |
<%= raw sections.map{|section| section[:html]}.join("\n") -%> | |
</section> | |
<%= render :partial => '/shared/draft_page_message' unless @page.nil? or @page.live? -%> | |
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
<!DOCTYPE html> | |
<%= render :partial => "/shared/html_tag" %> | |
<% site_bar = render(:partial => "/shared/site_bar", :locals => {:head => true}) -%> | |
<%= render :partial => "/shared/head" %> | |
<body> | |
<a id="backtotop" name="backtotop"></a> | |
<div id="wrap"> | |
<%= site_bar -%> | |
<%= render :partial => "/shared/ie6check" if request.env['HTTP_USER_AGENT'] =~ /MSIE/ -%> | |
<div id="page_container"> | |
<header> | |
<%= render :partial => "/shared/header" -%> | |
</header> | |
<section id='page'> | |
<%= yield %> | |
</section> | |
</div> | |
<div class="spacer" style="clear:both;"> </div> | |
<footer> | |
<%= render :partial => "/shared/footer" -%> | |
</footer> | |
<%= render :partial => "/shared/javascripts" %> | |
</div> <!-- end WRAP div --> | |
</body> | |
</html> | |
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
<% content_for :body_content_right do %> | |
<%= raw @page[:side_body] %> | |
<%= render :partial => "/shared/body_content_right" %> | |
<% end %> | |
<%= render :partial => "/shared/content_page" %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment