Sha256: 0ae7c764f2fc4b2ed573df936f87af16d3d9cd7339e5baa544822d5a14bb00bc

Contents?: true

Size: 926 Bytes

Versions: 3

Compression:

Stored size: 926 Bytes

Contents

module Orange
  class TestimonialsResource < Orange::ModelResource
    use OrangeTestimonial
    call_me :testimonials
    def stack_init
      orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Testimonials')
      orange[:radius].context.define_tag "testimonials" do |tag|
     	  if tag.attr["tag"] && model_class.all.count >0
          m = model_class.with_tag(tag.attr["tag"]).first(:offset => rand(model_class.with_tag(tag.attr["tag"]).count)) #selects testimonial based on tag
	      elsif model_class.all.count > 0
      	  m = model_class.first(:offset => rand(model_class.all.count)) #selects a random testimonial
	      end
        unless m.nil?
          orange[:testimonials].testimonial(tag.locals.packet, {:model => m })
        else
          ""
        end
      end
    end
    
    def testimonial(packet, opts = {})
      do_view(packet, :testimonials, opts)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
orange-0.2.4 lib/orange-more/testimonials/resources/testimonials_resource.rb
orange-0.2.3 lib/orange-more/testimonials/resources/testimonials_resource.rb
orange-0.1.10 lib/orange-more/testimonials/resources/testimonials_resource.rb