custom page attributes and display

git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@30 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7
master
andrew 2007-11-16 03:11:50 +00:00
parent 4670fc1a8a
commit 629cc9c2cc
6 changed files with 29 additions and 26 deletions

View File

@ -1,5 +1,2 @@
module BeersHelper
def abv(beer)
number_to_percentage(beer.abv, { :precision => 1 })
end
end

View File

@ -8,6 +8,21 @@ class Beer < ActiveRecord::Base
before_save :ensure_page_valid
after_save :save_page
##
# Returns a list of attributes for the Page partial.
#
def page_attributes
pattr = []
pattr << "ABV: #{"%.1f" % abv}%" unless abv.to_s.empty?
unless original_gravity.to_s.empty?
pattr << "Original Gravity: #{original_gravity}"
end
unless final_gravity.to_s.empty?
pattr << "Final Gravity: #{final_gravity}"
end
pattr
end
protected
##

View File

@ -8,6 +8,15 @@ class Brewery < ActiveRecord::Base
before_save :ensure_page_valid
after_save :save_page
##
# Returns a list of attributes to add into the Page display.
#
def page_attributes
pattr = []
pattr << "Available Beers: #{beers.size}"
pattr
end
protected
##

View File

@ -1,18 +1,5 @@
<%= render :partial => 'pages/page' %>
<%
attributes = []
attributes << "ABV: #{abv(@beer)}" unless @beer.abv.to_s.empty?
attributes << "Original Gravity: #{@beer.original_gravity}" unless @beer.original_gravity.to_s.empty?
attributes << "Final Gravity: #{@beer.final_gravity}" unless @beer.final_gravity.to_s.empty?
unless attributes.empty?
-%>
<div id="attributes">
<h3>Useful attributes</h3>
<ul><li><%= attributes.join('</li><li>') -%></ul>
</div>
<% end -%>
<% content_for :sidebar do -%>
<%= link_to 'New Beer', new_beer_path -%><br />
<%= link_to 'Edit Beer', edit_beer_path(@beer.page.title_for_url) -%><br />

View File

@ -1,11 +1,5 @@
<%= render :partial => 'pages/page' %>
<div id="attributes">
<ul>
<li>Available Beers: <%= @brewery.beers.size -%></li>
</ul>
</div>
<% content_for :sidebar do -%>
<%= link_to 'New Brewery', new_brewery_path -%><br />
<%= link_to 'Edit', edit_brewery_path(@brewery.page.title_for_url) -%><br />

View File

@ -12,8 +12,9 @@
</div>
<ul class="meta">
<li>Add Tags here</li>
<li>Meta
Version: <%= @page.version -%> / <%= @page.versions.size %>
</li>
<li>Version: <%= @page.version -%></li>
<% @page.owner.page_attributes.each do |x| -%>
<li><%= x -%></li>
<% end if @page.owner and @page.owner.respond_to?("page_attributes") %>
</ul>
</div>
</div>