crummy 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,11 +22,13 @@ Then install the Crummy gem:
22
22
  </code>
23
23
  </pre>
24
24
 
25
- You can also install it as a Rails plugin:
25
+ h3. Rails 3 / Bundler.
26
+
27
+ Simply add gem dependency to your Gemfile:
26
28
 
27
29
  <pre>
28
30
  <code>
29
- script/plugin install git://github.com/zachinglis/crummy.git
31
+ gem "crummy", ">= 1.0.1"
30
32
  </code>
31
33
  </pre>
32
34
 
@@ -65,7 +67,7 @@ Then in your view:
65
67
  </code>
66
68
  </pre>
67
69
 
68
- h2. Options for render_crumb_
70
+ h2. Options for render_crumbs
69
71
 
70
72
  render_crumbs renders the list of crumbs as either html or xml
71
73
 
@@ -106,11 +108,12 @@ h2. Todo
106
108
 
107
109
  h2. Credits
108
110
 
109
- * "Zach Inglis":http://zachinglis.com
111
+ * "Zach Inglis":http://zachinglis.com of "London Made":http://londonmade.co.uk
110
112
  * "Rein Henrichs":http://reinh.com
111
113
  * "Les Hill":http://blog.leshill.org/
112
114
  * "Sandro Turriate":http://turriate.com/
113
115
  * "Przemysław Kowalczyk":http://szeryf.wordpress.com/2008/06/13/easy-and-flexible-breadcrumbs-for-rails/ - feature ideas
114
116
  * "Sharad Jain":http://github.com/sjain
117
+ * "Max Riveiro":http://github.com/kavu
115
118
 
116
- *Copyright (c) 2008 Zach Inglis, released under the MIT license*
119
+ *Copyright (c) 2010 Zach Inglis, released under the MIT license*
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ begin
13
13
  gem.email = "zach@lt3media.com"
14
14
  gem.homepage = "http://github.com/zachinglis/crummy"
15
15
  gem.authors = ["Zach Inglis"]
16
+ gem.files = FileList['lib/**/*.rb','tasks/*.rake','init.rb','MIT-LICENSE','Rakefile','README.textile','VERSION', '.gitignore']
16
17
  end
17
18
  Jeweler::GemcutterTasks.new
18
19
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/init.rb CHANGED
@@ -1,2 +1 @@
1
- ActionController::Base.send :include, Crummy::ControllerMethods
2
- ActionView::Base.send :include, Crummy::ViewMethods
1
+ require 'crummy'
@@ -1,121 +1,10 @@
1
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 +&raquo;+ 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> &raquo; <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 +&raquo;+
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] = " &raquo; " 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
2
+ if defined?(Rails::Railtie)
3
+ require 'crummy/railtie'
4
+ else
5
+ require 'crummy/action_controller'
6
+ require 'crummy/action_view'
7
+ ActionController::Base.send :include, Crummy::ControllerMethods
8
+ ActionView::Base.send :include, Crummy::ViewMethods
9
+ end
10
+ end
@@ -0,0 +1,56 @@
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
+ end
@@ -0,0 +1,65 @@
1
+ module Crummy
2
+ module ViewMethods
3
+ # List the crumbs as an array
4
+ def crumbs
5
+ @_crumbs ||= [] # Give me something to push to
6
+ end
7
+
8
+ # Add a crumb to the +crumbs+ array
9
+ def add_crumb(name, url=nil)
10
+ crumbs.push [name, url]
11
+ end
12
+
13
+ # Render the list of crumbs as either html or xml
14
+ #
15
+ # Takes 3 options:
16
+ # The output format. Can either be xml or html. Default :html
17
+ # :format => (:html|:xml)
18
+ # The seperator text. It does not assume you want spaces on either side so you must specify. Default +&raquo;+ for :html and +crumb+ for xml
19
+ # :seperator => string
20
+ # Render links in the output. Default +true+
21
+ # :link => boolean
22
+ #
23
+ # Examples:
24
+ # render_crumbs #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
25
+ # render_crumbs :seperator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
26
+ # render_crumbs :format => :xml #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
27
+ #
28
+ # The only argument is for the seperator text. It does not assume you want spaces on either side so you must specify. Defaults to +&raquo;+
29
+ #
30
+ # render_crumbs(" . ") #=> <a href="/">Home</a> . <a href="/businesses">Businesses</a>
31
+ #
32
+ def render_crumbs(options = {})
33
+ options[:format] = :html if options[:format] == nil
34
+ if options[:seperator] == nil
35
+ options[:seperator] = " &raquo; " if options[:format] == :html
36
+ options[:seperator] = "crumb" if options[:format] == :xml
37
+ end
38
+ options[:links] = true if options[:links] == nil
39
+ case options[:format]
40
+ when :html
41
+ crumb_string = crumbs.collect do |crumb|
42
+ crumb_to_html crumb, options[:links]
43
+ end * options[:seperator]
44
+ crumb_string = crumb_string.html_safe if crumb_string.respond_to?(:html_safe)
45
+ crumb_string
46
+ when :xml
47
+ crumbs.collect do |crumb|
48
+ crumb_to_xml crumb, options[:links], options[:seperator]
49
+ end * ''
50
+ else
51
+ raise "Unknown breadcrumb output format"
52
+ end
53
+ end
54
+
55
+ def crumb_to_html(crumb, links)
56
+ name, url = crumb
57
+ url && links ? link_to(name, url) : name
58
+ end
59
+
60
+ def crumb_to_xml(crumb, links, seperator)
61
+ name, url = crumb
62
+ url && links ? "<#{seperator} href=\"#{url}\">#{name}</#{seperator}>" : "<#{seperator}>#{name}</#{seperator}>"
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,18 @@
1
+ require 'crummy'
2
+ require 'rails'
3
+
4
+ module Crummy
5
+ class Railtie < Rails::Railtie
6
+ initializer "crummy.action_controller" do |app|
7
+ if defined?(ActionController)
8
+ require 'crummy/action_controller'
9
+ ActionController::Base.send :include, Crummy::ControllerMethods
10
+ end
11
+ end
12
+
13
+ initializer "crummy.action_view" do |app|
14
+ require 'crummy/action_view'
15
+ ActionView::Base.send :include, Crummy::ViewMethods
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crummy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Zach Inglis
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-10 00:00:00 +01:00
18
+ date: 2010-11-26 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -33,18 +33,19 @@ files:
33
33
  - README.textile
34
34
  - Rakefile
35
35
  - VERSION
36
- - crummy.gemspec
37
36
  - init.rb
38
37
  - lib/crummy.rb
39
- - rails/init.rb
38
+ - lib/crummy/action_controller.rb
39
+ - lib/crummy/action_view.rb
40
+ - lib/crummy/railtie.rb
40
41
  - tasks/crummy_tasks.rake
41
42
  has_rdoc: true
42
43
  homepage: http://github.com/zachinglis/crummy
43
44
  licenses: []
44
45
 
45
46
  post_install_message:
46
- rdoc_options:
47
- - --charset=UTF-8
47
+ rdoc_options: []
48
+
48
49
  require_paths:
49
50
  - lib
50
51
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -1,46 +0,0 @@
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 = "1.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
-
@@ -1,3 +0,0 @@
1
- require File.join(File.dirname(__FILE__), *%w[.. lib crummy])
2
- ActionController::Base.send :include, Crummy::ControllerMethods
3
- ActionView::Base.send :include, Crummy::ViewMethods