Sha256: 6492433c88bf031e636e56c9db2d3c6c8024b5072086d6dbb37d17974bbd71af

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

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].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?
          template = tag.attr["template"] || "testimonials"
          orange[:testimonials].testimonial(tag.locals.packet, {:model => m, :template => template})
        else
          ""
        end
      end
    end
    
    def testimonial(packet, opts = {})
      template = opts[:template].to_sym || :testimonials
      do_view(packet, template, opts)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
orange-0.2.6 lib/orange-more/testimonials/resources/testimonials_resource.rb
orange-0.2.5 lib/orange-more/testimonials/resources/testimonials_resource.rb