Skip to content
Browse files

Major work with Lee - almost at the first version need to test install

  • Loading branch information...
1 parent 6c64879 commit f70ed9648cc266216eb6252041fccc17b6495b2d Luke Brown committed Feb 5, 2010
View
41 README
@@ -1,2 +1,41 @@
Testimonials plugin for RefineryCMS
-http://github.com/resolve/Refinery
+http://github.com/resolve/Refinery
+
+This is our first attempt at giving something back to the open source community. The guys at resolve
+have done a great job with refinerycms and made the project easily extendable with engines. We hope
+others find this plugin useful and would love to here any feedback or advice on improving it : )
+
+
+Plugin Installation
+===================
+script/plugin install git://github.com/tsdbrown/refinery_testimonials.git
+rake refinery_testimonials:install
+rake db:migrate
+
+Following the refinery conventions the standard install gives you a new tab in the
+admin interface to manage your testimonials. There is also a new page added under
+pages that is used to display your list in the front end.
+
+
+Gem Installation
+================
+Coming soon...
+
+
+Show a Random Testimonial On Any Page
+=====================================
+If like us you wish to show a random testimonial on pages you need to follow these
+two basic steps:
+
+1. Add <%= display_page_testimonial_if_setup %> into your layout where you would like to display them
+ -> We've put ours in the sidebar under shared/_content_page.html.erb
+
+2. Change the 'show_testimonials_on_pages' setting in the backend, there are three options:
+ -> all # Show one on every page (except testimonials)
+ -> none # Turn off the random testimonial on all pages
+ -> comma seperated list of page titles you want them on, i.e: news, contact us, home
+
+
+If you want to run the tests add the following to environments/test.rb
+config.gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com"
+config.gem "mocha"
View
18 app/helpers/testimonials_helper.rb
@@ -1,5 +1,13 @@
module TestimonialsHelper
+ # Helper method to be included in the page layout
+ def display_page_testimonial_if_setup
+ if @page.show_a_testimonial? && (random_testimonial = Testimonial.random)
+ content_for :head, stylesheet_link_tag('testimonials')
+ render :partial => '/testimonials/testimonial', :locals => {:testimonial => random_testimonial}
+ end
+ end
+
# Based on the fields filled in by the user display the
# citation in our desired format:
#
@@ -12,12 +20,18 @@ def citation_line(t)
].reject(&:blank?).join(", ").sub(/,\s/, ": ")
end
+ # Method to setup the end of the citation line
+ # Returns:
+ #
+ # The company name as a link is both are set
+ # The company name with a link
+ # Or
+ # Just a link if the name isn't set
def website_or_company(t)
if t.website.blank?
h(t.company)
else
content_tag(:a, h(t.company.blank? ? t.website : t.company), :href => h(t.website))
end
- end
-
+ end
end
View
3 app/models/testimonial.rb
@@ -10,4 +10,7 @@ def flash_name
"Quote by #{self.name}"
end
+ def self.random
+ self.find :first, :offset => ( Model.count * rand ).to_i
+ end
end
View
6 app/views/testimonials/_testimonial.html.erb
@@ -0,0 +1,6 @@
+ <div class="testimonial">
+ <blockquote>
+ <p><%= testimonial.quote %></p>
+ <p><cite><%= citation_line(testimonial) %></cite></p>
+ </blockquote>
+</div>
View
10 app/views/testimonials/index.html.erb
@@ -6,20 +6,14 @@
<%= will_paginate @testimonials %>
<div class="testimonials">
- <% @testimonials.each do |testimonial| %>
- <div class="testimonial">
- <blockquote>
- <p><%= testimonial.quote %></p>
- <p><cite><%= citation_line(testimonial) %></cite></p>
- </blockquote>
- </div>
- <% end %>
+ <%= render :partial => 'testimonial', :collection => @testimonials %>
</div>
<%= will_paginate @testimonials %>
<% end %>
<% content_for :body_content_right do %>
+ <%= y @random_testimonial %> hi
<%= @page[:side_body] %>
<% end %>
View
13 lib/refinery_testimonials.rb
@@ -0,0 +1,13 @@
+class Page < ActiveRecord::Base
+ # Works out whether this page should have a testimonial shown
+ # based on the :show_testimonials_on_pages setting
+ #
+ # We assume nobody wants one displayed on the testimonials page
+ def show_a_testimonial?
+ return false if self.link_url == '/testimonials'
+ show_on_pages = RefinerySetting.find_or_set(:show_testimonials_on_pages, 'none')
+ show_on_pages =~ /all/i || show_on_pages.split(',').map {|t| t.strip.downcase}.include?(self.title.strip.downcase)
+ end
+end
+
+ActionView::Base.send :include, TestimonialsHelper;
View
BIN public/images/close_quote.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/open_quote.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
4 public/stylesheets/testimonials.css
@@ -1,6 +1,6 @@
-.testimonials {border-top:1px dashed #ddd; margin:20px 0;}
+.testimonials {border-bottom:1px dashed #ddd; margin:20px 0;}
-.testimonial {border-bottom:1px dashed #ddd;}
+.testimonial {border-top:1px dashed #ddd;}
cite {font-style:normal;}
blockquote p {padding: 0 36px;}
View
2 rails/init.rb
@@ -5,3 +5,5 @@
plugin.version = 1.0
plugin.activity = {:class => Testimonial, :url_prefix => "edit_", :title => 'quote'}
end
+
+require File.dirname(__FILE__) + '/../lib/refinery_testimonials'
View
9 test/unit/page_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class PageTest < ActiveSupport::TestCase
+
+ context "The Page class has been extended and now it" do
+ should_have_instance_methods :show_a_testimonial?
+ end
+
+end
View
2 test/unit/testimonial_test.rb
@@ -1,10 +1,12 @@
require 'test_helper'
+require 'testimonial'
class TestimonialTest < ActiveSupport::TestCase
context "The Testimonial class itself" do
should_validate_presence_of :name, :quote
should_have_instance_methods :flash_name
+ should_have_class_methods :random
end
context "A valid instance of a Testimonial" do

0 comments on commit f70ed96

Please sign in to comment.
Something went wrong with that request. Please try again.