breadcrumbs 0.1.3 → 0.2.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 (70) hide show
  1. checksums.yaml +7 -0
  2. data/.github/FUNDING.yml +3 -0
  3. data/.gitignore +4 -0
  4. data/.rubocop.yml +22 -0
  5. data/.travis.yml +11 -0
  6. data/Gemfile +4 -0
  7. data/README.md +143 -0
  8. data/Rakefile +15 -0
  9. data/breadcrumbs.gemspec +38 -0
  10. data/examples/myapp/.gitignore +12 -0
  11. data/examples/myapp/Gemfile +12 -0
  12. data/examples/myapp/README.rdoc +28 -0
  13. data/examples/myapp/Rakefile +6 -0
  14. data/examples/myapp/app/assets/images/.keep +0 -0
  15. data/examples/myapp/app/assets/stylesheets/application.css +49 -0
  16. data/examples/myapp/app/controllers/application_controller.rb +13 -0
  17. data/examples/myapp/app/controllers/concerns/.keep +0 -0
  18. data/examples/myapp/app/controllers/site_controller.rb +9 -0
  19. data/examples/myapp/app/helpers/application_helper.rb +2 -0
  20. data/examples/myapp/app/mailers/.keep +0 -0
  21. data/examples/myapp/app/models/.keep +0 -0
  22. data/examples/myapp/app/models/concerns/.keep +0 -0
  23. data/examples/myapp/app/views/layouts/application.html.erb +15 -0
  24. data/examples/myapp/app/views/site/contact.html.erb +1 -0
  25. data/examples/myapp/app/views/site/home.html.erb +1 -0
  26. data/examples/myapp/bin/bundle +3 -0
  27. data/examples/myapp/bin/rails +4 -0
  28. data/examples/myapp/bin/rake +4 -0
  29. data/examples/myapp/bin/setup +29 -0
  30. data/examples/myapp/config.ru +4 -0
  31. data/examples/myapp/config/application.rb +30 -0
  32. data/examples/myapp/config/boot.rb +3 -0
  33. data/examples/myapp/config/environment.rb +5 -0
  34. data/examples/myapp/config/environments/development.rb +38 -0
  35. data/examples/myapp/config/environments/production.rb +73 -0
  36. data/examples/myapp/config/environments/test.rb +39 -0
  37. data/examples/myapp/config/initializers/assets.rb +11 -0
  38. data/examples/myapp/config/initializers/backtrace_silencers.rb +7 -0
  39. data/examples/myapp/config/initializers/cookies_serializer.rb +3 -0
  40. data/examples/myapp/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/examples/myapp/config/initializers/inflections.rb +16 -0
  42. data/examples/myapp/config/initializers/mime_types.rb +4 -0
  43. data/examples/myapp/config/initializers/session_store.rb +3 -0
  44. data/examples/myapp/config/initializers/wrap_parameters.rb +9 -0
  45. data/examples/myapp/config/locales/en.yml +28 -0
  46. data/examples/myapp/config/routes.rb +5 -0
  47. data/examples/myapp/config/secrets.yml +22 -0
  48. data/examples/myapp/db/seeds.rb +7 -0
  49. data/examples/myapp/lib/assets/.keep +0 -0
  50. data/examples/myapp/lib/tasks/.keep +0 -0
  51. data/examples/myapp/log/.keep +0 -0
  52. data/examples/myapp/public/404.html +67 -0
  53. data/examples/myapp/public/422.html +67 -0
  54. data/examples/myapp/public/500.html +66 -0
  55. data/examples/myapp/public/favicon.ico +0 -0
  56. data/examples/myapp/public/robots.txt +5 -0
  57. data/examples/myapp/vendor/assets/stylesheets/.keep +0 -0
  58. data/lib/breadcrumbs.rb +49 -19
  59. data/lib/breadcrumbs/action_controller_ext.rb +3 -1
  60. data/lib/breadcrumbs/render.rb +10 -3
  61. data/lib/breadcrumbs/render/base.rb +14 -17
  62. data/lib/breadcrumbs/render/inline.rb +12 -14
  63. data/lib/breadcrumbs/render/list.rb +13 -9
  64. data/lib/breadcrumbs/render/ordered_list.rb +11 -0
  65. data/lib/breadcrumbs/version.rb +4 -2
  66. data/test/breadcrumbs_test.rb +45 -30
  67. data/test/{resources/pt.yml → support/pt-BR.yml} +2 -2
  68. data/test/test_helper.rb +11 -4
  69. metadata +273 -50
  70. data/README.rdoc +0 -96
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
@@ -1,4 +1,9 @@
1
- require "i18n" unless defined?(I18n)
1
+ # frozen_string_literal: true
2
+
3
+ require "i18n"
4
+ require "action_view"
5
+ require "active_support/inflector"
6
+
2
7
  require "breadcrumbs/render"
3
8
  require "breadcrumbs/action_controller_ext" if defined?(ActionController)
4
9
 
@@ -11,42 +16,67 @@ class Breadcrumbs
11
16
 
12
17
  # Add a new breadcrumbs.
13
18
  #
14
- # breadcrumbs.add "Home"
15
- # breadcrumbs.add "Home", "/"
16
- # breadcrumbs.add "Home", "/", :class => "home"
19
+ # breadcrumbs.add 'Home'
20
+ # breadcrumbs.add 'Home', '/'
21
+ # breadcrumbs.add 'Home', '/', class: 'home'
17
22
  #
18
23
  # If you provide a symbol as text, it will try to
19
24
  # find it as I18n scope.
20
25
  #
21
26
  def add(text, url = nil, options = {})
22
- options.reverse_merge!(:i18n => true)
27
+ options = {i18n: true}.merge(options)
23
28
  text = translate(text) if options.delete(:i18n)
24
29
  items << [text.to_s, url, options]
25
30
  end
26
31
 
32
+ alias << add
33
+
27
34
  # Render breadcrumbs using the specified format.
28
35
  # Use HTML lists by default, but can be plain links.
29
36
  #
30
37
  # breadcrumbs.render
31
- # breadcrumbs.render(:format => :inline)
32
- # breadcrumbs.render(:format => :inline, :separator => "|")
33
- # breadcrumbs.render(:format => :list)
34
- # breadcrumbs.render(:id => "breadcrumbs")
35
- # breadcrumbs.render(:class => "breadcrumbs")
38
+ # breadcrumbs.render(format: "inline")
39
+ # breadcrumbs.render(format: "inline", separator: "|")
40
+ # breadcrumbs.render(format: "list")
41
+ # breadcrumbs.render(format: "ordered_list")
42
+ # breadcrumbs.render(id: 'breadcrumbs')
43
+ # breadcrumbs.render(class: 'breadcrumbs')
44
+ #
45
+ # You can also define your own formatter. Just create a class that implements
46
+ # a +render+ instance
47
+ # method and you're good to go.
48
+ #
49
+ # class Breadcrumbs::Render::Dl
50
+ # def render
51
+ # # return breadcrumbs wrapped in a <DL> tag
52
+ # end
53
+ # end
54
+ #
55
+ # To use your new format, just provide the <tt>:format</tt> option.
56
+ #
57
+ # breadcrumbs.render(format: 'dl')
36
58
  #
37
59
  def render(options = {})
38
- if options[:format] == :inline
39
- Breadcrumbs::Render::Inline.new(self, options).render
40
- else
41
- Breadcrumbs::Render::List.new(self, options).render
42
- end
43
- end
60
+ options[:format] ||= :list
44
61
 
45
- alias :<< :add
62
+ klass_name = options.delete(:format).to_s.classify
63
+ klass = Breadcrumbs::Render.const_get(klass_name)
64
+ klass.new(self, options).render
65
+ end
46
66
 
47
67
  def translate(scope) # :nodoc:
48
- text = I18n.t(scope, :scope => :breadcrumbs, :raise => true) rescue nil
49
- text ||= I18n.t(scope, :default => scope.to_s)
68
+ text = begin
69
+ I18n.t(scope, scope: "breadcrumbs", raise: true)
70
+ rescue StandardError
71
+ nil
72
+ end
73
+
74
+ text ||= begin
75
+ I18n.t(scope, default: scope.to_s)
76
+ rescue StandardError
77
+ scope
78
+ end
79
+
50
80
  text
51
81
  end
52
82
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Breadcrumbs
2
4
  module ActionController # :nodoc: all
3
5
  def self.included(base)
@@ -10,4 +12,4 @@ class Breadcrumbs
10
12
  end
11
13
  end
12
14
 
13
- ActionController::Base.send :include, Breadcrumbs::ActionController
15
+ ActionController::Base.include Breadcrumbs::ActionController
@@ -1,3 +1,10 @@
1
- require "breadcrumbs/render/base"
2
- require "breadcrumbs/render/inline"
3
- require "breadcrumbs/render/list"
1
+ # frozen_string_literal: true
2
+
3
+ class Breadcrumbs
4
+ module Render
5
+ require "breadcrumbs/render/base"
6
+ require "breadcrumbs/render/inline"
7
+ require "breadcrumbs/render/list"
8
+ require "breadcrumbs/render/ordered_list"
9
+ end
10
+ end
@@ -1,30 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Breadcrumbs
2
4
  module Render
3
5
  class Base # :nodoc: all
4
- attr_accessor :breadcrumbs
5
- attr_accessor :default_options
6
+ include ::ActionView::Helpers::TagHelper
7
+
8
+ attr_accessor :breadcrumbs, :default_options, :output_buffer
6
9
 
7
10
  def initialize(breadcrumbs, default_options = {})
8
11
  @breadcrumbs = breadcrumbs
9
12
  @default_options = default_options
10
13
  end
11
14
 
12
- # Build a HTML tag.
13
- #
14
- # tag(:p, "Hello!")
15
- # tag(:p, "Hello!", :class => "hello")
16
- # tag(:p, :class => "phrase") { "Hello" }
17
- #
18
- def tag(name, *args, &block)
19
- options = args.pop if args.last.kind_of?(Hash)
20
- options ||= {}
21
-
22
- content = args.first
23
- content = self.instance_eval(&block) if block_given?
24
-
25
- attrs = " " + options.collect {|n, v| %[%s="%s"] % [n, v] }.join(" ") unless options.empty?
15
+ def tag(name, content = "", options = {}, &block)
16
+ content_tag(name, content, options, &block)
17
+ end
26
18
 
27
- %[<#{name}#{attrs}>#{content}</#{name}>]
19
+ protected def wrap_item(url, text, options)
20
+ if url
21
+ tag(:a, text, options.merge(href: url))
22
+ else
23
+ tag(:span, text, options)
24
+ end
28
25
  end
29
26
  end
30
27
  end
@@ -1,8 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Breadcrumbs
2
4
  module Render
3
5
  class Inline < Base # :nodoc: all
4
6
  def render
5
- options = {:class => "breadcrumbs", :separator => "&#187;"}.merge(default_options)
7
+ options = {
8
+ class: "breadcrumbs",
9
+ separator: "&#187;"
10
+ }.merge(default_options)
6
11
 
7
12
  html = []
8
13
  items = breadcrumbs.items
@@ -12,30 +17,23 @@ class Breadcrumbs
12
17
  html << render_item(item, i, size)
13
18
  end
14
19
 
15
- separator = tag(:span, options[:separator], :class => "separator")
20
+ separator = tag(:span, options[:separator], class: "separator")
16
21
 
17
- html.join(" #{separator} ")
22
+ html.join(" #{separator} ").html_safe
18
23
  end
19
24
 
20
25
  def render_item(item, i, size)
21
26
  text, url, options = *item
22
- options[:class] ||= ""
23
27
 
24
- css = []
25
- css << "first" if i == 0
28
+ css = [options[:class]].compact
29
+ css << "first" if i.zero?
26
30
  css << "last" if i == size - 1
27
31
  css << "item-#{i}"
28
32
 
29
- options[:class] << " #{css.join(" ")}"
33
+ options[:class] = css.join(" ")
30
34
  options[:class].gsub!(/^ *(.*?)$/, '\\1')
31
35
 
32
- text = CGI.escapeHTML(text)
33
-
34
- if url
35
- text = tag(:a, text, options.merge(:href => url))
36
- else
37
- text = tag(:span, text, options)
38
- end
36
+ wrap_item(url, text, options)
39
37
  end
40
38
  end
41
39
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Breadcrumbs
2
4
  module Render
3
5
  class List < Base # :nodoc: all
4
6
  def render
5
- options = {:class => "breadcrumbs"}.merge(default_options)
7
+ options = {class: "breadcrumbs"}.merge(default_options)
6
8
 
7
- tag(:ul, options) do
8
- html = ""
9
+ tag(list_style, options) do
10
+ html = []
9
11
  items = breadcrumbs.items
10
12
  size = items.size
11
13
 
@@ -13,21 +15,23 @@ class Breadcrumbs
13
15
  html << render_item(item, i, size)
14
16
  end
15
17
 
16
- html
18
+ html.join.html_safe
17
19
  end
18
20
  end
19
21
 
22
+ def list_style
23
+ :ul
24
+ end
25
+
20
26
  def render_item(item, i, size)
21
27
  css = []
22
- css << "first" if i == 0
28
+ css << "first" if i.zero?
23
29
  css << "last" if i == size - 1
24
30
  css << "item-#{i}"
25
31
 
26
32
  text, url, options = *item
27
- text = CGI.escapeHTML(text)
28
- text = tag(:a, text, options.merge(:href => url)) if url
29
-
30
- tag(:li, text, :class => css.join(" "))
33
+ text = wrap_item(url, text, options)
34
+ tag(:li, text, class: css.join(" "))
31
35
  end
32
36
  end
33
37
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Breadcrumbs
4
+ module Render
5
+ class OrderedList < List # :nodoc: all
6
+ def list_style
7
+ :ol
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Breadcrumbs
2
4
  module Version # :nodoc: all
3
5
  MAJOR = 0
4
- MINOR = 1
5
- PATCH = 3
6
+ MINOR = 2
7
+ PATCH = 0
6
8
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
9
  end
8
10
  end
@@ -1,11 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
- class BreadcrumbsTest < Test::Unit::TestCase
5
+ class BreadcrumbsTest < Minitest::Test
4
6
  def setup
5
7
  @breadcrumbs = Breadcrumbs.new
6
8
  @inline = Breadcrumbs::Render::Inline.new(@breadcrumbs)
7
9
  end
8
10
 
11
+ def test_return_safe_html
12
+ assert @breadcrumbs.render(format: "list").html_safe?
13
+ end
14
+
9
15
  def test_add_item
10
16
  @breadcrumbs.add "Home"
11
17
  assert_equal 1, @breadcrumbs.items.count
@@ -14,13 +20,10 @@ class BreadcrumbsTest < Test::Unit::TestCase
14
20
  assert_equal 2, @breadcrumbs.items.count
15
21
  end
16
22
 
17
- def test_tag
18
- assert_equal "<span>Hi!</span>", @inline.tag(:span, "Hi!")
19
- end
20
-
21
23
  def test_tag_with_attributes
22
24
  expected = %[<span class="greetings" id="hi">Hi!</span>]
23
- assert_equal expected, @inline.tag(:span, "Hi!", :class => "greetings", :id => "hi")
25
+ assert_equal expected,
26
+ @inline.tag(:span, "Hi!", class: "greetings", id: "hi")
24
27
  end
25
28
 
26
29
  def test_tag_with_block
@@ -29,32 +32,44 @@ class BreadcrumbsTest < Test::Unit::TestCase
29
32
 
30
33
  def test_tag_with_block_and_attributes
31
34
  expected = %[<span class="greetings" id="hi">Hi!</span>]
32
- assert_equal expected, @inline.tag(:span, :class => "greetings", :id => "hi") { "Hi!" }
35
+ assert_equal expected,
36
+ @inline.tag(:span, class: "greetings", id: "hi") { "Hi!" }
33
37
  end
34
38
 
35
39
  def test_nested_tags
36
40
  expected = %[<span class="greetings"><strong id="hi">Hi!</strong></span>]
37
- actual = @inline.tag(:span, :class => "greetings") { tag(:strong, "Hi!", :id => "hi") }
41
+ actual = @inline.tag(:span, class: "greetings") do
42
+ @inline.tag(:strong, "Hi!", id: "hi")
43
+ end
44
+
38
45
  assert_equal expected, actual
39
46
  end
40
47
 
41
48
  def test_render_as_list
42
- @breadcrumbs.add "Home", "/", :class => "home"
49
+ @breadcrumbs.add "Home", "/", class: "home"
43
50
  html = Nokogiri::HTML(@breadcrumbs.render)
44
51
 
45
- assert_not_nil html.at("ul.breadcrumbs")
52
+ refute_nil html.at("ul.breadcrumbs")
53
+ assert_nil html.at("ul.breadcrumbs[format=list]")
54
+ end
55
+
56
+ def test_render_as_ordered_list
57
+ @breadcrumbs.add "Home", "/"
58
+ html = Nokogiri::HTML(@breadcrumbs.render(format: "ordered_list"))
59
+
60
+ refute_nil html.at("ol.breadcrumbs")
46
61
  end
47
62
 
48
63
  def test_render_as_list_with_custom_attributes
49
- @breadcrumbs.add "Home", "/", :class => "home"
50
- html = Nokogiri::HTML(@breadcrumbs.render(:id => "breadcrumbs", :class => "top"))
64
+ @breadcrumbs.add "Home", "/", class: "home"
65
+ html = Nokogiri::HTML(@breadcrumbs.render(id: "breadcrumbs", class: "top"))
51
66
 
52
- assert_not_nil html.at("ul.top#breadcrumbs")
67
+ refute_nil html.at("ul.top#breadcrumbs")
53
68
  end
54
69
 
55
70
  def test_render_as_list_add_items
56
- @breadcrumbs.add "Home", "/", :class => "home"
57
- @breadcrumbs.add "About", "/about", :class => "about"
71
+ @breadcrumbs.add "Home", "/", class: "home"
72
+ @breadcrumbs.add "About", "/about", class: "about"
58
73
  @breadcrumbs.add "People"
59
74
 
60
75
  html = Nokogiri::HTML(@breadcrumbs.render)
@@ -79,23 +94,24 @@ class BreadcrumbsTest < Test::Unit::TestCase
79
94
  assert_equal "last item-2", items[2]["class"]
80
95
  assert_equal "People", items[2].inner_text
81
96
  assert_nil items[2].at("a")
97
+ refute_nil items[2].at("span")
82
98
  end
83
99
 
84
100
  def test_render_inline
85
- @breadcrumbs.add "Home", "/", :class => "home"
86
- html = Nokogiri::HTML(@breadcrumbs.render(:format => :inline))
101
+ @breadcrumbs.add "Home", "/", class: "home"
102
+ html = Nokogiri::HTML(@breadcrumbs.render(format: "inline"))
87
103
 
88
104
  assert_nil html.at("ul.breadcrumbs")
89
105
  end
90
106
 
91
107
  def test_render_inline_add_items
92
- @breadcrumbs.add "Home", "/", :class => "home"
93
- @breadcrumbs.add "About", "/about", :class => "about"
108
+ @breadcrumbs.add "Home", "/", class: "home"
109
+ @breadcrumbs.add "About", "/about", class: "about"
94
110
  @breadcrumbs.add "People"
95
111
 
96
- html = @breadcrumbs.render(:format => :inline)
112
+ html = @breadcrumbs.render(format: "inline")
97
113
  html = Nokogiri::HTML("<div>#{html}</div>")
98
- separator = Nokogiri::HTML("<span>&#187;</span>").at("span").inner_text
114
+ separator = "&#187;"
99
115
 
100
116
  items = html.search("div *")
101
117
 
@@ -125,16 +141,16 @@ class BreadcrumbsTest < Test::Unit::TestCase
125
141
  end
126
142
 
127
143
  def test_render_inline_with_custom_separator
128
- @breadcrumbs.add "Home", "/", :class => "home"
144
+ @breadcrumbs.add "Home", "/", class: "home"
129
145
  @breadcrumbs.add "People"
130
146
 
131
- html = Nokogiri::HTML(@breadcrumbs.render(:format => :inline, :separator => "|"))
147
+ html = Nokogiri::HTML(@breadcrumbs.render(format: "inline", separator: "|"))
132
148
 
133
149
  assert_equal "|", html.at("span.separator").inner_text
134
150
  end
135
151
 
136
152
  def test_render_original_text_when_disabling_translation
137
- @breadcrumbs.add :home, nil, :i18n => false
153
+ @breadcrumbs.add :home, nil, i18n: false
138
154
  @breadcrumbs.add :people
139
155
 
140
156
  html = Nokogiri::HTML(@breadcrumbs.render)
@@ -162,7 +178,6 @@ class BreadcrumbsTest < Test::Unit::TestCase
162
178
  @breadcrumbs.add "Help"
163
179
 
164
180
  html = Nokogiri::HTML(@breadcrumbs.render)
165
-
166
181
  items = html.search("li")
167
182
 
168
183
  assert_equal "contact", items[0].inner_text
@@ -171,20 +186,20 @@ class BreadcrumbsTest < Test::Unit::TestCase
171
186
 
172
187
  def test_pimp_action_controller
173
188
  methods = ActionController::Base.instance_methods
174
- assert (methods.include?(:breadcrumbs) || methods.include?("breadcrumbs"))
189
+ assert(methods.include?(:breadcrumbs) || methods.include?("breadcrumbs"))
175
190
  end
176
191
 
177
192
  def test_escape_text_when_rendering_inline
178
193
  @breadcrumbs.add "<script>alert(1)</script>"
179
- html = @breadcrumbs.render(:format => :inline)
194
+ html = Nokogiri::HTML(@breadcrumbs.render(format: "inline"))
180
195
 
181
- assert_equal %[<span class="first last item-0">&lt;script&gt;alert(1)&lt;/script&gt;</span>], html
196
+ assert_empty html.search("script")
182
197
  end
183
198
 
184
199
  def test_escape_text_when_rendering_list
185
200
  @breadcrumbs.add "<script>alert(1)</script>"
186
- html = @breadcrumbs.render
201
+ html = Nokogiri::HTML(@breadcrumbs.render)
187
202
 
188
- assert_match /&lt;script&gt;alert\(1\)&lt;\/script&gt;/, html
203
+ assert_empty html.search("script")
189
204
  end
190
205
  end