Skip to content

Instantly share code, notes, and snippets.

@danielres
Forked from djones/gist:720668
Created March 27, 2011 14:48
Show Gist options
  • Save danielres/889262 to your computer and use it in GitHub Desktop.
Save danielres/889262 to your computer and use it in GitHub Desktop.
rendering a custom plugin
<% content_for :page_title do %>
<%= @destination.title %>
<% end %>
<% content_for :page_body do %>
<section>
<h1>Choose from our most popular recommended itineraries below</h1>
</section>
<%= render @destination.trips %>
<% end %>
<% content_for :page_side_body do %>
<aside>
<%= render :partial => "/shared/customize_your_itinerary" %>
<%=raw @destination.side_body %>
<%= render :partial => "/shared/brochure" %>
<%= render :partial => "/shared/have_a_question" %>
</aside>
<% end %>
<%= render :partial => "/shared/content_page" %>
rendering a standard page
<%= render :partial => "/shared/content_page" %>
rendering a home page
<% content_for :page_title do %>
<%= image_tag('peru.png') %>
<% end %>
<% content_for :page_body do %>
<h1>What Sets Us Apart</h1>
<%= raw @page[:what_sets_us_apart] %>
<%= render :partial => "/shared/have_a_question" %>
<% end %>
<% content_for :page_side_body do %>
<div class='clearfix'>
<%= image_tag('south-america.png') %>
<h1>Where Do You Want To Go?</h1>
<%= raw @page[:"where_do_you_want_to_go?"] %>
</div>
<div class='clearfix'>
<%= image_tag('brochure-large.png') %>
<h1>Vaya Adventures Brochure</h1>
<%= raw @page[:vaya_adventures_brochure] %>
</div>
<h1>What Our Travellers Say</h1>
<%= raw @page[:what_our_travellers_say] %>
<% end %>
<%= render :partial => "/shared/content_page" %>
rendering a news index page
<% content_for :page_title do %>
<%= t('plugins.refinerycms_news.title') %>
<% end %>
<% content_for :page_body do %>
<%= @page[:body] if @news_items.offset == 0 %>
<% if @news_items.any? %>
<% @news_items.each do |item| %>
<article class="news_item_truncated">
<h3><%= link_to item.title, news_item_url(item) %></h3>
<p>
<small><%= t('.published') %> <%= l(item.publish_date, :format => :long) %></small>
</p>
<%= truncate item.body, :length => 200,
:omission => " ... #{link_to t('.read_more'), news_item_url(item)}",
:preserve_html_tags => true %>
</article>
<% end %>
<%= will_paginate(@news_items) %>
<% else %>
<p><em><%= t('.no_items_yet') %></em></p>
<% end %>
<% end -%>
<%= render :partial => "/shared/content_page" %>
content page
<%
# 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? -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment