crummy 1.1.1 → 1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,9 +73,9 @@ render_crumbs renders the list of crumbs as either html or xml
73
73
 
74
74
  It takes 3 options
75
75
 
76
- The output format. Can either be :xml or :html. Defaults to :html
76
+ The output format. Can either be :xml or :html or :html_list. Defaults to :html
77
77
 
78
- <code>:format => (:html|:xml)</code>
78
+ <code>:format => (:html|:html_list|:xml)</code>
79
79
 
80
80
  The separator text. It does not assume you want spaces on either side so you must specify. Defaults to <code>&raquo;</code> for :html and <code><crumb></code> for :xml
81
81
 
@@ -85,16 +85,22 @@ Render links in the output. Defaults to +true+
85
85
 
86
86
  <code>:links => boolean</code>
87
87
 
88
+ <code>:skip_if_blank => true</code>
89
+
90
+ With this option, output will be blank if there are no breadcrumps.
91
+
88
92
  h3. Examples
89
93
 
90
94
  <pre>
91
95
  <code>
92
- render_crumbs #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
93
- render_crumbs :separator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
94
- render_crumbs :format => :xml #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
96
+ render_crumbs #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
97
+ render_crumbs :separator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
98
+ render_crumbs :format => :xml #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
99
+ render_crumbs :format => :html_list #=> <ul class="" id=""><li class=""><a href="/">Home</a></li><li class=""><a href="/">Businesses</a></li></ul>
95
100
  </code>
96
101
  </pre>
97
102
  A crumb with a nil link will just output plain text.
103
+ With :format => :html_list you can specify additional params: :active_li_class, :li_class, :ul_class, :ul_id
98
104
 
99
105
  h2. Notes
100
106
 
@@ -117,5 +123,6 @@ h2. Credits
117
123
  * "Max Riveiro":http://github.com/kavu
118
124
  * "Kamil K. Lemański":http://kml.jogger.pl
119
125
  * "Brian Cobb":http://bcobb.net/
126
+ * "Kir Shatrov":http://shatrov.tk/
120
127
 
121
128
  *Copyright (c) 2011 Zach Inglis, released under the MIT license*
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gem.name = "crummy"
11
11
  gem.summary = %Q{Tasty breadcrumbs!}
12
12
  gem.description = %Q{Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.}
13
- gem.email = "zach@lt3media.com"
13
+ gem.email = "zach+crummy@londonmade.co.uk"
14
14
  gem.homepage = "http://github.com/zachinglis/crummy"
15
15
  gem.authors = ["Zach Inglis"]
16
16
  gem.files = FileList['lib/**/*.rb','tasks/*.rake','init.rb','MIT-LICENSE','Rakefile','README.textile','VERSION', '.gitignore']
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2
@@ -15,14 +15,16 @@ module Crummy
15
15
  before_filter(options) do |instance|
16
16
  url = yield instance if block_given?
17
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)
18
+
19
+ _record = instance.instance_variable_get("@#{name}") unless url or block_given?
20
+ if _record and _record.respond_to? :to_param
21
+ instance.add_crumb(_record.to_s, instance.url_for(_record))
22
+ else
23
+ instance.add_crumb(name, url)
21
24
  end
22
25
 
23
26
  # FIXME: url = instance.url_for(name) if name.respond_to?("to_param") && url.nil?
24
27
  # FIXME: Add ||= for the name, url above
25
- instance.add_crumb(name, url)
26
28
  end
27
29
  end
28
30
  end
@@ -16,16 +16,19 @@ module Crummy
16
16
  # :link => boolean
17
17
  #
18
18
  # Examples:
19
- # render_crumbs #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
20
- # render_crumbs :separator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
21
- # render_crumbs :format => :xml #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
19
+ # render_crumbs #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
20
+ # render_crumbs :separator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
21
+ # render_crumbs :format => :xml #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
22
+ # render_crumbs :format => :html_list #=> <ul class="" id=""><li class=""><a href="/">Home</a></li><li class=""><a href="/">Businesses</a></li></ul>
22
23
  #
24
+ # With :format => :html_list you can specify additional params: active_li_class, li_class, ul_class, ul_id
23
25
  # The only argument is for the separator text. It does not assume you want spaces on either side so you must specify. Defaults to +&raquo;+
24
26
  #
25
27
  # render_crumbs(" . ") #=> <a href="/">Home</a> . <a href="/businesses">Businesses</a>
26
28
  #
27
29
  def render_crumbs(crumbs, options = {})
28
30
  options[:format] = :html if options[:format] == nil
31
+ return '' if options[:skip_if_blank] && crumbs.count < 1
29
32
  if options[:separator] == nil
30
33
  options[:separator] = " &raquo; " if options[:format] == :html
31
34
  options[:separator] = "crumb" if options[:format] == :xml
@@ -38,6 +41,20 @@ module Crummy
38
41
  end * options[:separator]
39
42
  crumb_string = crumb_string.html_safe if crumb_string.respond_to?(:html_safe)
40
43
  crumb_string
44
+ when :html_list
45
+ # In html_list format there are no separator, but may be
46
+ options[:separator] = "" if options[:separator] == nil
47
+ # Lets set default values for special options of html_list format
48
+ options[:active_li_class] = "" if options[:active_li_class] == nil
49
+ options[:li_class] = "" if options[:li_class] == nil
50
+ options[:ul_class] = "" if options[:ul_class] == nil
51
+ options[:ul_id] = "" if options[:ul_id] == nil
52
+ crumb_string = crumbs.collect do |crumb|
53
+ crumb_to_html_list crumb, options[:links], options[:li_class], options[:active_li_class]
54
+ end * options[:separator]
55
+ crumb_string = "<ul class=\"#{options[:ul_class]}\" id=\"#{options[:ul_id]}\">" + crumb_string + "</ul>"
56
+ crumb_string = crumb_string.html_safe if crumb_string.respond_to?(:html_safe)
57
+ crumb_string
41
58
  when :xml
42
59
  crumbs.collect do |crumb|
43
60
  crumb_to_xml crumb, options[:links], options[:separator]
@@ -53,6 +70,11 @@ module Crummy
53
70
  name, url = crumb
54
71
  url && links ? link_to(name, url) : name
55
72
  end
73
+
74
+ def crumb_to_html_list(crumb, links, li_class, active_li_class)
75
+ name, url = crumb
76
+ url && links ? "<li class=\"#{li_class}\"><a href=\"#{url}\">#{name}</a></li>" : "<li class=\"#{active_li_class}\"><span>#{name}</span></li>"
77
+ end
56
78
 
57
79
  def crumb_to_xml(crumb, links, separator)
58
80
  name, url = crumb
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crummy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
9
- - 1
10
- version: 1.1.1
8
+ - 2
9
+ version: "1.2"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Zach Inglis
@@ -15,12 +14,12 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-03-03 00:00:00 +00:00
17
+ date: 2011-04-20 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
22
21
  description: Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.
23
- email: zach@lt3media.com
22
+ email: zach+crummy@londonmade.co.uk
24
23
  executables: []
25
24
 
26
25
  extensions: []