crummy 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  rdoc
2
2
  pkg
3
+ nbproject
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -10,56 +10,20 @@ module Crummy
10
10
  crumbs.push [name, url]
11
11
  end
12
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 +»+ 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>
13
+ # Render the list of crumbs using renderer
31
14
  #
32
15
  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 * ''
16
+ raise ArgumentError, "Renderer and block given" if options.has_key?(:renderer) && block_given?
17
+ return yield(crumbs, options) if block_given?
18
+
19
+ @_renderer ||= if options.has_key?(:renderer)
20
+ options.delete(:renderer)
50
21
  else
51
- raise "Unknown breadcrumb output format"
22
+ require 'crummy/standard_renderer'
23
+ Crummy::StandardRenderer.new
52
24
  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}>"
25
+
26
+ @_renderer.render_crumbs(crumbs, options)
63
27
  end
64
28
  end
65
29
  end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ module Crummy
4
+ class StandardRenderer
5
+ include ActionView::Helpers::UrlHelper
6
+
7
+ # Render the list of crumbs as either html or xml
8
+ #
9
+ # Takes 3 options:
10
+ # The output format. Can either be xml or html. Default :html
11
+ # :format => (:html|:xml)
12
+ # 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
13
+ # :seperator => string
14
+ # Render links in the output. Default +true+
15
+ # :link => boolean
16
+ #
17
+ # Examples:
18
+ # render_crumbs #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
19
+ # render_crumbs :seperator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
20
+ # render_crumbs :format => :xml #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
21
+ #
22
+ # 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;+
23
+ #
24
+ # render_crumbs(" . ") #=> <a href="/">Home</a> . <a href="/businesses">Businesses</a>
25
+ #
26
+ def render_crumbs(crumbs, options = {})
27
+ options[:format] = :html if options[:format] == nil
28
+ if options[:seperator] == nil
29
+ options[:seperator] = " &raquo; " if options[:format] == :html
30
+ options[:seperator] = "crumb" if options[:format] == :xml
31
+ end
32
+ options[:links] = true if options[:links] == nil
33
+ case options[:format]
34
+ when :html
35
+ crumb_string = crumbs.collect do |crumb|
36
+ crumb_to_html crumb, options[:links]
37
+ end * options[:seperator]
38
+ crumb_string = crumb_string.html_safe if crumb_string.respond_to?(:html_safe)
39
+ crumb_string
40
+ when :xml
41
+ crumbs.collect do |crumb|
42
+ crumb_to_xml crumb, options[:links], options[:seperator]
43
+ end * ''
44
+ else
45
+ raise ArgumentError, "Unknown breadcrumb output format"
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def crumb_to_html(crumb, links)
52
+ name, url = crumb
53
+ url && links ? link_to(name, url) : name
54
+ end
55
+
56
+ def crumb_to_xml(crumb, links, seperator)
57
+ name, url = crumb
58
+ url && links ? "<#{seperator} href=\"#{url}\">#{name}</#{seperator}>" : "<#{seperator}>#{name}</#{seperator}>"
59
+ end
60
+ end
61
+ 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: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
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-11-26 00:00:00 +00:00
18
+ date: 2010-12-12 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -38,6 +38,7 @@ files:
38
38
  - lib/crummy/action_controller.rb
39
39
  - lib/crummy/action_view.rb
40
40
  - lib/crummy/railtie.rb
41
+ - lib/crummy/standard_renderer.rb
41
42
  - tasks/crummy_tasks.rake
42
43
  has_rdoc: true
43
44
  homepage: http://github.com/zachinglis/crummy