crummy 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +116 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/crummy.gemspec +46 -0
- data/init.rb +2 -0
- data/lib/crummy.rb +121 -0
- data/rails/init.rb +3 -0
- data/tasks/crummy_tasks.rake +4 -0
- metadata +76 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
h1. Crummy
|
2
|
+
|
3
|
+
h2. Introduction
|
4
|
+
|
5
|
+
Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.
|
6
|
+
|
7
|
+
h2. Install
|
8
|
+
|
9
|
+
The gem is hosted on gemcutter, so if you haven’t already, add it as a gem source:
|
10
|
+
|
11
|
+
<pre>
|
12
|
+
<code>
|
13
|
+
gem sources -a http://gemcutter.org/
|
14
|
+
</code>
|
15
|
+
</pre>
|
16
|
+
|
17
|
+
Then install the Crummy gem:
|
18
|
+
|
19
|
+
<pre>
|
20
|
+
<code>
|
21
|
+
gem install crummy
|
22
|
+
</code>
|
23
|
+
</pre>
|
24
|
+
|
25
|
+
You can also install it as a Rails plugin:
|
26
|
+
|
27
|
+
<pre>
|
28
|
+
<code>
|
29
|
+
script/plugin install git://github.com/zachinglis/crummy.git
|
30
|
+
</code>
|
31
|
+
</pre>
|
32
|
+
|
33
|
+
h2. Example
|
34
|
+
|
35
|
+
In your controllers you may add_crumb either like a before_filter or within a method (It is also available to views).
|
36
|
+
|
37
|
+
<pre>
|
38
|
+
<code>
|
39
|
+
class ApplicationController
|
40
|
+
add_crumb "Home", '/'
|
41
|
+
end
|
42
|
+
|
43
|
+
class BusinessController < ApplicationController
|
44
|
+
add_crumb("Businesses") { |instance| instance.send :businesses_path }
|
45
|
+
add_crumb("Comments", :only => "comments") { |instance| instance.send :businesses_comments_path }
|
46
|
+
before_filter :load_comment, :only => "show"
|
47
|
+
add_crumb :comment, :only => "show"
|
48
|
+
|
49
|
+
def show
|
50
|
+
add_crumb @business.display_name, @business
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_comment
|
54
|
+
@comment = Comment.find(params[:id])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
</code>
|
58
|
+
</pre>
|
59
|
+
|
60
|
+
Then in your view:
|
61
|
+
|
62
|
+
<pre>
|
63
|
+
<code>
|
64
|
+
<%= render_crumbs %>
|
65
|
+
</code>
|
66
|
+
</pre>
|
67
|
+
|
68
|
+
h2. Options for render_crumb_
|
69
|
+
|
70
|
+
render_crumbs renders the list of crumbs as either html or xml
|
71
|
+
|
72
|
+
It takes 3 options
|
73
|
+
|
74
|
+
The output format. Can either be :xml or :html. Defaults to :html
|
75
|
+
|
76
|
+
<code>:format => (:html|:xml)</code>
|
77
|
+
|
78
|
+
The seperator text. It does not assume you want spaces on either side so you must specify. Defaults to <code>»</code> for :html and <code><crumb></code> for :xml
|
79
|
+
|
80
|
+
<code>:seperator => string</code>
|
81
|
+
|
82
|
+
Render links in the output. Defaults to +true+
|
83
|
+
|
84
|
+
<code>:links => boolean</code>
|
85
|
+
|
86
|
+
h3. Examples
|
87
|
+
|
88
|
+
<pre>
|
89
|
+
<code>
|
90
|
+
render_crumbs #=> <a href="/">Home</a> » <a href="/businesses">Businesses</a>
|
91
|
+
render_crumbs :seperator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
|
92
|
+
render_crumbs :format => :xml #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
|
93
|
+
</code>
|
94
|
+
</pre>
|
95
|
+
A crumb with a nil link will just output plain text.
|
96
|
+
|
97
|
+
h2. Notes
|
98
|
+
|
99
|
+
The variable set is set to @_crumbs as to not conflict with your code.
|
100
|
+
|
101
|
+
h2. Todo
|
102
|
+
|
103
|
+
* Port over rspecs from project to plugin (Fully tested in a project)
|
104
|
+
* Accept instances of models as a single argument
|
105
|
+
* Allow for variables in names. (The workaround is to do your own before_filter for that currently)
|
106
|
+
|
107
|
+
h2. Credits
|
108
|
+
|
109
|
+
* "Zach Inglis":http://zachinglis.com
|
110
|
+
* "Rein Henrichs":http://reinh.com
|
111
|
+
* "Les Hill":http://blog.leshill.org/
|
112
|
+
* "Sandro Turriate":http://turriate.com/
|
113
|
+
* "Przemysław Kowalczyk":http://szeryf.wordpress.com/2008/06/13/easy-and-flexible-breadcrumbs-for-rails/ - feature ideas
|
114
|
+
* "Sharad Jain":http://github.com/sjain
|
115
|
+
|
116
|
+
*Copyright (c) 2008 Zach Inglis, released under the MIT license*
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
desc 'Default: run unit tests.'
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
gem.name = "crummy"
|
11
|
+
gem.summary = %Q{Tasty breadcrumbs!}
|
12
|
+
gem.description = %Q{Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.}
|
13
|
+
gem.email = "zach@lt3media.com"
|
14
|
+
gem.homepage = "http://github.com/zachinglis/crummy"
|
15
|
+
gem.authors = ["Zach Inglis"]
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
desc 'Test the crummy plugin.'
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.pattern = 'test/**/*_test.rb'
|
27
|
+
t.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
gem 'hanna'
|
32
|
+
require 'hanna/rdoctask'
|
33
|
+
rescue LoadError
|
34
|
+
require 'rake/rdoctask'
|
35
|
+
end
|
36
|
+
desc 'Generate documentation for the crummy plugin.'
|
37
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
38
|
+
rdoc.rdoc_dir = 'rdoc'
|
39
|
+
rdoc.title = 'Crummy: Tasty Breadcrumbs'
|
40
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
41
|
+
rdoc.rdoc_files.include('README.textile')
|
42
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
43
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/crummy.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{crummy}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Zach Inglis"]
|
12
|
+
s.date = %q{2010-09-10}
|
13
|
+
s.description = %q{Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.}
|
14
|
+
s.email = %q{zach@lt3media.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.textile"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.textile",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"crummy.gemspec",
|
25
|
+
"init.rb",
|
26
|
+
"lib/crummy.rb",
|
27
|
+
"rails/init.rb",
|
28
|
+
"tasks/crummy_tasks.rake"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/zachinglis/crummy}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
|
+
s.summary = %q{Tasty breadcrumbs!}
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
|
+
else
|
42
|
+
end
|
43
|
+
else
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/init.rb
ADDED
data/lib/crummy.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
module Crummy
|
2
|
+
module ControllerMethods
|
3
|
+
module ClassMethods
|
4
|
+
# Add a crumb to the crumbs array.
|
5
|
+
#
|
6
|
+
# add_crumb("Home", "/")
|
7
|
+
# add_crumb("Business") { |instance| instance.business_path }
|
8
|
+
#
|
9
|
+
# Works like a before_filter so +:only+ and +except+ both work.
|
10
|
+
def add_crumb(name, *args)
|
11
|
+
options = args.extract_options!
|
12
|
+
url = args.first
|
13
|
+
raise ArgumentError, "Need more arguments" unless name or options[:record] or block_given?
|
14
|
+
raise ArgumentError, "Cannot pass url and use block" if url && block_given?
|
15
|
+
before_filter(options) do |instance|
|
16
|
+
url = yield instance if block_given?
|
17
|
+
url = instance.send url if url.is_a? Symbol
|
18
|
+
record = instance.instance_variable_get("@#{name}") unless url or block_given?
|
19
|
+
if record and record.respond_to? :to_param
|
20
|
+
name, url = record.to_s, instance.url_for(record)
|
21
|
+
end
|
22
|
+
|
23
|
+
# FIXME: url = instance.url_for(name) if name.respond_to?("to_param") && url.nil?
|
24
|
+
# FIXME: Add ||= for the name, url above
|
25
|
+
instance.add_crumb(name, url)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module InstanceMethods
|
31
|
+
# Add a crumb to the crumbs array.
|
32
|
+
#
|
33
|
+
# add_crumb("Home", "/")
|
34
|
+
# add_crumb("Business") { |instance| instance.business_path }
|
35
|
+
#
|
36
|
+
def add_crumb(name, url=nil)
|
37
|
+
crumbs.push [name, url]
|
38
|
+
end
|
39
|
+
|
40
|
+
# Lists the crumbs as an array
|
41
|
+
def crumbs
|
42
|
+
get_or_set_ivar "@_crumbs", []
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_or_set_ivar(var, value) # :nodoc:
|
46
|
+
instance_variable_set var, instance_variable_get(var) || value
|
47
|
+
end
|
48
|
+
private :get_or_set_ivar
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.included(receiver) # :nodoc:
|
52
|
+
receiver.extend ClassMethods
|
53
|
+
receiver.send :include, InstanceMethods
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module ViewMethods
|
58
|
+
# List the crumbs as an array
|
59
|
+
def crumbs
|
60
|
+
@_crumbs ||= [] # Give me something to push to
|
61
|
+
end
|
62
|
+
|
63
|
+
# Add a crumb to the +crumbs+ array
|
64
|
+
def add_crumb(name, url=nil)
|
65
|
+
crumbs.push [name, url]
|
66
|
+
end
|
67
|
+
|
68
|
+
# Render the list of crumbs as either html or xml
|
69
|
+
#
|
70
|
+
# Takes 3 options:
|
71
|
+
# The output format. Can either be xml or html. Default :html
|
72
|
+
# :format => (:html|:xml)
|
73
|
+
# The seperator text. It does not assume you want spaces on either side so you must specify. Default +»+ for :html and +crumb+ for xml
|
74
|
+
# :seperator => string
|
75
|
+
# Render links in the output. Default +true+
|
76
|
+
# :link => boolean
|
77
|
+
#
|
78
|
+
# Examples:
|
79
|
+
# render_crumbs #=> <a href="/">Home</a> » <a href="/businesses">Businesses</a>
|
80
|
+
# render_crumbs :seperator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
|
81
|
+
# render_crumbs :format => :xml #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
|
82
|
+
#
|
83
|
+
# The only argument is for the seperator text. It does not assume you want spaces on either side so you must specify. Defaults to +»+
|
84
|
+
#
|
85
|
+
# render_crumbs(" . ") #=> <a href="/">Home</a> . <a href="/businesses">Businesses</a>
|
86
|
+
#
|
87
|
+
def render_crumbs(options = {})
|
88
|
+
options[:format] = :html if options[:format] == nil
|
89
|
+
if options[:seperator] == nil
|
90
|
+
options[:seperator] = " » " if options[:format] == :html
|
91
|
+
options[:seperator] = "crumb" if options[:format] == :xml
|
92
|
+
end
|
93
|
+
options[:links] = true if options[:links] == nil
|
94
|
+
case options[:format]
|
95
|
+
when :html
|
96
|
+
crumb_string = crumbs.collect do |crumb|
|
97
|
+
crumb_to_html crumb, options[:links]
|
98
|
+
end * options[:seperator]
|
99
|
+
crumb_string = crumb_string.html_safe if crumb_string.respond_to?(:html_safe)
|
100
|
+
crumb_string
|
101
|
+
when :xml
|
102
|
+
crumbs.collect do |crumb|
|
103
|
+
crumb_to_xml crumb, options[:links], options[:seperator]
|
104
|
+
end * ''
|
105
|
+
else
|
106
|
+
raise "Unknown breadcrumb output format"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def crumb_to_html(crumb, links)
|
111
|
+
name, url = crumb
|
112
|
+
url && links ? link_to(name, url) : name
|
113
|
+
end
|
114
|
+
|
115
|
+
def crumb_to_xml(crumb, links, seperator)
|
116
|
+
name, url = crumb
|
117
|
+
url && links ? "<#{seperator} href=\"#{url}\">#{name}</#{seperator}>" : "<#{seperator}>#{name}</#{seperator}>"
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
data/rails/init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crummy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Zach Inglis
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-10 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.
|
23
|
+
email: zach@lt3media.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.textile
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- MIT-LICENSE
|
33
|
+
- README.textile
|
34
|
+
- Rakefile
|
35
|
+
- VERSION
|
36
|
+
- crummy.gemspec
|
37
|
+
- init.rb
|
38
|
+
- lib/crummy.rb
|
39
|
+
- rails/init.rb
|
40
|
+
- tasks/crummy_tasks.rake
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/zachinglis/crummy
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.7
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Tasty breadcrumbs!
|
75
|
+
test_files: []
|
76
|
+
|