Sha256: faf8e2f780ab575cab0c3de4fce1720b62821bb19250349b4539e2eb7764d758

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

module TaxonsHelper
  def breadcrumbs(taxon, separator=" » ")
    return "" if current_page?("/")
    separator = raw(separator)
    crumbs = [content_tag(:li, link_to(t(:home) , root_path) + separator)]
    if taxon
      crumbs << content_tag(:li, link_to(t('products') , products_path) + separator)
      crumbs << taxon.ancestors.collect { |ancestor| content_tag(:li, link_to(ancestor.name , seo_url(ancestor)) + separator) } unless taxon.ancestors.empty?
      crumbs << content_tag(:li, content_tag(:span, taxon.name))
    else
      crumbs << content_tag(:li, content_tag(:span, t('products')))
    end
    crumb_list = content_tag(:ul, raw(crumbs.flatten.map{|li| li.mb_chars}.join))
    content_tag(:div, crumb_list + tag(:br, {:class => 'clear'}, false, true), :class => 'breadcrumbs')
  end

  
  # Retrieves the collection of products to display when "previewing" a taxon.  This is abstracted into a helper so 
  # that we can use configurations as well as make it easier for end users to override this determination.  One idea is
  # to show the most popular products for a particular taxon (that is an exercise left to the developer.) 
  def taxon_preview(taxon, max=5)
    products = taxon.products.active.find(:all, :limit => max)
    if (products.size < max) && Spree::Config[:show_descendents]
      taxon.descendents.each do |taxon|
        to_get = max - products.length
        products += taxon.products.active.find(:all, :limit => to_get)
        break if products.size >= max
      end
    end
    products
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree-0.11.4 app/helpers/taxons_helper.rb
spree-0.11.3 app/helpers/taxons_helper.rb
spree-0.11.2 app/helpers/taxons_helper.rb
spree-0.11.1 app/helpers/taxons_helper.rb