Sha256: f70284328fb16d0bf33b5bc06094f154edcf40b1eb5e988d212310cde7b72a0b

Contents?: true

Size: 1.56 KB

Versions: 7

Compression:

Stored size: 1.56 KB

Contents

##
# Outpost::Breadcrumbs
#
# Super-simple breadcrumbs for you and me.
# Include it into a controller
#
# Arguments:
# Pairs of strings. Title of breadcrumb, Path
#
# Usage:
# In the controller:
#
#   class PostsController < ApplicationController
#     def new
#       breadcrumb "New", outpost_new_post_path
#       @post = Post.new
#     end
#   end
#
# This module then makes the "breadcrumbs" helper
# available to you (and me), which can be used in
# your view:
#
#   <% breadcrumbs.each do |crumb| %>
#     <%= link_to crumb.title, crumb.link %>
#   <% end %>
#
# You can also define multiple breadcrumbs at once.
# Every 2 arguments is a new breadcrumb:
#
#   breadcrumb "Edit",
#     outpost_edit_post_path(@post.id),
#     @post.title, outpost_post_path(@post)
#
# Don't want the crumb to be linked? Just leave the
# second argument off, or +nil+ if you're defining
# multiple breadcrumbs:
#
#   breadcrumb "Edit", nil, @post.title
#
module Outpost
  class Breadcrumb
    attr_accessor :title, :link
  end

  #---------------

  module Breadcrumbs
    extend ActiveSupport::Concern

    included do
      attr_reader :breadcrumbs

      if self < ActionController::Base
        helper_method :breadcrumbs
      end
    end

    #--------------
    # Use this method to add breadcrumbs.
    # See Outpost::Breadcrumbs
    # for usage.
    def breadcrumb(*args)
      @breadcrumbs ||= []

      args.each_slice(2).map do |pair|
        crumb       = Outpost::Breadcrumb.new
        crumb.title = pair[0]
        crumb.link  = pair[1]

        @breadcrumbs.push crumb
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
outpost-cms-0.1.4 lib/outpost/breadcrumbs.rb
outpost-cms-0.1.3 lib/outpost/breadcrumbs.rb
outpost-cms-0.1.2 lib/outpost/breadcrumbs.rb
outpost-cms-0.1.1 lib/outpost/breadcrumbs.rb
outpost-cms-0.1.0 lib/outpost/breadcrumbs.rb
outpost-cms-0.0.5 lib/outpost/breadcrumbs.rb
outpost-cms-0.0.4 lib/outpost/breadcrumbs.rb