breadcrumbs 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8bdbdf372fa1a15d2268090d73f6fe86895d6040
4
- data.tar.gz: 5e8930edb2dd75fcfa6b2cb4a97b58f7d23b26ab
2
+ SHA256:
3
+ metadata.gz: 638b77085849ea1f06cb4c55b11f3baecaaeae84b5fce2c98e8421ac18e20929
4
+ data.tar.gz: 3bd0227aa31d6630f29b6d2c7e37a1ba3a76df992cfe716bb1bc343473abff19
5
5
  SHA512:
6
- metadata.gz: 048a538d414631e8a81af252f2dbabfd918de128d9ea0c110543a44d65357483e71efc43a75915c0d89c9c3a517e5729d7d80cf7075b7beb69e17b4c293f14a6
7
- data.tar.gz: 8079caa6ef44eed3924bfa3db4791e7e2f1f6db33f2e30e210ef3eb1ae9a81cb2ff48213b2bd7017b31b136b3979d5345155141de132e10bfcaf2c84e0144b8e
6
+ metadata.gz: 676edfeedcdd4a914bfbb2ad3caa6a29e6be4ab9f50f4106f715510a52a669eca7504c1ee99854f712cb929a0723436d7cfd63fccd8e471050249c4c40ef9e1e
7
+ data.tar.gz: 4a015506ccc94efa8cd8b228ac38dda10409e88e60191036a4e3fc5a6fc1f909e36292b9fe3dace9cf5541bc4886f0e5491e250f7a1386aaab66c620e2802bb7
@@ -0,0 +1,3 @@
1
+ ---
2
+ github: [fnando]
3
+ custom: ["https://www.paypal.me/nandovieira/🍕"]
data/.gitignore CHANGED
@@ -1,2 +1,4 @@
1
1
  pkg
2
- doc
2
+ doc
3
+ *.lock
4
+ coverage
@@ -0,0 +1,22 @@
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+ Exclude:
9
+ - examples/**/*
10
+ - vendor/**/*
11
+
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+
15
+ Metrics/AbcSize:
16
+ Enabled: false
17
+
18
+ Metrics/MethodLength:
19
+ Enabled: false
20
+
21
+ Metrics/ClassLength:
22
+ Enabled: false
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+ rvm:
5
+ - 2.7.1
6
+ - 2.6.5
7
+ notifications:
8
+ email: false
9
+ env:
10
+ global:
11
+ secure: e3cKbK2ru5Wx2Jir+PUUTQFx/lrYESRMhqPPgGQ1Eq6Xc8kQ+ACxuLmgFZEZOD1aUlCVfvm8kpIJ8uVhKystwotjV3ObK2imgWvpoJLfvgIWXZ3dhIWmVI98Da1I2t66LM+1l9LREzQm2bN7zAx7NPr2oRHasDpuNc13BnIcIsg=
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
  gemspec
@@ -0,0 +1,143 @@
1
+ # Breadcrumbs
2
+
3
+ [![Travis-CI](https://travis-ci.org/fnando/breadcrumbs.svg)](https://travis-ci.org/fnando/breadcrumbs)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/breadcrumbs/badges/gpa.svg)](https://codeclimate.com/github/fnando/breadcrumbs)
5
+ [![Gem](https://img.shields.io/gem/v/breadcrumbs.svg)](https://rubygems.org/gems/breadcrumbs)
6
+ [![Gem](https://img.shields.io/gem/dt/breadcrumbs.svg)](https://rubygems.org/gems/breadcrumbs)
7
+
8
+ Breadcrumbs is a simple plugin that adds a `breadcrumbs` object to controllers
9
+ and views.
10
+
11
+ ## Instalation
12
+
13
+ Just run `gem install breadcrumbs`. Or add `gem "breadcrumbs"` to your Gemfile.
14
+
15
+ ## Usage
16
+
17
+ On your controller (optional):
18
+
19
+ ```ruby
20
+ class ApplicationController < ActionController::Base
21
+ before_filter :add_initial_breadcrumbs
22
+
23
+ private
24
+ def add_initial_breadcrumbs
25
+ breadcrumbs.add "Home", root_path
26
+ end
27
+ end
28
+
29
+ class ThingsController < ApplicationController
30
+ def index
31
+ breadcrumbs.add "Things", things_path
32
+ end
33
+ end
34
+ ```
35
+
36
+ You don't need to provide an URL; in that case, a span will be generated instead
37
+ of a link:
38
+
39
+ ```ruby
40
+ breadcrumbs.add "Some page"
41
+ ```
42
+
43
+ You can set additional HTML attributes if you need to:
44
+
45
+ ```ruby
46
+ breadcrumbs.add "Home", root_path, id: "home", title: "Go to the home page"
47
+ ```
48
+
49
+ On your view (possibly application.html.erb):
50
+
51
+ ```erb
52
+ <%= breadcrumbs.render %>
53
+ ```
54
+
55
+ You can render as ordered list.
56
+
57
+ ```erb
58
+ <%= breadcrumbs.render(format: :ordered_list) %>
59
+ ```
60
+
61
+ You can render as inline links.
62
+
63
+ ```erb
64
+ <%= breadcrumbs.render(format: :inline) %>
65
+ ```
66
+
67
+ You can set your own separator:
68
+
69
+ ```erb
70
+ <p>
71
+ You are here: <%= breadcrumbs.render(format: :inline, separator: "|") %>
72
+ </p>
73
+ ```
74
+
75
+ You can also define your own formatter. Just create a class that implements a
76
+ `render` instance method and you're good to go.
77
+
78
+ ```ruby
79
+ class Breadcrumbs::Render::Dl
80
+ def render
81
+ # return breadcrumbs wrapped in a <dl> tag
82
+ end
83
+ end
84
+ ```
85
+
86
+ To use your new format, just provide the `:format` option.
87
+
88
+ ```ruby
89
+ breadcrumbs.render(format: :dl)
90
+ ```
91
+
92
+ ### I18n
93
+
94
+ Breadcrumbs is integrated with I18n. You can set translations like:
95
+
96
+ ```yaml
97
+ en:
98
+ breadcrumbs:
99
+ home: "Home"
100
+ ```
101
+
102
+ And then you just call
103
+
104
+ ```ruby
105
+ breadcrumbs.add :home
106
+ ```
107
+
108
+ In fact, you can provide any scope you want.
109
+
110
+ ```ruby
111
+ breadcrumbs.add :"titles.home"
112
+ ```
113
+
114
+ If you don't want to translate a label, just pass the option `:i18n` as `false`.
115
+
116
+ ```ruby
117
+ breadcrumbs.add :home, nil, i18n: false
118
+ ```
119
+
120
+ ## Maintainer
121
+
122
+ - Nando Vieira - http://nandovieira.com
123
+
124
+ ## License
125
+
126
+ (The MIT License)
127
+
128
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
129
+ this software and associated documentation files (the 'Software'), to deal in
130
+ the Software without restriction, including without limitation the rights to
131
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
132
+ the Software, and to permit persons to whom the Software is furnished to do so,
133
+ subject to the following conditions:
134
+
135
+ The above copyright notice and this permission notice shall be included in all
136
+ copies or substantial portions of the Software.
137
+
138
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
139
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
140
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
141
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
142
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
143
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,10 +1,15 @@
1
- require "bundler"
2
- Bundler::GemHelper.install_tasks
1
+ # frozen_string_literal: true
3
2
 
3
+ require "bundler/gem_tasks"
4
4
  require "rake/testtask"
5
- Rake::TestTask.new do |t|
5
+ require "rubocop/rake_task"
6
+
7
+ Rake::TestTask.new(:test) do |t|
6
8
  t.libs << "test"
7
- t.libs << "lib"
8
9
  t.test_files = FileList["test/**/*_test.rb"]
9
- t.verbose = true
10
+ t.warning = false
10
11
  end
12
+
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[test rubocop]
@@ -1,6 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "breadcrumbs/version"
1
+ # frozen_string_literal: true
2
+
3
+ require "./lib/breadcrumbs/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "breadcrumbs"
@@ -9,19 +9,30 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Nando Vieira"]
10
10
  s.email = ["fnando.vieira@gmail.com"]
11
11
  s.homepage = "http://rubygems.org/gems/breadcrumbs"
12
- s.summary = "Breadcrumbs is a simple plugin that adds a `breadcrumbs` object to controllers and views."
12
+ s.summary = "Breadcrumbs is a simple plugin that adds a `breadcrumbs` " \
13
+ "object to controllers and views."
13
14
  s.description = s.summary
15
+ s.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
14
16
 
15
17
  s.files = `git ls-files`.split("\n")
16
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.executables = `git ls-files -- bin/*`
20
+ .split("\n")
21
+ .map {|f| File.basename(f) }
18
22
  s.require_paths = ["lib"]
19
23
 
24
+ s.add_dependency "actionview"
25
+ s.add_dependency "activesupport"
20
26
  s.add_dependency "i18n"
21
27
 
22
- s.add_development_dependency "nokogiri"
23
28
  s.add_development_dependency "actionpack"
29
+ s.add_development_dependency "bundler"
30
+ s.add_development_dependency "minitest-utils"
24
31
  s.add_development_dependency "mocha"
32
+ s.add_development_dependency "nokogiri"
33
+ s.add_development_dependency "pry-meta"
25
34
  s.add_development_dependency "rake"
26
- s.add_development_dependency "test-unit"
35
+ s.add_development_dependency "rubocop"
36
+ s.add_development_dependency "rubocop-fnando"
37
+ s.add_development_dependency "simplecov"
27
38
  end
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
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
@@ -25,20 +29,21 @@ class Breadcrumbs
25
29
  items << [text.to_s, url, options]
26
30
  end
27
31
 
28
- alias :<< :add
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(format: 'inline')
35
- # breadcrumbs.render(format: 'inline', separator: '|')
36
- # breadcrumbs.render(format: 'list')
37
- # breadcrumbs.render(format: 'ordered_list')
38
+ # breadcrumbs.render(format: "inline")
39
+ # breadcrumbs.render(format: "inline", separator: "|")
40
+ # breadcrumbs.render(format: "list")
41
+ # breadcrumbs.render(format: "ordered_list")
38
42
  # breadcrumbs.render(id: 'breadcrumbs')
39
43
  # breadcrumbs.render(class: 'breadcrumbs')
40
44
  #
41
- # You can also define your own formatter. Just create a class that implements a +render+ instance
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
@@ -56,14 +61,22 @@ class Breadcrumbs
56
61
 
57
62
  klass_name = options.delete(:format).to_s.classify
58
63
  klass = Breadcrumbs::Render.const_get(klass_name)
59
- html = klass.new(self, options).render
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
- text = I18n.t(scope, scope: 'breadcrumbs', raise: true) rescue nil
66
- text ||= I18n.t(scope, default: scope.to_s) rescue scope
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
+
67
80
  text
68
81
  end
69
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,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Breadcrumbs
2
4
  module Render
3
5
  require "breadcrumbs/render/base"
@@ -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
- 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?
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(:href => url))
21
+ tag(:a, text, options.merge(href: url))
34
22
  else
35
23
  tag(:span, text, options)
36
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Breadcrumbs
2
4
  module Render
3
5
  class Inline < Base # :nodoc: all
@@ -17,22 +19,21 @@ class Breadcrumbs
17
19
 
18
20
  separator = tag(:span, options[:separator], class: "separator")
19
21
 
20
- html.join(" #{separator} ")
22
+ html.join(" #{separator} ").html_safe
21
23
  end
22
24
 
23
25
  def render_item(item, i, size)
24
26
  text, url, options = *item
25
- options[:class] ||= ""
26
27
 
27
- css = []
28
- css << "first" if i == 0
28
+ css = [options[:class]].compact
29
+ css << "first" if i.zero?
29
30
  css << "last" if i == size - 1
30
31
  css << "item-#{i}"
31
32
 
32
- options[:class] << " #{css.join(" ")}"
33
+ options[:class] = css.join(" ")
33
34
  options[:class].gsub!(/^ *(.*?)$/, '\\1')
34
35
 
35
- wrap_item(url, CGI.escapeHTML(text), options)
36
+ wrap_item(url, text, options)
36
37
  end
37
38
  end
38
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Breadcrumbs
2
4
  module Render
3
5
  class List < Base # :nodoc: all
@@ -5,7 +7,7 @@ class Breadcrumbs
5
7
  options = {class: "breadcrumbs"}.merge(default_options)
6
8
 
7
9
  tag(list_style, options) do
8
- html = ''
10
+ html = []
9
11
  items = breadcrumbs.items
10
12
  size = items.size
11
13
 
@@ -13,7 +15,7 @@ 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
 
@@ -23,12 +25,12 @@ class Breadcrumbs
23
25
 
24
26
  def render_item(item, i, size)
25
27
  css = []
26
- css << "first" if i == 0
28
+ css << "first" if i.zero?
27
29
  css << "last" if i == size - 1
28
30
  css << "item-#{i}"
29
31
 
30
32
  text, url, options = *item
31
- text = wrap_item(url, CGI.escapeHTML(text), options)
33
+ text = wrap_item(url, text, options)
32
34
  tag(:li, text, class: css.join(" "))
33
35
  end
34
36
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Breadcrumbs
2
4
  module Render
3
5
  class OrderedList < List # :nodoc: all
@@ -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 = 7
6
+ MINOR = 2
7
+ PATCH = 0
6
8
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
9
  end
8
10
  end
@@ -1,17 +1,15 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
- class BreadcrumbsTest < Test::Unit::TestCase
5
+ class BreadcrumbsTest < Minitest::Test
5
6
  def setup
6
7
  @breadcrumbs = Breadcrumbs.new
7
8
  @inline = Breadcrumbs::Render::Inline.new(@breadcrumbs)
8
9
  end
9
10
 
10
11
  def test_return_safe_html
11
- html_mock = mock()
12
- html_mock.expects(:html_safe).once
13
- Breadcrumbs::Render::List.any_instance.stubs(:render).returns(html_mock)
14
- @breadcrumbs.render(format: "list")
12
+ assert @breadcrumbs.render(format: "list").html_safe?
15
13
  end
16
14
 
17
15
  def test_add_item
@@ -22,13 +20,10 @@ class BreadcrumbsTest < Test::Unit::TestCase
22
20
  assert_equal 2, @breadcrumbs.items.count
23
21
  end
24
22
 
25
- def test_tag
26
- assert_equal "<span>Hi!</span>", @inline.tag(:span, "Hi!")
27
- end
28
-
29
23
  def test_tag_with_attributes
30
24
  expected = %[<span class="greetings" id="hi">Hi!</span>]
31
- assert_equal expected, @inline.tag(:span, "Hi!", class: "greetings", id: "hi")
25
+ assert_equal expected,
26
+ @inline.tag(:span, "Hi!", class: "greetings", id: "hi")
32
27
  end
33
28
 
34
29
  def test_tag_with_block
@@ -37,12 +32,16 @@ class BreadcrumbsTest < Test::Unit::TestCase
37
32
 
38
33
  def test_tag_with_block_and_attributes
39
34
  expected = %[<span class="greetings" id="hi">Hi!</span>]
40
- assert_equal expected, @inline.tag(:span, class: "greetings", id: "hi") { "Hi!" }
35
+ assert_equal expected,
36
+ @inline.tag(:span, class: "greetings", id: "hi") { "Hi!" }
41
37
  end
42
38
 
43
39
  def test_nested_tags
44
40
  expected = %[<span class="greetings"><strong id="hi">Hi!</strong></span>]
45
- 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
+
46
45
  assert_equal expected, actual
47
46
  end
48
47
 
@@ -50,7 +49,7 @@ class BreadcrumbsTest < Test::Unit::TestCase
50
49
  @breadcrumbs.add "Home", "/", class: "home"
51
50
  html = Nokogiri::HTML(@breadcrumbs.render)
52
51
 
53
- assert_not_nil html.at("ul.breadcrumbs")
52
+ refute_nil html.at("ul.breadcrumbs")
54
53
  assert_nil html.at("ul.breadcrumbs[format=list]")
55
54
  end
56
55
 
@@ -58,14 +57,14 @@ class BreadcrumbsTest < Test::Unit::TestCase
58
57
  @breadcrumbs.add "Home", "/"
59
58
  html = Nokogiri::HTML(@breadcrumbs.render(format: "ordered_list"))
60
59
 
61
- assert_not_nil html.at("ol.breadcrumbs")
60
+ refute_nil html.at("ol.breadcrumbs")
62
61
  end
63
62
 
64
63
  def test_render_as_list_with_custom_attributes
65
64
  @breadcrumbs.add "Home", "/", class: "home"
66
65
  html = Nokogiri::HTML(@breadcrumbs.render(id: "breadcrumbs", class: "top"))
67
66
 
68
- assert_not_nil html.at("ul.top#breadcrumbs")
67
+ refute_nil html.at("ul.top#breadcrumbs")
69
68
  end
70
69
 
71
70
  def test_render_as_list_add_items
@@ -95,7 +94,7 @@ class BreadcrumbsTest < Test::Unit::TestCase
95
94
  assert_equal "last item-2", items[2]["class"]
96
95
  assert_equal "People", items[2].inner_text
97
96
  assert_nil items[2].at("a")
98
- assert_not_nil items[2].at("span")
97
+ refute_nil items[2].at("span")
99
98
  end
100
99
 
101
100
  def test_render_inline
@@ -112,7 +111,7 @@ class BreadcrumbsTest < Test::Unit::TestCase
112
111
 
113
112
  html = @breadcrumbs.render(format: "inline")
114
113
  html = Nokogiri::HTML("<div>#{html}</div>")
115
- separator = Nokogiri::HTML("<span>&#187;</span>").at("span").inner_text
114
+ separator = "&#187;"
116
115
 
117
116
  items = html.search("div *")
118
117
 
@@ -179,7 +178,6 @@ class BreadcrumbsTest < Test::Unit::TestCase
179
178
  @breadcrumbs.add "Help"
180
179
 
181
180
  html = Nokogiri::HTML(@breadcrumbs.render)
182
-
183
181
  items = html.search("li")
184
182
 
185
183
  assert_equal "contact", items[0].inner_text
@@ -188,20 +186,20 @@ class BreadcrumbsTest < Test::Unit::TestCase
188
186
 
189
187
  def test_pimp_action_controller
190
188
  methods = ActionController::Base.instance_methods
191
- assert (methods.include?(:breadcrumbs) || methods.include?("breadcrumbs"))
189
+ assert(methods.include?(:breadcrumbs) || methods.include?("breadcrumbs"))
192
190
  end
193
191
 
194
192
  def test_escape_text_when_rendering_inline
195
193
  @breadcrumbs.add "<script>alert(1)</script>"
196
- html = @breadcrumbs.render(format: "inline")
194
+ html = Nokogiri::HTML(@breadcrumbs.render(format: "inline"))
197
195
 
198
- assert_equal %[<span class="first last item-0">&lt;script&gt;alert(1)&lt;/script&gt;</span>], html
196
+ assert_empty html.search("script")
199
197
  end
200
198
 
201
199
  def test_escape_text_when_rendering_list
202
200
  @breadcrumbs.add "<script>alert(1)</script>"
203
- html = @breadcrumbs.render
201
+ html = Nokogiri::HTML(@breadcrumbs.render)
204
202
 
205
- assert_match /&lt;script&gt;alert\(1\)&lt;\/script&gt;/, html
203
+ assert_empty html.search("script")
206
204
  end
207
205
  end
@@ -1,5 +1,11 @@
1
- require "bundler"
2
- require "test/unit"
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"
3
9
  require "cgi"
4
10
  require "nokogiri"
5
11
  require "action_controller"
@@ -7,5 +13,5 @@ require "mocha/test_unit"
7
13
 
8
14
  require "breadcrumbs"
9
15
 
10
- I18n.load_path << File.dirname(__FILE__) + "/support/pt-BR.yml"
16
+ I18n.load_path << "#{File.dirname(__FILE__)}/support/pt-BR.yml"
11
17
  I18n.locale = "pt-BR"
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breadcrumbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-03 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: i18n
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -25,7 +53,7 @@ dependencies:
25
53
  - !ruby/object:Gem::Version
26
54
  version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
- name: nokogiri
56
+ name: actionpack
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - ">="
@@ -39,7 +67,21 @@ dependencies:
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
- name: actionpack
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-utils
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
87
  - - ">="
@@ -66,6 +108,34 @@ dependencies:
66
108
  - - ">="
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: nokogiri
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-meta
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
69
139
  - !ruby/object:Gem::Dependency
70
140
  name: rake
71
141
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +151,35 @@ dependencies:
81
151
  - !ruby/object:Gem::Version
82
152
  version: '0'
83
153
  - !ruby/object:Gem::Dependency
84
- name: test-unit
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-fnando
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov
85
183
  requirement: !ruby/object:Gem::Requirement
86
184
  requirements:
87
185
  - - ">="
@@ -102,15 +200,16 @@ executables: []
102
200
  extensions: []
103
201
  extra_rdoc_files: []
104
202
  files:
203
+ - ".github/FUNDING.yml"
105
204
  - ".gitignore"
205
+ - ".rubocop.yml"
206
+ - ".travis.yml"
106
207
  - Gemfile
107
- - Gemfile.lock
108
- - README.rdoc
208
+ - README.md
109
209
  - Rakefile
110
210
  - breadcrumbs.gemspec
111
211
  - examples/myapp/.gitignore
112
212
  - examples/myapp/Gemfile
113
- - examples/myapp/Gemfile.lock
114
213
  - examples/myapp/README.rdoc
115
214
  - examples/myapp/Rakefile
116
215
  - examples/myapp/app/assets/images/.keep
@@ -171,7 +270,7 @@ files:
171
270
  homepage: http://rubygems.org/gems/breadcrumbs
172
271
  licenses: []
173
272
  metadata: {}
174
- post_install_message:
273
+ post_install_message:
175
274
  rdoc_options: []
176
275
  require_paths:
177
276
  - lib
@@ -179,16 +278,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
278
  requirements:
180
279
  - - ">="
181
280
  - !ruby/object:Gem::Version
182
- version: '0'
281
+ version: 2.5.0
183
282
  required_rubygems_version: !ruby/object:Gem::Requirement
184
283
  requirements:
185
284
  - - ">="
186
285
  - !ruby/object:Gem::Version
187
286
  version: '0'
188
287
  requirements: []
189
- rubyforge_project:
190
- rubygems_version: 2.2.2
191
- signing_key:
288
+ rubygems_version: 3.1.2
289
+ signing_key:
192
290
  specification_version: 4
193
291
  summary: Breadcrumbs is a simple plugin that adds a `breadcrumbs` object to controllers
194
292
  and views.
@@ -1,56 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- breadcrumbs (0.1.7)
5
- i18n
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actionpack (4.1.6)
11
- actionview (= 4.1.6)
12
- activesupport (= 4.1.6)
13
- rack (~> 1.5.2)
14
- rack-test (~> 0.6.2)
15
- actionview (4.1.6)
16
- activesupport (= 4.1.6)
17
- builder (~> 3.1)
18
- erubis (~> 2.7.0)
19
- activesupport (4.1.6)
20
- i18n (~> 0.6, >= 0.6.9)
21
- json (~> 1.7, >= 1.7.7)
22
- minitest (~> 5.1)
23
- thread_safe (~> 0.1)
24
- tzinfo (~> 1.1)
25
- builder (3.2.2)
26
- erubis (2.7.0)
27
- i18n (0.6.11)
28
- json (1.8.1)
29
- metaclass (0.0.4)
30
- mini_portile (0.6.0)
31
- minitest (5.4.2)
32
- mocha (1.1.0)
33
- metaclass (~> 0.0.1)
34
- nokogiri (1.6.3.1)
35
- mini_portile (= 0.6.0)
36
- power_assert (0.1.4)
37
- rack (1.5.2)
38
- rack-test (0.6.2)
39
- rack (>= 1.0)
40
- rake (10.3.2)
41
- test-unit (3.0.1)
42
- power_assert
43
- thread_safe (0.3.4)
44
- tzinfo (1.2.2)
45
- thread_safe (~> 0.1)
46
-
47
- PLATFORMS
48
- ruby
49
-
50
- DEPENDENCIES
51
- actionpack
52
- breadcrumbs!
53
- mocha
54
- nokogiri
55
- rake
56
- test-unit
@@ -1,113 +0,0 @@
1
- = Breadcrumbs
2
-
3
- Breadcrumbs is a simple plugin that adds a +breadcrumbs+ object to controllers and views.
4
-
5
- == Instalation
6
-
7
- Just run <tt>sudo gem install breadcrumbs</tt>
8
-
9
- == Usage
10
-
11
- On your controller (optional):
12
-
13
- class ApplicationController < ActionController::Base
14
- before_filter :add_initial_breadcrumbs
15
-
16
- private
17
- def add_initial_breadcrumbs
18
- breadcrumbs.add 'Home', root_path
19
- end
20
- end
21
-
22
- class ThingsController < ApplicationController
23
- def index
24
- breadcrumbs.add 'Things', things_path
25
- end
26
- end
27
-
28
- You don't need to provide an URL; in that case, a span will be generated
29
- instead of a link:
30
-
31
- breadcrumbs.add 'Some page'
32
-
33
- You can set additional HTML attributes if you need to:
34
-
35
- breadcrumbs.add 'Home', root_path, :id => 'home', :title => 'Go to the home page'
36
-
37
- On your view (possibly application.html.erb):
38
-
39
- <%= breadcrumbs.render %>
40
-
41
- You can render as ordered list.
42
-
43
- <%= breadcrumbs.render(:format => :ordered_list) %>
44
-
45
- You can render as inline links.
46
-
47
- <%= breadcrumbs.render(:format => :inline) %>
48
-
49
- You can set your own separator:
50
-
51
- <p>
52
- You are here: <%= breadcrumbs.render(:format => :inline, :separator => '|') %>
53
- </p>
54
-
55
- You can also define your own formatter. Just create a class that implements a +render+ instance
56
- method and you're good to go.
57
-
58
- class Breadcrumbs::Render::Dl
59
- def render
60
- # return breadcrumbs wrapped in a <DL> tag
61
- end
62
- end
63
-
64
- To use your new format, just provide the <tt>:format</tt> option.
65
-
66
- breadcrumbs.render(:format => :dl)
67
-
68
- === I18n
69
-
70
- Breadcrumbs is integrated with I18n. You can set translations like:
71
-
72
- en:
73
- breadcrumbs:
74
- home: "Home"
75
-
76
- And then you just call
77
-
78
- breadcrumbs.add :home
79
-
80
- In fact, you can provide any scope you want.
81
-
82
- breadcrumbs.add "titles.home"
83
-
84
- If you don't want to translate a label, just pass the option <tt>:i18n</tt> as <tt>false</tt>.
85
-
86
- breadcrumbs.add :home, nil, :i18n => false
87
-
88
- == Maintainer
89
-
90
- * Nando Vieira - http://simplesideias.com.br
91
-
92
- License
93
-
94
- (The MIT License)
95
-
96
- Permission is hereby granted, free of charge, to any person obtaining
97
- a copy of this software and associated documentation files (the
98
- 'Software'), to deal in the Software without restriction, including
99
- without limitation the rights to use, copy, modify, merge, publish,
100
- distribute, sublicense, and/or sell copies of the Software, and to
101
- permit persons to whom the Software is furnished to do so, subject to
102
- the following conditions:
103
-
104
- The above copyright notice and this permission notice shall be
105
- included in all copies or substantial portions of the Software.
106
-
107
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
108
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
109
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
110
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
111
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
112
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
113
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,124 +0,0 @@
1
- PATH
2
- remote: ../..
3
- specs:
4
- breadcrumbs (0.1.6)
5
- i18n
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actionmailer (4.2.0.beta1)
11
- actionpack (= 4.2.0.beta1)
12
- actionview (= 4.2.0.beta1)
13
- mail (~> 2.5, >= 2.5.4)
14
- rails-dom-testing (~> 1.0, >= 1.0.2)
15
- actionpack (4.2.0.beta1)
16
- actionview (= 4.2.0.beta1)
17
- activesupport (= 4.2.0.beta1)
18
- rack (~> 1.6.0.beta)
19
- rack-test (~> 0.6.2)
20
- rails-deprecated_sanitizer (~> 1.0, >= 1.0.2)
21
- rails-dom-testing (~> 1.0, >= 1.0.2)
22
- actionview (4.2.0.beta1)
23
- activesupport (= 4.2.0.beta1)
24
- builder (~> 3.1)
25
- erubis (~> 2.7.0)
26
- rails-deprecated_sanitizer (~> 1.0, >= 1.0.2)
27
- rails-dom-testing (~> 1.0, >= 1.0.2)
28
- activejob (4.2.0.beta1)
29
- globalid (>= 0.2.3)
30
- activemodel (4.2.0.beta1)
31
- activesupport (= 4.2.0.beta1)
32
- builder (~> 3.1)
33
- activerecord (4.2.0.beta1)
34
- activemodel (= 4.2.0.beta1)
35
- activesupport (= 4.2.0.beta1)
36
- arel (>= 6.0.0.beta1, < 6.1)
37
- activesupport (4.2.0.beta1)
38
- i18n (>= 0.7.0.beta1, < 0.8)
39
- json (~> 1.7, >= 1.7.7)
40
- minitest (~> 5.1)
41
- thread_safe (~> 0.1)
42
- tzinfo (~> 1.1)
43
- arel (6.0.0.beta1)
44
- builder (3.2.2)
45
- erubis (2.7.0)
46
- execjs (2.2.1)
47
- globalid (0.3.0)
48
- activesupport (>= 4.1.0)
49
- hike (1.2.3)
50
- i18n (0.7.0.beta1)
51
- json (1.8.1)
52
- loofah (2.0.1)
53
- nokogiri (>= 1.5.9)
54
- mail (2.6.1)
55
- mime-types (>= 1.16, < 3)
56
- mime-types (2.3)
57
- mini_portile (0.6.0)
58
- minitest (5.4.2)
59
- multi_json (1.10.1)
60
- nokogiri (1.6.3.1)
61
- mini_portile (= 0.6.0)
62
- rack (1.6.0.beta)
63
- rack-test (0.6.2)
64
- rack (>= 1.0)
65
- rails (4.2.0.beta1)
66
- actionmailer (= 4.2.0.beta1)
67
- actionpack (= 4.2.0.beta1)
68
- actionview (= 4.2.0.beta1)
69
- activejob (= 4.2.0.beta1)
70
- activemodel (= 4.2.0.beta1)
71
- activerecord (= 4.2.0.beta1)
72
- activesupport (= 4.2.0.beta1)
73
- bundler (>= 1.3.0, < 2.0)
74
- railties (= 4.2.0.beta1)
75
- sprockets-rails (~> 3.0.0.beta1)
76
- rails-deprecated_sanitizer (1.0.3)
77
- activesupport (>= 4.2.0.alpha)
78
- rails-dom-testing (1.0.3)
79
- activesupport
80
- nokogiri (~> 1.6.0)
81
- rails-deprecated_sanitizer (>= 1.0.1)
82
- rails-html-sanitizer (1.0.1)
83
- loofah (~> 2.0)
84
- railties (4.2.0.beta1)
85
- actionpack (= 4.2.0.beta1)
86
- activesupport (= 4.2.0.beta1)
87
- rake (>= 0.8.7)
88
- thor (>= 0.18.1, < 2.0)
89
- rake (10.3.2)
90
- sass (3.4.5)
91
- sass-rails (5.0.0.beta1)
92
- railties (>= 4.0.0, < 5.0)
93
- sass (~> 3.2)
94
- sprockets (~> 2.12)
95
- sprockets-rails (>= 2.0, < 4.0)
96
- spring (1.1.3)
97
- sprockets (2.12.2)
98
- hike (~> 1.2)
99
- multi_json (~> 1.0)
100
- rack (~> 1.0)
101
- tilt (~> 1.1, != 1.3.0)
102
- sprockets-rails (3.0.0.beta1)
103
- actionpack (>= 4.0)
104
- activesupport (>= 4.0)
105
- sprockets (~> 2.8)
106
- thor (0.19.1)
107
- thread_safe (0.3.4)
108
- tilt (1.4.1)
109
- tzinfo (1.2.2)
110
- thread_safe (~> 0.1)
111
- uglifier (2.5.3)
112
- execjs (>= 0.3.0)
113
- json (>= 1.8.0)
114
-
115
- PLATFORMS
116
- ruby
117
-
118
- DEPENDENCIES
119
- breadcrumbs!
120
- rails (= 4.2.0.beta1)
121
- rails-html-sanitizer (~> 1.0)
122
- sass-rails (~> 5.0.0.beta1)
123
- spring
124
- uglifier (>= 1.3.0)