crummy-schema-dot-org 1.9.0

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.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rvmrc +48 -0
  4. data/.travis.yml +7 -0
  5. data/Appraisals +9 -0
  6. data/CHANGELOG +47 -0
  7. data/Gemfile +3 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.md +216 -0
  10. data/Rakefile +25 -0
  11. data/crummy-schema-dot-org.gemspec +31 -0
  12. data/example/.gitignore +5 -0
  13. data/example/.rspec +1 -0
  14. data/example/.rvmrc +48 -0
  15. data/example/Gemfile +30 -0
  16. data/example/README.md +40 -0
  17. data/example/Rakefile +7 -0
  18. data/example/app/assets/images/rails.png +0 -0
  19. data/example/app/assets/javascripts/application.js +9 -0
  20. data/example/app/assets/javascripts/pages.js.coffee +3 -0
  21. data/example/app/assets/javascripts/post.js.coffee +3 -0
  22. data/example/app/assets/stylesheets/application.css +7 -0
  23. data/example/app/assets/stylesheets/layout.css.sass +26 -0
  24. data/example/app/assets/stylesheets/post.css.scss +3 -0
  25. data/example/app/controllers/application_controller.rb +6 -0
  26. data/example/app/controllers/pages_controller.rb +5 -0
  27. data/example/app/controllers/posts_controller.rb +19 -0
  28. data/example/app/helpers/application_helper.rb +9 -0
  29. data/example/app/helpers/pages_helper.rb +2 -0
  30. data/example/app/helpers/post_helper.rb +2 -0
  31. data/example/app/mailers/.gitkeep +0 -0
  32. data/example/app/models/.gitkeep +0 -0
  33. data/example/app/models/category.rb +6 -0
  34. data/example/app/models/post.rb +19 -0
  35. data/example/app/views/layouts/application.html.haml +16 -0
  36. data/example/app/views/pages/index.html.haml +4 -0
  37. data/example/app/views/posts/index.html.haml +5 -0
  38. data/example/app/views/posts/new.html.haml +1 -0
  39. data/example/app/views/posts/show.html.haml +3 -0
  40. data/example/config.ru +4 -0
  41. data/example/config/application.rb +48 -0
  42. data/example/config/boot.rb +6 -0
  43. data/example/config/database.yml +25 -0
  44. data/example/config/environment.rb +5 -0
  45. data/example/config/environments/development.rb +30 -0
  46. data/example/config/environments/production.rb +60 -0
  47. data/example/config/environments/test.rb +39 -0
  48. data/example/config/initializers/backtrace_silencers.rb +7 -0
  49. data/example/config/initializers/inflections.rb +10 -0
  50. data/example/config/initializers/mime_types.rb +5 -0
  51. data/example/config/initializers/secret_token.rb +7 -0
  52. data/example/config/initializers/session_store.rb +8 -0
  53. data/example/config/initializers/wrap_parameters.rb +14 -0
  54. data/example/config/locales/en.yml +5 -0
  55. data/example/config/routes.rb +5 -0
  56. data/example/db/migrate/20111104103150_create_posts.rb +10 -0
  57. data/example/db/migrate/20111104103738_create_categories.rb +12 -0
  58. data/example/db/migrate/20111104104040_add_category_id_to_posts.rb +5 -0
  59. data/example/db/schema.rb +32 -0
  60. data/example/db/seeds.rb +15 -0
  61. data/example/doc/README_FOR_APP +2 -0
  62. data/example/lib/assets/.gitkeep +0 -0
  63. data/example/lib/tasks/.gitkeep +0 -0
  64. data/example/log/.gitkeep +0 -0
  65. data/example/public/404.html +26 -0
  66. data/example/public/422.html +26 -0
  67. data/example/public/500.html +26 -0
  68. data/example/public/favicon.ico +0 -0
  69. data/example/public/robots.txt +5 -0
  70. data/example/script/rails +6 -0
  71. data/example/spec/controllers/posts_controller_spec.rb +7 -0
  72. data/example/spec/spec_helper.rb +38 -0
  73. data/example/vendor/assets/stylesheets/.gitkeep +0 -0
  74. data/example/vendor/plugins/.gitkeep +0 -0
  75. data/gemfiles/rails3_2.gemfile +8 -0
  76. data/gemfiles/rails4_0.gemfile +8 -0
  77. data/init.rb +1 -0
  78. data/lib/crummy.rb +69 -0
  79. data/lib/crummy/action_controller.rb +83 -0
  80. data/lib/crummy/action_view.rb +29 -0
  81. data/lib/crummy/railtie.rb +18 -0
  82. data/lib/crummy/standard_renderer.rb +173 -0
  83. data/lib/crummy/version.rb +6 -0
  84. data/test/standard_renderer_test.rb +172 -0
  85. metadata +216 -0
@@ -0,0 +1,83 @@
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(lambda { |instance| instance.business_name }, "/")
8
+ # add_crumb("Business") { |instance| instance.business_path }
9
+ #
10
+ # Works like a before_filter so +:only+ and +except+ both work.
11
+ def add_crumb(name, *args)
12
+ options = args.extract_options!
13
+ url = args.first
14
+ raise ArgumentError, "Need more arguments" unless name or options[:record] or block_given?
15
+ raise ArgumentError, "Cannot pass url and use block" if url && block_given?
16
+ before_filter(options) do |instance|
17
+ url = yield instance if block_given?
18
+ url = instance.send url if url.is_a? Symbol
19
+
20
+ if url.present?
21
+ if url.kind_of? Array
22
+ url.map! do |name|
23
+ name.is_a?(Symbol) ? instance.instance_variable_get("@#{name}") : name
24
+ end
25
+ end
26
+ if not url.kind_of? String
27
+ url = instance.send :url_for, url
28
+ end
29
+ end
30
+
31
+ # Get the return value of the name if its a proc.
32
+ name = name.call(instance) if name.is_a?(Proc)
33
+
34
+ _record = instance.instance_variable_get("@#{name}") unless name.kind_of?(String)
35
+ if _record and _record.respond_to? :to_param
36
+ instance.add_crumb(_record.to_s, url || instance.url_for(_record), options)
37
+ else
38
+ instance.add_crumb(name, url, options)
39
+ end
40
+
41
+ # FIXME: url = instance.url_for(name) if name.respond_to?("to_param") && url.nil?
42
+ # FIXME: Add ||= for the name, url above
43
+ end
44
+ end
45
+
46
+ def clear_crumbs
47
+ before_filter do |instance|
48
+ instance.clear_crumbs
49
+ end
50
+ end
51
+ end
52
+
53
+ module InstanceMethods
54
+ # Add a crumb to the crumbs array.
55
+ #
56
+ # add_crumb("Home", "/")
57
+ # add_crumb("Business") { |instance| instance.business_path }
58
+ #
59
+ def add_crumb(name, url=nil, options={})
60
+ crumbs.push [name, url, options]
61
+ end
62
+
63
+ def clear_crumbs
64
+ crumbs.clear
65
+ end
66
+
67
+ # Lists the crumbs as an array
68
+ def crumbs
69
+ get_or_set_ivar "@_crumbs", []
70
+ end
71
+
72
+ def get_or_set_ivar(var, value) # :nodoc:
73
+ instance_variable_set var, instance_variable_get(var) || value
74
+ end
75
+ private :get_or_set_ivar
76
+ end
77
+
78
+ def self.included(receiver) # :nodoc:
79
+ receiver.extend ClassMethods
80
+ receiver.send :include, InstanceMethods
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,29 @@
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, options={})
10
+ crumbs.push [name, url, options]
11
+ end
12
+
13
+ # Render the list of crumbs using renderer
14
+ #
15
+ def render_crumbs(options = {})
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)
21
+ else
22
+ require 'crummy/standard_renderer'
23
+ Crummy::StandardRenderer.new
24
+ end
25
+
26
+ @_renderer.render_crumbs(crumbs, options)
27
+ end
28
+ end
29
+ 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
@@ -0,0 +1,173 @@
1
+ # encoding: utf-8
2
+
3
+ module Crummy
4
+ class StandardRenderer
5
+ include ActionView::Helpers::UrlHelper
6
+ include ActionView::Helpers::TagHelper unless self.included_modules.include?(ActionView::Helpers::TagHelper)
7
+ ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES.merge([:itemscope].to_set)
8
+
9
+ # Render the list of crumbs as either html or xml
10
+ #
11
+ # Takes 3 options:
12
+ # The output format. Can either be xml or html. Default :html
13
+ # :format => (:html|:xml)
14
+ # The separator text. It does not assume you want spaces on either side so you must specify. Default +&raquo;+ for :html and +crumb+ for xml
15
+ # :separator => string
16
+ # Render links in the output. Default +true+
17
+ # :link => boolean
18
+ #
19
+ # Examples:
20
+ # render_crumbs #=> <a href="/">Home</a> &raquo; <a href="/businesses">Businesses</a>
21
+ # render_crumbs :separator => ' | ' #=> <a href="/">Home</a> | <a href="/businesses">Businesses</a>
22
+ # render_crumbs :format => :xml #=> <crumb href="/">Home</crumb><crumb href="/businesses">Businesses</crumb>
23
+ # render_crumbs :format => :html_list #=> <ol class="" id=""><li class=""><a href="/">Home</a></li><li class=""><a href="/">Businesses</a></li></ol>
24
+ #
25
+ # With :format => :html_list you can specify additional params: li_class, ol_class, ol_id
26
+ # 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;+
27
+ #
28
+ # render_crumbs(" . ") #=> <a href="/">Home</a> . <a href="/businesses">Businesses</a>
29
+ #
30
+ def render_crumbs(crumbs, options = {})
31
+
32
+ options[:skip_if_blank] ||= Crummy.configuration.skip_if_blank
33
+ return '' if options[:skip_if_blank] && crumbs.count < 1
34
+ options[:format] ||= Crummy.configuration.format
35
+ options[:separator] ||= Crummy.configuration.send(:"#{options[:format]}_separator")
36
+ options[:right_separator] ||= Crummy.configuration.send(:"#{options[:format]}_right_separator")
37
+ options[:links] ||= Crummy.configuration.links
38
+ options[:first_class] ||= Crummy.configuration.first_class
39
+ options[:last_class] ||= Crummy.configuration.last_class
40
+ options[:microdata] ||= Crummy.configuration.microdata if options[:microdata].nil?
41
+ options[:truncate] ||= Crummy.configuration.truncate if options[:truncate]
42
+ options[:last_crumb_linked] = Crummy.configuration.last_crumb_linked if options[:last_crumb_linked].nil?
43
+ options[:right_side] ||= Crummy.configuration.right_side
44
+
45
+ last_hash = lambda {|o|k=o.map{|c|
46
+ c.is_a?(Hash) ? (c.empty? ? nil: c) : nil}.compact
47
+ k.empty? ? {} : k.last
48
+ }
49
+ local_global = lambda {|crumb, global_options, param_name| last_hash.call(crumb).has_key?(param_name.to_sym) ? last_hash.call(crumb)[param_name.to_sym] : global_options[param_name.to_sym]}
50
+
51
+ case options[:format]
52
+ when :html
53
+ crumb_string = crumbs.map{|crumb|local_global.call(crumb, options, :right_side) ? nil :
54
+ crumb_to_html(crumb,
55
+ local_global.call(crumb, options, :links),
56
+ local_global.call(crumb, options, :first_class),
57
+ local_global.call(crumb, options, :last_class),
58
+ (crumb == crumbs.first),
59
+ (crumb == crumbs.last),
60
+ local_global.call(crumb, options, :last_crumb_linked),
61
+ local_global.call(crumb, options, :truncate))}.compact.join(options[:separator]).html_safe
62
+ crumb_string
63
+ when :html_list
64
+ # Let's set values for special options of html_list format
65
+ options[:li_class] ||= Crummy.configuration.li_class
66
+ options[:ol_class] ||= Crummy.configuration.ol_class
67
+ options[:ol_id] ||= Crummy.configuration.ol_id
68
+ options[:ol_id] = nil if options[:ol_id].blank?
69
+
70
+ crumb_string = crumbs.map{|crumb|local_global.call(crumb, options, :right_side) ? nil :
71
+ crumb_to_html_list(crumb,
72
+ local_global.call(crumb, options, :links),
73
+ local_global.call(crumb, options, :li_class),
74
+ local_global.call(crumb, options, :first_class),
75
+ local_global.call(crumb, options, :last_class),
76
+ (crumb == crumbs.first),
77
+ (crumb == crumbs.find_all{|crumb|
78
+ !last_hash.call(crumb).fetch(:right_side,false)}.compact.last),
79
+ local_global.call(crumb, options, :microdata),
80
+ crumbs.find_index(crumb) + 1,
81
+ local_global.call(crumb, options, :last_crumb_linked),
82
+ local_global.call(crumb, options, :truncate),
83
+ local_global.call(crumb, options, :separator))}.compact.join.html_safe
84
+ crumb_right_string = crumbs.reverse.map{|crumb|!local_global.call(crumb, options, :right_side) ? nil :
85
+
86
+ crumb_to_html_list(crumb,
87
+ local_global.call(crumb, options, :links),
88
+ local_global.call(crumb, options, :li_right_class),
89
+ local_global.call(crumb, options, :first_class),
90
+ local_global.call(crumb, options, :last_class),
91
+ (crumb == crumbs.first),
92
+ (crumb == crumbs.find_all{|crumb|!local_global.call(crumb, options, :right_side)}.compact.last),
93
+ local_global.call(crumb, options, :microdata),
94
+ crumbs.find_index(crumb) + 1,
95
+ local_global.call(crumb, options, :last_crumb_linked),
96
+ local_global.call(crumb, options, :truncate),
97
+ local_global.call(crumb, options, :right_separator))}.compact.join.html_safe
98
+ ol_options = {}
99
+ ol_options[:class] = options[:ol_class]
100
+ ol_options[:id] = options[:ol_id]
101
+ if options[:microdata]
102
+ ol_options[:itemscope] = true
103
+ ol_options[:itemtype] = data_definition_url("BreadcrumbList")
104
+ end
105
+ crumb_string = content_tag(:ol, crumb_string+crumb_right_string, ol_options)
106
+ crumb_string
107
+ when :xml
108
+ crumbs.collect do |crumb|
109
+ crumb_to_xml(crumb,
110
+ local_global.call(crumb, options, :links),
111
+ local_global.call(crumb, options, :separator),
112
+ (crumb == crumbs.first),
113
+ (crumb == crumbs.last))
114
+ end * ''
115
+ else
116
+ raise ArgumentError, "Unknown breadcrumb output format"
117
+ end
118
+ end
119
+
120
+ private
121
+
122
+ def crumb_to_html(crumb, links, first_class, last_class, is_first, is_last, last_crumb_linked, truncate)
123
+ html_classes = []
124
+ html_classes << first_class if is_first
125
+ html_classes << last_class if is_last
126
+ name, url, options = crumb
127
+ options = {} unless options.is_a?(Hash)
128
+ can_link = url && links && (!is_last || last_crumb_linked)
129
+ link_html_options = options[:link_html_options] || {}
130
+ link_html_options[:class] = html_classes
131
+ if can_link
132
+ link_to((truncate.present? ? name.truncate(truncate) : name), url, link_html_options)
133
+ else
134
+ truncate.present? ? name.truncate(truncate) : name
135
+ end
136
+ end
137
+
138
+ def crumb_to_html_list(crumb, links, li_class, first_class, last_class, is_first, is_last, with_microdata, position, last_crumb_linked, truncate, separator='')
139
+ name, url, options = crumb
140
+ options = {} unless options.is_a?(Hash)
141
+ can_link = url && links && (!is_last || last_crumb_linked) && !(/<\/a/ =~ name)
142
+ html_classes = []
143
+ html_classes << first_class if is_first && !first_class.empty?
144
+ html_classes << last_class if is_last && !last_class.empty?
145
+ html_classes << li_class unless li_class.empty?
146
+ html_options = html_classes.size > 0 ? {:class => html_classes.join(' ').strip} : {}
147
+
148
+ if with_microdata
149
+ html_options[:itemscope] = true
150
+ html_options[:itemtype] = data_definition_url("ListItem")
151
+ html_options[:itemprop] = "itemListElement"
152
+ item_title = content_tag(:span, (truncate.present? ? name.truncate(truncate) : name), :itemprop => "name")
153
+ link_html_options = options[:link_html_options] || {}
154
+ link_html_options[:itemprop] = "item"
155
+ html_content = can_link ? link_to(item_title, url, link_html_options) : item_title
156
+ html_content << tag(:meta, :itemprop => "position", :content => position)
157
+ else
158
+ html_content = can_link ? link_to((truncate.present? ? name.truncate(truncate) : name), url, options[:link_html_options]) : content_tag(:span, (truncate.present? ? name.truncate(truncate) : name))
159
+ end
160
+ content_tag(:li, html_content, html_options)+(/<\/li/ =~ separator ?
161
+ separator : content_tag(:li, separator) unless separator.blank? || is_last)
162
+ end
163
+
164
+ def crumb_to_xml(crumb, links, separator, is_first, is_last)
165
+ name, url = crumb
166
+ content_tag(separator, name, :href => (url && links ? url : nil))
167
+ end
168
+
169
+ def data_definition_url(type)
170
+ "http://schema.org/#{type}"
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,6 @@
1
+ module Crummy
2
+ MAJOR = 1
3
+ MINOR = 9
4
+ PATCH = 0
5
+ VERSION = [MAJOR, MINOR, PATCH].join('.')
6
+ end
@@ -0,0 +1,172 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require(:test)
4
+ require 'test/unit'
5
+
6
+ require 'action_controller'
7
+ require 'active_support/core_ext/string/output_safety'
8
+ require 'action_dispatch/testing/assertions'
9
+ require 'crummy'
10
+ require 'crummy/standard_renderer'
11
+
12
+ class StandardRendererTest < Test::Unit::TestCase
13
+ include ActionDispatch::Assertions
14
+ include Crummy
15
+
16
+ def test_classes
17
+ renderer = StandardRenderer.new
18
+ assert_dom_equal('<a href="url" class="first last">name</a>',
19
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html))
20
+ assert_equal('<ol class=""><li class="first last"><a href="url">name</a></li></ol>',
21
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list))
22
+ assert_equal('<crumb href="url">name</crumb>',
23
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :xml))
24
+
25
+ assert_dom_equal('<a href="url1" class="first">name1</a> &raquo; <a href="url2" class="last">name2</a>',
26
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :first_class => 'first', :last_class => 'last', :format => :html))
27
+ assert_equal('<ol class=""><li class="first li_class"><a href="url1">name1</a></li><li class="li_class"><a href="url2">name2</a></li><li class="last li_class"><a href="url3">name3</a></li></ol>',
28
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2'], ['name3', 'url3']], :li_class => "li_class", :first_class => 'first', :last_class => 'last', :format => :html_list))
29
+ assert_equal('<ol class=""><li class="first li_class"><a href="url1">name1</a></li><li> / </li><li class="li_class"><a href="url2">name2</a></li><li> / </li><li class="last li_class"><a href="url3">name3</a></li></ol>',
30
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2'], ['name3', 'url3']], :li_class => "li_class", :first_class => 'first', :last_class => 'last', :format => :html_list, :separator => " / "))
31
+ assert_equal('<crumb href="url1">name1</crumb><crumb href="url2">name2</crumb>',
32
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :first_class => 'first', :last_class => 'last', :format => :xml))
33
+
34
+ assert_equal('<ol class="" itemscope="itemscope" itemtype="http://schema.org/BreadcrumbList"><li class="first last" itemscope="itemscope" itemtype="http://schema.org/ListItem" itemprop="itemListElement"><a itemprop="item" href="url"><span itemprop="name">name</span></a><meta itemprop="position" content="1" /></li></ol>',
35
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list, :microdata => true))
36
+ assert_equal('<ol class="crumbclass" id="crumbid"><li class="liclass"><a href="url">name</a></li></ol>',
37
+ renderer.render_crumbs([['name', 'url']], :format => :html_list, :ol_id => "crumbid", :ol_class => "crumbclass", :li_class => "liclass"))
38
+ end
39
+
40
+ def test_classes_last_crumb_not_linked
41
+ renderer = StandardRenderer.new
42
+ assert_equal('name',
43
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html, :last_crumb_linked => false))
44
+ assert_equal('<ol class=""><li class="first last"><span>name</span></li></ol>',
45
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list, :last_crumb_linked => false))
46
+ assert_equal('<crumb href="url">name</crumb>',
47
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :xml, :last_crumb_linked => false))
48
+
49
+ assert_dom_equal('<a href="url1" class="first">name1</a> &raquo; name2',
50
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :first_class => 'first', :last_class => 'last', :format => :html, :last_crumb_linked => false))
51
+ assert_equal('<ol class=""><li class="first li_class"><a href="url1">name1</a></li><li class="li_class"><a href="url2">name2</a></li><li class="last li_class"><span>name3</span></li></ol>',
52
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2'], ['name3', 'url3']], :li_class => "li_class", :first_class => 'first', :last_class => 'last', :format => :html_list, :last_crumb_linked => false))
53
+ assert_equal('<ol class=""><li class="first li_class"><a href="url1">name1</a></li><li> / </li><li class="li_class"><a href="url2">name2</a></li><li> / </li><li class="last li_class"><span>name3</span></li></ol>',
54
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2'], ['name3', 'url3']], :li_class => "li_class", :first_class => 'first', :last_class => 'last', :format => :html_list, :separator => " / ", :last_crumb_linked => false))
55
+ assert_equal('<crumb href="url1">name1</crumb><crumb href="url2">name2</crumb>',
56
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :first_class => 'first', :last_class => 'last', :format => :xml, :last_crumb_linked => false))
57
+
58
+ assert_equal('<ol class="" itemscope="itemscope" itemtype="http://schema.org/BreadcrumbList"><li class="first last" itemscope="itemscope" itemtype="http://schema.org/ListItem" itemprop="itemListElement"><span itemprop="name">name</span><meta itemprop="position" content="1" /></li></ol>',
59
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list, :microdata => true, :last_crumb_linked => false))
60
+ assert_equal('<ol class="crumbclass" id="crumbid"><li class="liclass"><span>name</span></li></ol>',
61
+ renderer.render_crumbs([['name', 'url']], :format => :html_list, :ol_id => "crumbid", :ol_class => "crumbclass", :li_class => "liclass", :last_crumb_linked => false))
62
+ end
63
+
64
+ def test_input_object_mutation
65
+ renderer = StandardRenderer.new
66
+ Crummy.configure do |config|
67
+ config.microdata = false
68
+ end
69
+
70
+ name1 = 'name1'
71
+ url1 = nil
72
+ name2 = 'name2'
73
+ url2 = nil
74
+
75
+ renderer.render_crumbs([[name1, url1], [name2, url2]], :format => :html, :microdata => false)
76
+
77
+ # Rendering the crumbs shouldn't alter the input objects.
78
+ assert_equal('name1', name1);
79
+ assert_equal(nil, url2);
80
+ assert_equal('name2', name2);
81
+ assert_equal(nil, url2);
82
+ end
83
+
84
+ def test_link_html_options
85
+ renderer = StandardRenderer.new
86
+ Crummy.configure do |config|
87
+ config.microdata = false
88
+ end
89
+
90
+ assert_dom_equal('<a href="url" class="first last" title="link title">name</a>',
91
+ renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html))
92
+
93
+ assert_equal('name',
94
+ renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html, :last_crumb_linked => false))
95
+
96
+ assert_equal('<ol class=""><li class="first last"><a title="link title" href="url">name</a></li></ol>',
97
+ renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html_list))
98
+
99
+ assert_equal('<ol class=""><li class="first last"><span>name</span></li></ol>',
100
+ renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html_list, :last_crumb_linked => false))
101
+ end
102
+
103
+ def test_link_html_options_with_microdata
104
+ renderer = StandardRenderer.new
105
+ Crummy.configure do |config|
106
+ config.microdata = true
107
+ end
108
+
109
+ assert_equal('<ol class="" itemscope="itemscope" itemtype="http://schema.org/BreadcrumbList"><li class="first last" itemscope="itemscope" itemtype="http://schema.org/ListItem" itemprop="itemListElement"><a title="link title" itemprop="item" href="url"><span itemprop="name">name</span></a><meta itemprop="position" content="1" /></li></ol>',
110
+ renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html_list))
111
+
112
+ assert_equal('<ol class="" itemscope="itemscope" itemtype="http://schema.org/BreadcrumbList"><li class="first last" itemscope="itemscope" itemtype="http://schema.org/ListItem" itemprop="itemListElement"><span itemprop="name">name</span><meta itemprop="position" content="1" /></li></ol>',
113
+ renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html_list, :last_crumb_linked => false))
114
+ end
115
+
116
+ def test_inline_configuration
117
+ renderer = StandardRenderer.new
118
+ Crummy.configure do |config|
119
+ config.microdata = true
120
+ config.last_crumb_linked = true
121
+ end
122
+
123
+ assert_no_match(/itemscope/, renderer.render_crumbs([['name', 'url']], :microdata => false))
124
+ assert_match(/href/, renderer.render_crumbs([['name', 'url']], :last_crumb_linked => true))
125
+
126
+ Crummy.configure do |config|
127
+ config.microdata = false
128
+ config.last_crumb_linked = true
129
+ end
130
+
131
+ assert_match(/itemscope/, renderer.render_crumbs([['name', 'url']], :microdata => true, :format => :html_list))
132
+ assert_no_match(/href/, renderer.render_crumbs([['name', 'url']], :last_crumb_linked => false))
133
+ end
134
+
135
+ def test_configuration
136
+ renderer = StandardRenderer.new
137
+ # check defaults
138
+ assert_equal " &raquo; ", Crummy.configuration.html_separator
139
+ # adjust configuration
140
+ Crummy.configure do |config|
141
+ config.html_separator = " / "
142
+ end
143
+ assert_equal " / ", Crummy.configuration.html_separator
144
+ end
145
+
146
+ def test_configured_renderer
147
+ renderer = StandardRenderer.new
148
+ Crummy.configure do |config|
149
+ config.html_separator = " / "
150
+ end
151
+ # using configured separator
152
+ assert_dom_equal('<a href="url1" class="">name1</a> / <a href="url2" class="">name2</a>',
153
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']]))
154
+ # overriding configured separator
155
+ assert_dom_equal('<a href="url1" class="">name1</a> | <a href="url2" class="">name2</a>',
156
+ renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :separator => " | "))
157
+ end
158
+
159
+ def test_configured_renderer_with_microdata
160
+ renderer = StandardRenderer.new
161
+ Crummy.configure do |config|
162
+ config.microdata = true
163
+ end
164
+ # using configured microdata setting
165
+ assert_dom_equal('<ol class="" itemscope="itemscope" itemtype="http://schema.org/BreadcrumbList"><li class="first last" itemscope="itemscope" itemtype="http://schema.org/ListItem" itemprop="itemListElement"><a itemprop="item" href="url"><span itemprop="name">name</span></a><meta itemprop="position" content="1" /></li></ol>',
166
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list))
167
+ # last crumb not linked
168
+ assert_equal('<ol class="" itemscope="itemscope" itemtype="http://schema.org/BreadcrumbList"><li class="first last" itemscope="itemscope" itemtype="http://schema.org/ListItem" itemprop="itemListElement"><span itemprop="name">name</span><meta itemprop="position" content="1" /></li></ol>',
169
+ renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list, :last_crumb_linked => false))
170
+ end
171
+
172
+ end