Sha256: 4cb207f1f65aaa234c9a199393b3f697232d8b0854fdf4324ca3ea5393ce0b02

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

module Formol
  module ApplicationHelper
    def breadcrumb_for(record)
      items = [[t('home'), root_path]]
      
      klass = record.class.to_s
      
      case klass
        when 'Formol::Category'
          items << [record.label, category_path(record)]
        when 'Formol::Forum'
          items << [record.category.label, category_path(record.category)]
          items << [record.label, forum_path(record)]
        when 'Formol::Topic'
          items << [record.forum.category.label, category_path(record.forum.category)]
          items << [record.forum.label, forum_path(record.forum)]
          items << [record.title, forum_topic_path(record.forum, record)]
      end
      
      content_tag(:ul, :class => 'breadcrumb') do
        items.each do |(text, path)|
          concat(content_tag(:li, :class => 'item'){ link_to(text, path) })
        end
      end
    end
    
    # When you want to link to last post, you don't need to calculate position
    # of last post (wich need to load all topic's posts).
    # Last post is obviously on last page, you can rely then on posts_count in 
    # topic object
    def link_to_last_post(forum, topic, post, text = nil)
      link_to (text || '>'), last_page_forum_topic_path(forum, topic, post), :title => t('formol.posts.last_post.go_to_last')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formol-0.0.6 app/helpers/formol/application_helper.rb
formol-0.0.5 app/helpers/formol/application_helper.rb
formol-0.0.4 app/helpers/formol/application_helper.rb