breadcrumbs 0.1.5 → 0.3.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.
- checksums.yaml +7 -0
- data/.github/CODEOWNERS +4 -0
- data/.github/FUNDING.yml +4 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
- data/.github/ISSUE_TEMPLATE/config.yml +5 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
- data/.github/dependabot.yml +20 -0
- data/.github/workflows/ruby-tests.yml +52 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +80 -0
- data/Gemfile +4 -0
- data/LICENSE.md +20 -0
- data/README.md +142 -0
- data/Rakefile +15 -0
- data/breadcrumbs.gemspec +49 -0
- data/examples/myapp/.gitignore +12 -0
- data/examples/myapp/Gemfile +12 -0
- data/examples/myapp/README.rdoc +28 -0
- data/examples/myapp/Rakefile +6 -0
- data/examples/myapp/app/assets/images/.keep +0 -0
- data/examples/myapp/app/assets/stylesheets/application.css +49 -0
- data/examples/myapp/app/controllers/application_controller.rb +13 -0
- data/examples/myapp/app/controllers/concerns/.keep +0 -0
- data/examples/myapp/app/controllers/site_controller.rb +9 -0
- data/examples/myapp/app/helpers/application_helper.rb +2 -0
- data/examples/myapp/app/mailers/.keep +0 -0
- data/examples/myapp/app/models/.keep +0 -0
- data/examples/myapp/app/models/concerns/.keep +0 -0
- data/examples/myapp/app/views/layouts/application.html.erb +15 -0
- data/examples/myapp/app/views/site/contact.html.erb +1 -0
- data/examples/myapp/app/views/site/home.html.erb +1 -0
- data/examples/myapp/bin/bundle +3 -0
- data/examples/myapp/bin/rails +4 -0
- data/examples/myapp/bin/rake +4 -0
- data/examples/myapp/bin/setup +29 -0
- data/examples/myapp/config/application.rb +30 -0
- data/examples/myapp/config/boot.rb +3 -0
- data/examples/myapp/config/environment.rb +5 -0
- data/examples/myapp/config/environments/development.rb +38 -0
- data/examples/myapp/config/environments/production.rb +73 -0
- data/examples/myapp/config/environments/test.rb +39 -0
- data/examples/myapp/config/initializers/assets.rb +11 -0
- data/examples/myapp/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/myapp/config/initializers/cookies_serializer.rb +3 -0
- data/examples/myapp/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/myapp/config/initializers/inflections.rb +16 -0
- data/examples/myapp/config/initializers/mime_types.rb +4 -0
- data/examples/myapp/config/initializers/session_store.rb +3 -0
- data/examples/myapp/config/initializers/wrap_parameters.rb +9 -0
- data/examples/myapp/config/locales/en.yml +28 -0
- data/examples/myapp/config/routes.rb +5 -0
- data/examples/myapp/config/secrets.yml +22 -0
- data/examples/myapp/config.ru +4 -0
- data/examples/myapp/db/seeds.rb +7 -0
- data/examples/myapp/lib/assets/.keep +0 -0
- data/examples/myapp/lib/tasks/.keep +0 -0
- data/examples/myapp/log/.keep +0 -0
- data/examples/myapp/public/404.html +67 -0
- data/examples/myapp/public/422.html +67 -0
- data/examples/myapp/public/500.html +66 -0
- data/examples/myapp/public/favicon.ico +0 -0
- data/examples/myapp/public/robots.txt +5 -0
- data/examples/myapp/vendor/assets/stylesheets/.keep +0 -0
- data/lib/breadcrumbs/action_controller_ext.rb +3 -1
- data/lib/breadcrumbs/render/base.rb +9 -21
- data/lib/breadcrumbs/render/inline.rb +12 -8
- data/lib/breadcrumbs/render/list.rb +8 -8
- data/lib/breadcrumbs/render/ordered_list.rb +2 -0
- data/lib/breadcrumbs/render.rb +6 -4
- data/lib/breadcrumbs/version.rb +4 -2
- data/lib/breadcrumbs.rb +36 -21
- data/test/breadcrumbs_test.rb +71 -56
- data/test/{resources/pt.yml → support/pt-BR.yml} +3 -2
- data/test/test_helper.rb +11 -6
- metadata +288 -55
- data/README.rdoc +0 -113
|
@@ -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
|
|
File without changes
|
|
@@ -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.
|
|
15
|
+
ActionController::Base.include Breadcrumbs::ActionController
|
|
@@ -1,36 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Breadcrumbs
|
|
2
4
|
module Render
|
|
3
5
|
class Base # :nodoc: all
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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?
|
|
26
|
-
|
|
27
|
-
%[<#{name}#{attrs}>#{content}</#{name}>]
|
|
15
|
+
def tag(name, content = "", options = {}, &block)
|
|
16
|
+
content_tag(name, content, options, &block)
|
|
28
17
|
end
|
|
29
18
|
|
|
30
|
-
protected
|
|
31
|
-
def wrap_item(url, text, options)
|
|
19
|
+
protected def wrap_item(url, text, options)
|
|
32
20
|
if url
|
|
33
|
-
tag(:a, text, options.merge(:
|
|
21
|
+
tag(:a, text, options.merge(href: url))
|
|
34
22
|
else
|
|
35
23
|
tag(:span, text, options)
|
|
36
24
|
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 = {
|
|
7
|
+
options = {
|
|
8
|
+
class: "breadcrumbs",
|
|
9
|
+
separator: "»"
|
|
10
|
+
}.merge(default_options)
|
|
6
11
|
|
|
7
12
|
html = []
|
|
8
13
|
items = breadcrumbs.items
|
|
@@ -12,24 +17,23 @@ class Breadcrumbs
|
|
|
12
17
|
html << render_item(item, i, size)
|
|
13
18
|
end
|
|
14
19
|
|
|
15
|
-
separator = tag(:span, options[: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
|
|
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]
|
|
33
|
+
options[:class] = css.join(" ")
|
|
30
34
|
options[:class].gsub!(/^ *(.*?)$/, '\\1')
|
|
31
35
|
|
|
32
|
-
wrap_item(url,
|
|
36
|
+
wrap_item(url, text, options)
|
|
33
37
|
end
|
|
34
38
|
end
|
|
35
39
|
end
|
|
@@ -1,13 +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 = {
|
|
6
|
-
:class => "breadcrumbs"
|
|
7
|
-
}.merge(default_options)
|
|
7
|
+
options = {class: "breadcrumbs"}.merge(default_options)
|
|
8
8
|
|
|
9
9
|
tag(list_style, options) do
|
|
10
|
-
html =
|
|
10
|
+
html = []
|
|
11
11
|
items = breadcrumbs.items
|
|
12
12
|
size = items.size
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ class Breadcrumbs
|
|
|
15
15
|
html << render_item(item, i, size)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
html
|
|
18
|
+
html.join.html_safe
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -25,13 +25,13 @@ class Breadcrumbs
|
|
|
25
25
|
|
|
26
26
|
def render_item(item, i, size)
|
|
27
27
|
css = []
|
|
28
|
-
css << "first" if i
|
|
28
|
+
css << "first" if i.zero?
|
|
29
29
|
css << "last" if i == size - 1
|
|
30
30
|
css << "item-#{i}"
|
|
31
31
|
|
|
32
32
|
text, url, options = *item
|
|
33
|
-
text = wrap_item(url,
|
|
34
|
-
tag(:li, text, :
|
|
33
|
+
text = wrap_item(url, text, options)
|
|
34
|
+
tag(:li, text, class: css.join(" "))
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
data/lib/breadcrumbs/render.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Breadcrumbs
|
|
2
4
|
module Render
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
require "breadcrumbs/render/base"
|
|
6
|
+
require "breadcrumbs/render/inline"
|
|
7
|
+
require "breadcrumbs/render/list"
|
|
8
|
+
require "breadcrumbs/render/ordered_list"
|
|
7
9
|
end
|
|
8
10
|
end
|
data/lib/breadcrumbs/version.rb
CHANGED
data/lib/breadcrumbs.rb
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
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
|
-
require "active_support/inflector"
|
|
5
9
|
|
|
6
10
|
class Breadcrumbs
|
|
7
11
|
attr_accessor :items
|
|
@@ -12,33 +16,34 @@ class Breadcrumbs
|
|
|
12
16
|
|
|
13
17
|
# Add a new breadcrumbs.
|
|
14
18
|
#
|
|
15
|
-
# breadcrumbs.add
|
|
16
|
-
# breadcrumbs.add
|
|
17
|
-
# breadcrumbs.add
|
|
19
|
+
# breadcrumbs.add 'Home'
|
|
20
|
+
# breadcrumbs.add 'Home', '/'
|
|
21
|
+
# breadcrumbs.add 'Home', '/', class: 'home'
|
|
18
22
|
#
|
|
19
23
|
# If you provide a symbol as text, it will try to
|
|
20
24
|
# find it as I18n scope.
|
|
21
25
|
#
|
|
22
26
|
def add(text, url = nil, options = {})
|
|
23
|
-
options
|
|
27
|
+
options = {i18n: true}.merge(options)
|
|
24
28
|
text = translate(text) if options.delete(:i18n)
|
|
25
29
|
items << [text.to_s, url, options]
|
|
26
30
|
end
|
|
27
31
|
|
|
28
|
-
alias
|
|
32
|
+
alias << add
|
|
29
33
|
|
|
30
34
|
# Render breadcrumbs using the specified format.
|
|
31
35
|
# Use HTML lists by default, but can be plain links.
|
|
32
36
|
#
|
|
33
37
|
# breadcrumbs.render
|
|
34
|
-
# breadcrumbs.render(:
|
|
35
|
-
# breadcrumbs.render(:
|
|
36
|
-
# breadcrumbs.render(:
|
|
37
|
-
# breadcrumbs.render(:
|
|
38
|
-
# breadcrumbs.render(:
|
|
39
|
-
# breadcrumbs.render(:
|
|
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')
|
|
40
44
|
#
|
|
41
|
-
# You can also define your own formatter. Just create a class that implements
|
|
45
|
+
# You can also define your own formatter. Just create a class that implements
|
|
46
|
+
# a +render+ instance
|
|
42
47
|
# method and you're good to go.
|
|
43
48
|
#
|
|
44
49
|
# class Breadcrumbs::Render::Dl
|
|
@@ -49,21 +54,31 @@ class Breadcrumbs
|
|
|
49
54
|
#
|
|
50
55
|
# To use your new format, just provide the <tt>:format</tt> option.
|
|
51
56
|
#
|
|
52
|
-
# breadcrumbs.render(:
|
|
57
|
+
# breadcrumbs.render(format: 'dl')
|
|
53
58
|
#
|
|
54
59
|
def render(options = {})
|
|
55
60
|
options[:format] ||= :list
|
|
56
61
|
|
|
57
|
-
klass_name = options
|
|
62
|
+
klass_name = options.delete(:format).to_s.classify
|
|
58
63
|
klass = Breadcrumbs::Render.const_get(klass_name)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
html.respond_to?(:html_safe) ? html.html_safe : html
|
|
64
|
+
klass.new(self, options).render
|
|
62
65
|
end
|
|
63
66
|
|
|
64
67
|
def translate(scope) # :nodoc:
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
return scope if scope.match?(/\A[\s.]+\z/)
|
|
69
|
+
|
|
70
|
+
text = begin
|
|
71
|
+
I18n.t(scope, scope: "breadcrumbs", raise: true)
|
|
72
|
+
rescue StandardError
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
text ||= begin
|
|
77
|
+
I18n.t(scope, default: scope.to_s)
|
|
78
|
+
rescue StandardError
|
|
79
|
+
scope
|
|
80
|
+
end
|
|
81
|
+
|
|
67
82
|
text
|
|
68
83
|
end
|
|
69
84
|
end
|
data/test/breadcrumbs_test.rb
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "test_helper"
|
|
2
4
|
|
|
3
|
-
class BreadcrumbsTest < Test
|
|
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
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
html_mock.expects(:html_safe).once
|
|
12
|
-
Breadcrumbs::Render::List.any_instance.stubs(:render).returns(html_mock)
|
|
13
|
-
@breadcrumbs.render(:format => :list)
|
|
11
|
+
test "returns safe html" do
|
|
12
|
+
assert @breadcrumbs.render(format: "list").html_safe?
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
test "adds item" do
|
|
17
16
|
@breadcrumbs.add "Home"
|
|
18
17
|
assert_equal 1, @breadcrumbs.items.count
|
|
19
18
|
|
|
@@ -21,54 +20,56 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
|
21
20
|
assert_equal 2, @breadcrumbs.items.count
|
|
22
21
|
end
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
assert_equal "<span>Hi!</span>", @inline.tag(:span, "Hi!")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def test_tag_with_attributes
|
|
23
|
+
test "renders tag with attributes" do
|
|
29
24
|
expected = %[<span class="greetings" id="hi">Hi!</span>]
|
|
30
|
-
assert_equal expected,
|
|
25
|
+
assert_equal expected,
|
|
26
|
+
@inline.tag(:span, "Hi!", class: "greetings", id: "hi")
|
|
31
27
|
end
|
|
32
28
|
|
|
33
|
-
|
|
29
|
+
test "renders tag with block" do
|
|
34
30
|
assert_equal "<span>Hi!</span>", @inline.tag(:span) { "Hi!" }
|
|
35
31
|
end
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
test "renders tag with block and attributes" do
|
|
38
34
|
expected = %[<span class="greetings" id="hi">Hi!</span>]
|
|
39
|
-
assert_equal expected,
|
|
35
|
+
assert_equal expected,
|
|
36
|
+
@inline.tag(:span, class: "greetings", id: "hi") { "Hi!" }
|
|
40
37
|
end
|
|
41
38
|
|
|
42
|
-
|
|
39
|
+
test "renders nested tags" do
|
|
43
40
|
expected = %[<span class="greetings"><strong id="hi">Hi!</strong></span>]
|
|
44
|
-
actual = @inline.tag(:span, :
|
|
41
|
+
actual = @inline.tag(:span, class: "greetings") do
|
|
42
|
+
@inline.tag(:strong, "Hi!", id: "hi")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
45
|
assert_equal expected, actual
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
@breadcrumbs.add "Home", "/", :
|
|
48
|
+
test "renders as list" do
|
|
49
|
+
@breadcrumbs.add "Home", "/", class: "home"
|
|
50
50
|
html = Nokogiri::HTML(@breadcrumbs.render)
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
refute_nil html.at("ul.breadcrumbs")
|
|
53
|
+
assert_nil html.at("ul.breadcrumbs[format=list]")
|
|
53
54
|
end
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
test "renders as ordered list" do
|
|
56
57
|
@breadcrumbs.add "Home", "/"
|
|
57
|
-
html = Nokogiri::HTML(@breadcrumbs.render(:
|
|
58
|
+
html = Nokogiri::HTML(@breadcrumbs.render(format: "ordered_list"))
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
refute_nil html.at("ol.breadcrumbs")
|
|
60
61
|
end
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
@breadcrumbs.add "Home", "/", :
|
|
64
|
-
html = Nokogiri::HTML(@breadcrumbs.render(:
|
|
63
|
+
test "renders as list with custom attributes" do
|
|
64
|
+
@breadcrumbs.add "Home", "/", class: "home"
|
|
65
|
+
html = Nokogiri::HTML(@breadcrumbs.render(id: "breadcrumbs", class: "top"))
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
refute_nil html.at("ul.top#breadcrumbs")
|
|
67
68
|
end
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
@breadcrumbs.add "Home", "/", :
|
|
71
|
-
@breadcrumbs.add "About", "/about", :
|
|
70
|
+
test "renders as list add items" do
|
|
71
|
+
@breadcrumbs.add "Home", "/", class: "home"
|
|
72
|
+
@breadcrumbs.add "About", "/about", class: "about"
|
|
72
73
|
@breadcrumbs.add "People"
|
|
73
74
|
|
|
74
75
|
html = Nokogiri::HTML(@breadcrumbs.render)
|
|
@@ -93,24 +94,24 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
|
93
94
|
assert_equal "last item-2", items[2]["class"]
|
|
94
95
|
assert_equal "People", items[2].inner_text
|
|
95
96
|
assert_nil items[2].at("a")
|
|
96
|
-
|
|
97
|
+
refute_nil items[2].at("span")
|
|
97
98
|
end
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
@breadcrumbs.add "Home", "/", :
|
|
101
|
-
html = Nokogiri::HTML(@breadcrumbs.render(:
|
|
100
|
+
test "renders inline" do
|
|
101
|
+
@breadcrumbs.add "Home", "/", class: "home"
|
|
102
|
+
html = Nokogiri::HTML(@breadcrumbs.render(format: "inline"))
|
|
102
103
|
|
|
103
104
|
assert_nil html.at("ul.breadcrumbs")
|
|
104
105
|
end
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
@breadcrumbs.add "Home", "/", :
|
|
108
|
-
@breadcrumbs.add "About", "/about", :
|
|
107
|
+
test "renders inline add items" do
|
|
108
|
+
@breadcrumbs.add "Home", "/", class: "home"
|
|
109
|
+
@breadcrumbs.add "About", "/about", class: "about"
|
|
109
110
|
@breadcrumbs.add "People"
|
|
110
111
|
|
|
111
|
-
html = @breadcrumbs.render(:
|
|
112
|
+
html = @breadcrumbs.render(format: "inline")
|
|
112
113
|
html = Nokogiri::HTML("<div>#{html}</div>")
|
|
113
|
-
separator =
|
|
114
|
+
separator = "»"
|
|
114
115
|
|
|
115
116
|
items = html.search("div *")
|
|
116
117
|
|
|
@@ -139,17 +140,17 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
|
139
140
|
assert_equal "People", items[4].inner_text
|
|
140
141
|
end
|
|
141
142
|
|
|
142
|
-
|
|
143
|
-
@breadcrumbs.add "Home", "/", :
|
|
143
|
+
test "renders inline with custom separator" do
|
|
144
|
+
@breadcrumbs.add "Home", "/", class: "home"
|
|
144
145
|
@breadcrumbs.add "People"
|
|
145
146
|
|
|
146
|
-
html = Nokogiri::HTML(@breadcrumbs.render(:
|
|
147
|
+
html = Nokogiri::HTML(@breadcrumbs.render(format: "inline", separator: "|"))
|
|
147
148
|
|
|
148
149
|
assert_equal "|", html.at("span.separator").inner_text
|
|
149
150
|
end
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
@breadcrumbs.add :home, nil, :
|
|
152
|
+
test "renders original text when disabling_translation" do
|
|
153
|
+
@breadcrumbs.add :home, nil, i18n: false
|
|
153
154
|
@breadcrumbs.add :people
|
|
154
155
|
|
|
155
156
|
html = Nokogiri::HTML(@breadcrumbs.render)
|
|
@@ -160,7 +161,7 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
|
160
161
|
assert_equal "Nosso time", items[1].inner_text
|
|
161
162
|
end
|
|
162
163
|
|
|
163
|
-
|
|
164
|
+
test "renders internationalized text using default scope" do
|
|
164
165
|
@breadcrumbs.add :home
|
|
165
166
|
@breadcrumbs.add :people
|
|
166
167
|
|
|
@@ -172,34 +173,48 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
|
172
173
|
assert_equal "Nosso time", items[1].inner_text
|
|
173
174
|
end
|
|
174
175
|
|
|
175
|
-
|
|
176
|
+
test "renders scope as text for missing scope" do
|
|
176
177
|
@breadcrumbs.add :contact
|
|
177
178
|
@breadcrumbs.add "Help"
|
|
178
179
|
|
|
179
180
|
html = Nokogiri::HTML(@breadcrumbs.render)
|
|
180
|
-
|
|
181
181
|
items = html.search("li")
|
|
182
182
|
|
|
183
183
|
assert_equal "contact", items[0].inner_text
|
|
184
184
|
assert_equal "Help", items[1].inner_text
|
|
185
185
|
end
|
|
186
186
|
|
|
187
|
-
|
|
187
|
+
test "extends action controller" do
|
|
188
188
|
methods = ActionController::Base.instance_methods
|
|
189
|
-
assert
|
|
189
|
+
assert(methods.include?(:breadcrumbs) || methods.include?("breadcrumbs"))
|
|
190
190
|
end
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
test "escapes text when rendering inline" do
|
|
193
193
|
@breadcrumbs.add "<script>alert(1)</script>"
|
|
194
|
-
html = @breadcrumbs.render(:
|
|
194
|
+
html = Nokogiri::HTML(@breadcrumbs.render(format: "inline"))
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
assert_empty html.search("script")
|
|
197
197
|
end
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
test "escapes text when rendering list" do
|
|
200
200
|
@breadcrumbs.add "<script>alert(1)</script>"
|
|
201
|
-
html = @breadcrumbs.render
|
|
201
|
+
html = Nokogiri::HTML(@breadcrumbs.render)
|
|
202
|
+
|
|
203
|
+
assert_empty html.search("script")
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
test "renders dots as breadcrumb items" do
|
|
207
|
+
@breadcrumbs.add "."
|
|
208
|
+
@breadcrumbs.add ".."
|
|
209
|
+
@breadcrumbs.add "..."
|
|
210
|
+
@breadcrumbs.add ". . ."
|
|
211
|
+
html = Nokogiri::HTML(@breadcrumbs.render)
|
|
212
|
+
|
|
213
|
+
items = html.search("li")
|
|
202
214
|
|
|
203
|
-
|
|
215
|
+
assert_equal ".", items[0].inner_text
|
|
216
|
+
assert_equal "..", items[1].inner_text
|
|
217
|
+
assert_equal "...", items[2].inner_text
|
|
218
|
+
assert_equal ". . .", items[3].inner_text
|
|
204
219
|
end
|
|
205
220
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require "
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "simplecov"
|
|
4
|
+
SimpleCov.start
|
|
5
|
+
|
|
6
|
+
require "bundler/setup"
|
|
7
|
+
require "minitest/utils"
|
|
8
|
+
require "minitest/autorun"
|
|
4
9
|
require "cgi"
|
|
5
10
|
require "nokogiri"
|
|
6
11
|
require "action_controller"
|
|
7
|
-
require "mocha"
|
|
12
|
+
require "mocha/test_unit"
|
|
8
13
|
|
|
9
14
|
require "breadcrumbs"
|
|
10
15
|
|
|
11
|
-
I18n.load_path << File.dirname(__FILE__)
|
|
12
|
-
I18n.locale =
|
|
16
|
+
I18n.load_path << "#{File.dirname(__FILE__)}/support/pt-BR.yml"
|
|
17
|
+
I18n.locale = "pt-BR"
|