Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Documented the methods

  • Loading branch information...
commit c237a1c609e8b32aefed48088e2133f89fd1b219 1 parent 6879adf
Zach Inglis zachinglis authored
Showing with 43 additions and 19 deletions.
  1. +20 −1 README.textile
  2. +23 −18 lib/crummy.rb
21 README.textile
View
@@ -6,10 +6,29 @@ Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.
h2. Example
-
+In your controllers you may add_crumb either like a before_filter or within a method (It is also available to views).
+
+<pre>
+ <code>
+ class ApplicationController
+ add_crumb "Home", '/'
+ end
+
+ class BusinessController < ApplicationController
+ add_crumb("Business") { |instance| instance.business_path }
+
+ def show
+ add_crumb @business.display_name, @business
+ end
+ end
+ </code>
+</pre>
+
+The variable set is set to @_crumbs not to conflict with your code.
h2. Todo
+* Port over rspecs from project to plugin (Fully tested in a project)
* Accept instances of models as a single argument
h2. Credits
41 lib/crummy.rb
View
@@ -1,6 +1,11 @@
module Crummy
module ControllerMethods
module ClassMethods
+ # Add a crumb to the crumbs array.
+ #
+ # add_crumb("Home", "/")
+ # add_crumb("Business") { |instance| instance.business_path }
+ #
def add_crumb(name, url = nil, options = {})
raise ArgumentError, "Cannot pass url and use block" if url && block_given?
before_filter(options) do |instance|
@@ -12,36 +17,51 @@ def add_crumb(name, url = nil, options = {})
end
module InstanceMethods
+ # Add a crumb to the crumbs array.
+ #
+ # add_crumb("Home", "/")
+ # add_crumb("Business") { |instance| instance.business_path }
+ #
def add_crumb(name, url='')
crumbs.push [name, url]
end
+ # Lists the crumbs as an array
def crumbs
get_or_set_ivar "@_crumbs", []
end
- # :nodoc:
- def get_or_set_ivar(var, value)
+ def get_or_set_ivar(var, value) # :nodoc:
instance_variable_set var, instance_variable_get(var) || value
end
private :get_or_set_ivar
end
- def self.included(receiver)
+ def self.included(receiver) # :nodoc:
receiver.extend ClassMethods
receiver.send :include, InstanceMethods
end
end
module ViewMethods
+ # List the crumbs as an array
def crumbs
@_crumbs ||= [] # Give me something to push to
end
+ # Add a crumb to the +crumbs+ array
def add_crumb(name, url='')
crumbs.push [name, url]
end
+ # Render the list of crumbs
+ #
+ # render_crumbs #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
+ #
+ # The only option is for the seperator text. It does not assume you want spaces on either side so you must specify. Defaults to +&raquo;+
+ #
+ # render_crumbs(" . ") #=> <a href="/">Home</a> . <a href="/businesses">Businesses</a>
+ #
def render_crumbs(seperator=" &raquo; ")
crumbs.collect do |crumb|
crumb_to_html crumb
@@ -54,18 +74,3 @@ def crumb_to_html(crumb)
end
end
end
-
-# class EventsController < ApplicationController
-# add_crumb "Home", '/' # really in application.rb
-# add_crumb @events
-# add_crumb "Events" { |instance| instance.events_path }
-#
-# def index
-# end
-#
-# def show
-# add_crumb @event.display_name, @event
-# end
-# end
-#
-# Home > Events > Some Event
Please sign in to comment.
Something went wrong with that request. Please try again.