Sha256: f54b177262b49798d22875b833fd6b0702b6869adf184d22dbcd917033063181

Contents?: true

Size: 991 Bytes

Versions: 3

Compression:

Stored size: 991 Bytes

Contents

module Orange
  class TestimonialsResource < Orange::ModelResource
    use OrangeTestimonial
    call_me :testimonials
    def afterLoad
      orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Testimonials')
      orange.register(:stack_loaded) do
        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
    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.1.8 lib/orange-more/testimonials/resources/testimonials_resource.rb
orange-0.1.7 lib/orange-more/testimonials/resources/testimonials_resource.rb
orange-0.1.4 lib/orange-more/testimonials/resources/testimonials_resource.rb