Sha256: 9df5e6131adae329c95dbc382f0d95d4b6e864a048b56b7d9e37a10470c0ac76
Contents?: true
Size: 1.43 KB
Versions: 13
Compression:
Stored size: 1.43 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| packet = tag.locals.packet if tag.attr["tag"] && for_site(packet).with_tag(tag.attr["tag"]).count >0 m = for_site(packet).with_tag(tag.attr["tag"]).first(:offset => rand(for_site(packet).with_tag(tag.attr["tag"]).count)) #selects testimonial based on tag elsif for_site(packet).count > 0 && !tag.attr.include?("tag") m = for_site(packet).first(:offset => rand(for_site(packet).count)) #selects a random testimonial end unless m.nil? template = tag.attr["template"] || "testimonials" orange[:testimonials].testimonial(packet, {:model => m, :template => template}) else "" end end end def for_site(packet, opts = {}) site_filtered = model_class.all(:orange_site => packet['subsite'].blank? ? packet['site'] : packet['subsite']) if site_filtered.count > 0 site_filtered else # Return unfiltered if no site-specific ones model_class.all end end def testimonial(packet, opts = {}) template = opts[:template].to_sym || :testimonials do_view(packet, template, opts) end end end
Version data entries
13 entries across 13 versions & 1 rubygems