gretel 3.0.9 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +11 -7
- data/.travis.yml +11 -10
- data/CHANGELOG.md +27 -0
- data/Gemfile +2 -19
- data/LICENSE.txt +1 -1
- data/README.md +43 -62
- data/Rakefile +3 -7
- data/coverage/coverage.txt +5 -0
- data/gretel.gemspec +12 -10
- data/lib/gretel.rb +2 -29
- data/lib/gretel/crumb.rb +5 -2
- data/lib/gretel/crumbs.rb +26 -7
- data/lib/gretel/railtie.rb +11 -0
- data/lib/gretel/renderer.rb +62 -30
- data/lib/gretel/version.rb +1 -1
- data/lib/gretel/view_helpers.rb +2 -0
- metadata +83 -110
- data/gemfiles/Gemfile-rails.3.1.x +0 -19
- data/gemfiles/Gemfile-rails.3.2.x +0 -19
- data/gemfiles/Gemfile-rails.4.0.x +0 -19
- data/gemfiles/Gemfile-rails.4.1.x +0 -19
- data/lib/gretel/deprecated.rb +0 -1
- data/lib/gretel/deprecated/default_style_key.rb +0 -25
- data/lib/gretel/deprecated/layout.rb +0 -15
- data/lib/gretel/deprecated/show_root_alone.rb +0 -27
- data/lib/gretel/deprecated/yield_links.rb +0 -44
- data/test/deprecated_test.rb +0 -45
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -5
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/models/issue.rb +0 -3
- data/test/dummy/app/models/project.rb +0 -3
- data/test/dummy/app/views/breadcrumbs/site.rb +0 -3
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -14
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/breadcrumbs.rb +0 -3
- data/test/dummy/config/breadcrumbs/test_crumbs.rb +0 -85
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -2
- data/test/dummy/config/environments/production.rb +0 -2
- data/test/dummy/config/environments/test.rb +0 -2
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -11
- data/test/dummy/db/migrate/20130122163007_create_projects.rb +0 -9
- data/test/dummy/db/migrate/20130122163051_create_issues.rb +0 -10
- data/test/dummy/db/schema.rb +0 -29
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/fixtures/issues.yml +0 -4
- data/test/fixtures/projects.yml +0 -3
- data/test/gretel_test.rb +0 -24
- data/test/helper_methods_test.rb +0 -546
- data/test/test_helper.rb +0 -15
@@ -1,7 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
-
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
-
|
6
|
-
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
-
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# Add new inflection rules using the following format
|
4
|
-
# (all these examples are active by default):
|
5
|
-
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
-
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
-
# inflect.singular /^(ox)en/i, '\1'
|
8
|
-
# inflect.irregular 'person', 'people'
|
9
|
-
# inflect.uncountable %w( fish sheep )
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# These inflection rules are supported but not enabled by default:
|
13
|
-
# ActiveSupport::Inflector.inflections do |inflect|
|
14
|
-
# inflect.acronym 'RESTful'
|
15
|
-
# end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# Your secret key for verifying the integrity of signed cookies.
|
4
|
-
# If you change this key, all old signed cookies will become invalid!
|
5
|
-
# Make sure the secret is at least 30 characters and all random,
|
6
|
-
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
-
Dummy::Application.config.secret_token = '42da708db5725479ebd37530644412b9a6203a31f1db83d8799995365f1c026abb0c9fed978d81a80388b8bbfc9f9b9b33683330f4b657e6253d1a6df55860bb'
|
@@ -1,8 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
|
-
|
5
|
-
# Use the database for sessions instead of the cookie-based default,
|
6
|
-
# which shouldn't be used to store highly confidential information
|
7
|
-
# (create the session table with "rails generate session_migration")
|
8
|
-
# Dummy::Application.config.session_store :active_record_store
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
#
|
3
|
-
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
-
# is enabled by default.
|
5
|
-
|
6
|
-
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
-
ActiveSupport.on_load(:action_controller) do
|
8
|
-
wrap_parameters format: [:json]
|
9
|
-
end
|
10
|
-
|
11
|
-
# Disable root element in JSON by default.
|
12
|
-
ActiveSupport.on_load(:active_record) do
|
13
|
-
self.include_root_in_json = false
|
14
|
-
end
|
data/test/dummy/config/routes.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
Dummy::Application.routes.draw do
|
2
|
-
root to: "dummy#dummy"
|
3
|
-
|
4
|
-
get "about" => "dummy#dummy", as: :about
|
5
|
-
get "about/contact" => "dummy#dummy", as: :contact
|
6
|
-
get "about/contact/form" => "dummy#dummy", as: :contact_form
|
7
|
-
|
8
|
-
resources :projects do
|
9
|
-
resources :issues
|
10
|
-
end
|
11
|
-
end
|
data/test/dummy/db/schema.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# This file is auto-generated from the current state of the database. Instead
|
3
|
-
# of editing this file, please use the migrations feature of Active Record to
|
4
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
-
#
|
6
|
-
# Note that this schema.rb definition is the authoritative source for your
|
7
|
-
# database schema. If you need to create the application database on another
|
8
|
-
# system, you should be using db:schema:load, not running all the migrations
|
9
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
-
#
|
12
|
-
# It's strongly recommended to check this file into your version control system.
|
13
|
-
|
14
|
-
ActiveRecord::Schema.define(:version => 20130122163051) do
|
15
|
-
|
16
|
-
create_table "issues", :force => true do |t|
|
17
|
-
t.string "title"
|
18
|
-
t.integer "project_id"
|
19
|
-
t.datetime "created_at", :null => false
|
20
|
-
t.datetime "updated_at", :null => false
|
21
|
-
end
|
22
|
-
|
23
|
-
create_table "projects", :force => true do |t|
|
24
|
-
t.string "name"
|
25
|
-
t.datetime "created_at", :null => false
|
26
|
-
t.datetime "updated_at", :null => false
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
File without changes
|
data/test/dummy/log/.gitkeep
DELETED
File without changes
|
data/test/dummy/public/404.html
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
-
<style type="text/css">
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
-
div.dialog {
|
8
|
-
width: 25em;
|
9
|
-
padding: 0 4em;
|
10
|
-
margin: 4em auto 0 auto;
|
11
|
-
border: 1px solid #ccc;
|
12
|
-
border-right-color: #999;
|
13
|
-
border-bottom-color: #999;
|
14
|
-
}
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
-
</style>
|
17
|
-
</head>
|
18
|
-
|
19
|
-
<body>
|
20
|
-
<!-- This file lives in public/404.html -->
|
21
|
-
<div class="dialog">
|
22
|
-
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
-
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
-
</div>
|
25
|
-
</body>
|
26
|
-
</html>
|
data/test/dummy/public/422.html
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The change you wanted was rejected (422)</title>
|
5
|
-
<style type="text/css">
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
-
div.dialog {
|
8
|
-
width: 25em;
|
9
|
-
padding: 0 4em;
|
10
|
-
margin: 4em auto 0 auto;
|
11
|
-
border: 1px solid #ccc;
|
12
|
-
border-right-color: #999;
|
13
|
-
border-bottom-color: #999;
|
14
|
-
}
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
-
</style>
|
17
|
-
</head>
|
18
|
-
|
19
|
-
<body>
|
20
|
-
<!-- This file lives in public/422.html -->
|
21
|
-
<div class="dialog">
|
22
|
-
<h1>The change you wanted was rejected.</h1>
|
23
|
-
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
-
</div>
|
25
|
-
</body>
|
26
|
-
</html>
|
data/test/dummy/public/500.html
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>We're sorry, but something went wrong (500)</title>
|
5
|
-
<style type="text/css">
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
-
div.dialog {
|
8
|
-
width: 25em;
|
9
|
-
padding: 0 4em;
|
10
|
-
margin: 4em auto 0 auto;
|
11
|
-
border: 1px solid #ccc;
|
12
|
-
border-right-color: #999;
|
13
|
-
border-bottom-color: #999;
|
14
|
-
}
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
-
</style>
|
17
|
-
</head>
|
18
|
-
|
19
|
-
<body>
|
20
|
-
<!-- This file lives in public/500.html -->
|
21
|
-
<div class="dialog">
|
22
|
-
<h1>We're sorry, but something went wrong.</h1>
|
23
|
-
</div>
|
24
|
-
</body>
|
25
|
-
</html>
|
File without changes
|
data/test/dummy/script/rails
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
-
|
4
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
-
require File.expand_path('../../config/boot', __FILE__)
|
6
|
-
require 'rails/commands'
|
data/test/fixtures/issues.yml
DELETED
data/test/fixtures/projects.yml
DELETED
data/test/gretel_test.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class GretelTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
Gretel.reset!
|
6
|
-
end
|
7
|
-
|
8
|
-
test "defaults" do
|
9
|
-
assert_equal [Rails.root.join("config", "breadcrumbs.rb"),
|
10
|
-
Rails.root.join("config", "breadcrumbs", "**", "*.rb"),
|
11
|
-
Rails.root.join("app", "views", "breadcrumbs", "**", "*.rb")],
|
12
|
-
Gretel.breadcrumb_paths[-3..-1]
|
13
|
-
assert_equal ["development"], Gretel.reload_environments
|
14
|
-
assert !Gretel.suppress_deprecation_warnings?
|
15
|
-
end
|
16
|
-
|
17
|
-
test "configuration block" do
|
18
|
-
Gretel.configure do |config|
|
19
|
-
config.reload_environments << "staging"
|
20
|
-
end
|
21
|
-
|
22
|
-
assert_equal ["development", "staging"], Gretel.reload_environments
|
23
|
-
end
|
24
|
-
end
|
data/test/helper_methods_test.rb
DELETED
@@ -1,546 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class HelperMethodsTest < ActionView::TestCase
|
4
|
-
include Gretel::ViewHelpers
|
5
|
-
|
6
|
-
self.fixture_path = File.expand_path("../../test/fixtures", __FILE__)
|
7
|
-
fixtures :all
|
8
|
-
|
9
|
-
helper :application
|
10
|
-
|
11
|
-
setup do
|
12
|
-
Gretel.reset!
|
13
|
-
end
|
14
|
-
|
15
|
-
def itemscope_value
|
16
|
-
ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES.include?("itemscope") ?
|
17
|
-
"itemscope" : ""
|
18
|
-
end
|
19
|
-
|
20
|
-
# Breadcrumb generation
|
21
|
-
|
22
|
-
test "basic breadcrumb" do
|
23
|
-
breadcrumb :basic
|
24
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
25
|
-
breadcrumbs.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
test "breadcrumb with root" do
|
29
|
-
breadcrumb :with_root
|
30
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
31
|
-
breadcrumbs.to_s
|
32
|
-
end
|
33
|
-
|
34
|
-
test "breadcrumb with parent" do
|
35
|
-
breadcrumb :with_parent
|
36
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/about">About</a> › <span class="current">Contact</span></div>},
|
37
|
-
breadcrumbs.to_s
|
38
|
-
end
|
39
|
-
|
40
|
-
test "breadcrumb with autopath" do
|
41
|
-
breadcrumb :with_autopath, projects(:one)
|
42
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Test Project</span></div>},
|
43
|
-
breadcrumbs.to_s
|
44
|
-
end
|
45
|
-
|
46
|
-
test "breadcrumb with parent object" do
|
47
|
-
breadcrumb :with_parent_object, issues(:one)
|
48
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/projects/1">Test Project</a> › <span class="current">Test Issue</span></div>},
|
49
|
-
breadcrumbs.to_s
|
50
|
-
end
|
51
|
-
|
52
|
-
test "multiple links" do
|
53
|
-
breadcrumb :multiple_links
|
54
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/about/contact">Contact</a> › <span class="current">Contact form</span></div>},
|
55
|
-
breadcrumbs.to_s
|
56
|
-
end
|
57
|
-
|
58
|
-
test "multiple links with parent" do
|
59
|
-
breadcrumb :multiple_links_with_parent
|
60
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/about">About</a> › <a href="/about/contact">Contact</a> › <span class="current">Contact form</span></div>},
|
61
|
-
breadcrumbs.to_s
|
62
|
-
end
|
63
|
-
|
64
|
-
test "semantic breadcrumb" do
|
65
|
-
breadcrumb :with_root
|
66
|
-
assert_dom_equal %Q{<div class="breadcrumbs"><span itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/" itemprop="url"><span itemprop="title">Home</span></a></span> › <span itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><span class="current" itemprop="title">About</span></span></div>},
|
67
|
-
breadcrumbs(semantic: true).to_s
|
68
|
-
end
|
69
|
-
|
70
|
-
test "doesn't show root alone" do
|
71
|
-
breadcrumb :root
|
72
|
-
assert_dom_equal "", breadcrumbs.to_s
|
73
|
-
end
|
74
|
-
|
75
|
-
test "displays single fragment" do
|
76
|
-
breadcrumb :root
|
77
|
-
assert_dom_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
|
78
|
-
breadcrumbs(display_single_fragment: true).to_s
|
79
|
-
end
|
80
|
-
|
81
|
-
test "displays single non-root fragment" do
|
82
|
-
breadcrumb :basic
|
83
|
-
assert_dom_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
|
84
|
-
breadcrumbs(autoroot: false, display_single_fragment: true).to_s
|
85
|
-
end
|
86
|
-
|
87
|
-
test "no breadcrumb" do
|
88
|
-
assert_dom_equal "", breadcrumbs.to_s
|
89
|
-
end
|
90
|
-
|
91
|
-
test "links current breadcrumb" do
|
92
|
-
breadcrumb :with_root
|
93
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/about" class="current">About</a></div>},
|
94
|
-
breadcrumbs(link_current: true).to_s
|
95
|
-
end
|
96
|
-
|
97
|
-
test "pretext" do
|
98
|
-
breadcrumb :basic
|
99
|
-
assert_dom_equal %{<div class="breadcrumbs"><span class="pretext">You are here:</span> <a href="/">Home</a> › <span class="current">About</span></div>},
|
100
|
-
breadcrumbs(pretext: "You are here:").to_s
|
101
|
-
end
|
102
|
-
|
103
|
-
test "posttext" do
|
104
|
-
breadcrumb :basic
|
105
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span> <span class="posttext">text after breadcrumbs</span></div>},
|
106
|
-
breadcrumbs(posttext: "text after breadcrumbs").to_s
|
107
|
-
end
|
108
|
-
|
109
|
-
test "autoroot disabled" do
|
110
|
-
breadcrumb :basic
|
111
|
-
assert_dom_equal "", breadcrumbs(autoroot: false).to_s
|
112
|
-
end
|
113
|
-
|
114
|
-
test "separator" do
|
115
|
-
breadcrumb :with_root
|
116
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> » <span class="current">About</span></div>},
|
117
|
-
breadcrumbs(separator: " » ").to_s
|
118
|
-
end
|
119
|
-
|
120
|
-
test "element id" do
|
121
|
-
breadcrumb :basic
|
122
|
-
assert_dom_equal %{<div class="breadcrumbs" id="custom_id"><a href="/">Home</a> › <span class="current">About</span></div>},
|
123
|
-
breadcrumbs(id: "custom_id").to_s
|
124
|
-
end
|
125
|
-
|
126
|
-
test "custom container class" do
|
127
|
-
breadcrumb :basic
|
128
|
-
assert_dom_equal %{<div class="custom_class"><a href="/">Home</a> › <span class="current">About</span></div>},
|
129
|
-
breadcrumbs(class: "custom_class").to_s
|
130
|
-
end
|
131
|
-
|
132
|
-
test "custom current class" do
|
133
|
-
breadcrumb :basic
|
134
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="custom_current_class">About</span></div>},
|
135
|
-
breadcrumbs(current_class: "custom_current_class").to_s
|
136
|
-
end
|
137
|
-
|
138
|
-
test "custom pretext class" do
|
139
|
-
breadcrumb :basic
|
140
|
-
assert_dom_equal %{<div class="breadcrumbs"><span class="custom_pretext_class">You are here:</span> <a href="/">Home</a> › <span class="current">About</span></div>},
|
141
|
-
breadcrumbs(pretext: "You are here:", pretext_class: "custom_pretext_class").to_s
|
142
|
-
end
|
143
|
-
|
144
|
-
test "custom posttext class" do
|
145
|
-
breadcrumb :basic
|
146
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span> <span class="custom_posttext_class">after breadcrumbs</span></div>},
|
147
|
-
breadcrumbs(posttext: "after breadcrumbs", posttext_class: "custom_posttext_class").to_s
|
148
|
-
end
|
149
|
-
|
150
|
-
test "unsafe html" do
|
151
|
-
breadcrumb :with_unsafe_html
|
152
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Test <strong>bold text</strong></span></div>},
|
153
|
-
breadcrumbs.to_s
|
154
|
-
end
|
155
|
-
|
156
|
-
test "safe html" do
|
157
|
-
breadcrumb :with_safe_html
|
158
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Test <strong>bold text</strong></span></div>},
|
159
|
-
breadcrumbs.to_s
|
160
|
-
end
|
161
|
-
|
162
|
-
test "parent breadcrumb" do
|
163
|
-
breadcrumb :multiple_links_with_parent
|
164
|
-
|
165
|
-
parent = parent_breadcrumb
|
166
|
-
assert_equal [:multiple_links_with_parent, "Contact", "/about/contact"],
|
167
|
-
[parent.key, parent.text, parent.url]
|
168
|
-
end
|
169
|
-
|
170
|
-
test "yields parent breadcrumb" do
|
171
|
-
breadcrumb :multiple_links_with_parent
|
172
|
-
|
173
|
-
out = parent_breadcrumb do |parent|
|
174
|
-
[parent.key, parent.text, parent.url]
|
175
|
-
end
|
176
|
-
assert_equal [:multiple_links_with_parent, "Contact", "/about/contact"],
|
177
|
-
out
|
178
|
-
end
|
179
|
-
|
180
|
-
test "parent breadcrumb returns nil if not present" do
|
181
|
-
breadcrumb :basic
|
182
|
-
|
183
|
-
assert_nil parent_breadcrumb(autoroot: false)
|
184
|
-
end
|
185
|
-
|
186
|
-
test "parent breadcrumb yields only if present" do
|
187
|
-
breadcrumb :basic
|
188
|
-
|
189
|
-
out = parent_breadcrumb(autoroot: false) do
|
190
|
-
"yielded"
|
191
|
-
end
|
192
|
-
|
193
|
-
assert_nil out
|
194
|
-
end
|
195
|
-
|
196
|
-
test "link keys" do
|
197
|
-
breadcrumb :basic
|
198
|
-
assert_equal [:root, :basic], breadcrumbs.keys
|
199
|
-
end
|
200
|
-
|
201
|
-
test "using breadcrumbs as array" do
|
202
|
-
breadcrumb :basic
|
203
|
-
|
204
|
-
breadcrumbs.tap do |links|
|
205
|
-
assert_kind_of Array, links
|
206
|
-
assert_equal 2, links.count
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
test "sets current on last link in array" do
|
211
|
-
breadcrumb :multiple_links_with_parent
|
212
|
-
assert_equal [false, false, false, true], breadcrumbs.map(&:current?)
|
213
|
-
end
|
214
|
-
|
215
|
-
test "passing options to links" do
|
216
|
-
breadcrumb :with_link_options
|
217
|
-
|
218
|
-
breadcrumbs(autoroot: false).tap do |links|
|
219
|
-
links[0].tap do |link|
|
220
|
-
assert link.title?
|
221
|
-
assert_equal "My Title", link.title
|
222
|
-
|
223
|
-
assert link.other?
|
224
|
-
assert_equal "Other Option", link.other
|
225
|
-
|
226
|
-
assert !link.nonexistent?
|
227
|
-
assert_nil link.nonexistent
|
228
|
-
end
|
229
|
-
|
230
|
-
links[1].tap do |link|
|
231
|
-
assert link.some_option?
|
232
|
-
assert_equal "Test", link.some_option
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/about">Test</a> › <span class="current">Other Link</span></div>},
|
237
|
-
breadcrumbs(autoroot: false).to_s
|
238
|
-
end
|
239
|
-
|
240
|
-
test "without link" do
|
241
|
-
breadcrumb :without_link
|
242
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › Also without link › <span class="current">Without link</span></div>},
|
243
|
-
breadcrumbs.to_s
|
244
|
-
end
|
245
|
-
|
246
|
-
test "view context" do
|
247
|
-
breadcrumb :using_view_helper
|
248
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">TestTest</span></div>},
|
249
|
-
breadcrumbs.to_s
|
250
|
-
end
|
251
|
-
|
252
|
-
test "multiple arguments" do
|
253
|
-
breadcrumb :with_multiple_arguments, "One", "Two", "Three"
|
254
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/about">First OneOne then TwoTwo then ThreeThree</a> › <span class="current">One and Two and Three</span></div>},
|
255
|
-
breadcrumbs.to_s
|
256
|
-
end
|
257
|
-
|
258
|
-
test "from views folder" do
|
259
|
-
breadcrumb :from_views
|
260
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Breadcrumb From View</span></div>},
|
261
|
-
breadcrumbs.to_s
|
262
|
-
end
|
263
|
-
|
264
|
-
test "with_breadcrumb" do
|
265
|
-
breadcrumb :basic
|
266
|
-
|
267
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
268
|
-
breadcrumbs.to_s
|
269
|
-
|
270
|
-
with_breadcrumb(:with_parent_object, issues(:one)) do
|
271
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/projects/1">Test Project</a> › <span class="current">Test Issue</span></div>},
|
272
|
-
breadcrumbs.to_s
|
273
|
-
end
|
274
|
-
|
275
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
276
|
-
breadcrumbs.to_s
|
277
|
-
end
|
278
|
-
|
279
|
-
test "calling breadcrumbs helper twice" do
|
280
|
-
breadcrumb :with_parent
|
281
|
-
2.times do
|
282
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/about">About</a> › <span class="current">Contact</span></div>},
|
283
|
-
breadcrumbs.to_s
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
test "breadcrumb not found" do
|
288
|
-
assert_raises ArgumentError do
|
289
|
-
breadcrumb :nonexistent
|
290
|
-
breadcrumbs
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
test "current link url is set to fullpath" do
|
295
|
-
self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
|
296
|
-
|
297
|
-
breadcrumb :basic
|
298
|
-
assert_equal "/testpath?a=1&b=2", breadcrumbs.last.url
|
299
|
-
end
|
300
|
-
|
301
|
-
test "current link url is not set to fullpath using link_current_to_request_path=false" do
|
302
|
-
self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
|
303
|
-
|
304
|
-
breadcrumb :basic
|
305
|
-
assert_equal "/about", breadcrumbs(:link_current_to_request_path => false).last.url
|
306
|
-
end
|
307
|
-
|
308
|
-
test "calling the breadcrumb method with wrong arguments" do
|
309
|
-
assert_nothing_raised do
|
310
|
-
breadcrumb :basic, test: 1
|
311
|
-
end
|
312
|
-
|
313
|
-
assert_raises ArgumentError do
|
314
|
-
breadcrumb
|
315
|
-
end
|
316
|
-
|
317
|
-
assert_raises ArgumentError do
|
318
|
-
breadcrumb(pretext: "bla")
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
test "inferred breadcrumb" do
|
323
|
-
breadcrumb Project.first
|
324
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Test Project</span></div>},
|
325
|
-
breadcrumbs.to_s
|
326
|
-
end
|
327
|
-
|
328
|
-
test "inferred parent" do
|
329
|
-
breadcrumb :with_inferred_parent
|
330
|
-
|
331
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/projects/1">Test Project</a> › <span class="current">Test</span></div>},
|
332
|
-
breadcrumbs.to_s
|
333
|
-
end
|
334
|
-
|
335
|
-
# Styles
|
336
|
-
|
337
|
-
test "default style" do
|
338
|
-
breadcrumb :basic
|
339
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
340
|
-
breadcrumbs.to_s
|
341
|
-
end
|
342
|
-
|
343
|
-
test "ordered list style" do
|
344
|
-
breadcrumb :basic
|
345
|
-
assert_dom_equal %{<ol class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ol>},
|
346
|
-
breadcrumbs(style: :ol).to_s
|
347
|
-
end
|
348
|
-
|
349
|
-
test "unordered list style" do
|
350
|
-
breadcrumb :basic
|
351
|
-
assert_dom_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
|
352
|
-
breadcrumbs(style: :ul).to_s
|
353
|
-
end
|
354
|
-
|
355
|
-
test "bootstrap style" do
|
356
|
-
breadcrumb :basic
|
357
|
-
assert_dom_equal %{<ol class="breadcrumb"><li><a href="/">Home</a></li><li class="active">About</li></ol>},
|
358
|
-
breadcrumbs(style: :bootstrap).to_s
|
359
|
-
end
|
360
|
-
|
361
|
-
test "foundation5 style" do
|
362
|
-
breadcrumb :basic
|
363
|
-
assert_dom_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
|
364
|
-
breadcrumbs(style: :foundation5).to_s
|
365
|
-
end
|
366
|
-
|
367
|
-
test "custom container and fragment tags" do
|
368
|
-
breadcrumb :basic
|
369
|
-
assert_dom_equal %{<c class="breadcrumbs"><f><a href="/">Home</a></f> › <f class="current">About</f></c>},
|
370
|
-
breadcrumbs(container_tag: :c, fragment_tag: :f).to_s
|
371
|
-
end
|
372
|
-
|
373
|
-
test "custom semantic container and fragment tags" do
|
374
|
-
breadcrumb :basic
|
375
|
-
assert_dom_equal %Q{<c class="breadcrumbs"><f itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><a itemprop="url" href="/"><span itemprop="title">Home</span></a></f> › <f class="current" itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title">About</span><meta itemprop="url" content="http://test.host/about" /></f></c>},
|
376
|
-
breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true).to_s
|
377
|
-
end
|
378
|
-
|
379
|
-
test "unknown style" do
|
380
|
-
breadcrumb :basic
|
381
|
-
assert_raises ArgumentError do
|
382
|
-
breadcrumbs(style: :nonexistent)
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
test "register style" do
|
387
|
-
Gretel.register_style :test_style, { container_tag: :one, fragment_tag: :two }
|
388
|
-
|
389
|
-
breadcrumb :basic
|
390
|
-
|
391
|
-
assert_dom_equal %{<one class="breadcrumbs"><two><a href="/">Home</a></two><two class="current">About</two></one>},
|
392
|
-
breadcrumbs(style: :test_style).to_s
|
393
|
-
end
|
394
|
-
|
395
|
-
# Configuration reload
|
396
|
-
|
397
|
-
test "reload configuration when file is changed" do
|
398
|
-
path = setup_loading_from_tmp_folder
|
399
|
-
Gretel.reload_environments << "test"
|
400
|
-
|
401
|
-
File.open(path.join("site.rb"), "w") do |f|
|
402
|
-
f.write <<-EOT
|
403
|
-
crumb :root do
|
404
|
-
link "Home (loaded)", root_path
|
405
|
-
end
|
406
|
-
crumb :about do
|
407
|
-
link "About (loaded)", about_path
|
408
|
-
end
|
409
|
-
EOT
|
410
|
-
end
|
411
|
-
|
412
|
-
breadcrumb :about
|
413
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
414
|
-
|
415
|
-
sleep 1 # File change interval is 1 second
|
416
|
-
|
417
|
-
File.open(path.join("site.rb"), "w") do |f|
|
418
|
-
f.write <<-EOT
|
419
|
-
crumb :root do
|
420
|
-
link "Home (reloaded)", "/test"
|
421
|
-
end
|
422
|
-
crumb :about do
|
423
|
-
link "About (reloaded)", "/reloaded"
|
424
|
-
end
|
425
|
-
EOT
|
426
|
-
end
|
427
|
-
|
428
|
-
breadcrumb :about
|
429
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/test">Home (reloaded)</a> › <span class="current">About (reloaded)</span></div>}, breadcrumbs.to_s
|
430
|
-
end
|
431
|
-
|
432
|
-
test "reload configuration when file is added" do
|
433
|
-
path = setup_loading_from_tmp_folder
|
434
|
-
Gretel.reload_environments << "test"
|
435
|
-
|
436
|
-
File.open(path.join("site.rb"), "w") do |f|
|
437
|
-
f.write <<-EOT
|
438
|
-
crumb :root do
|
439
|
-
link "Home (loaded)", root_path
|
440
|
-
end
|
441
|
-
EOT
|
442
|
-
end
|
443
|
-
|
444
|
-
assert_raises ArgumentError do
|
445
|
-
breadcrumb :about
|
446
|
-
breadcrumbs
|
447
|
-
end
|
448
|
-
|
449
|
-
File.open(path.join("pages.rb"), "w") do |f|
|
450
|
-
f.write <<-EOT
|
451
|
-
crumb :about do
|
452
|
-
link "About (loaded)", about_path
|
453
|
-
end
|
454
|
-
EOT
|
455
|
-
end
|
456
|
-
|
457
|
-
breadcrumb :about
|
458
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
459
|
-
end
|
460
|
-
|
461
|
-
test "reload configuration when file is deleted" do
|
462
|
-
path = setup_loading_from_tmp_folder
|
463
|
-
Gretel.reload_environments << "test"
|
464
|
-
|
465
|
-
File.open(path.join("site.rb"), "w") do |f|
|
466
|
-
f.write <<-EOT
|
467
|
-
crumb :root do
|
468
|
-
link "Home (loaded)", root_path
|
469
|
-
end
|
470
|
-
crumb :about do
|
471
|
-
link "About (loaded)", about_path
|
472
|
-
end
|
473
|
-
EOT
|
474
|
-
end
|
475
|
-
|
476
|
-
File.open(path.join("pages.rb"), "w") do |f|
|
477
|
-
f.write <<-EOT
|
478
|
-
crumb :contact do
|
479
|
-
link "Contact (loaded)", "/contact"
|
480
|
-
parent :about
|
481
|
-
end
|
482
|
-
EOT
|
483
|
-
end
|
484
|
-
|
485
|
-
breadcrumb :contact
|
486
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <a href="/about">About (loaded)</a> › <span class="current">Contact (loaded)</span></div>}, breadcrumbs.to_s
|
487
|
-
|
488
|
-
File.delete path.join("pages.rb")
|
489
|
-
|
490
|
-
assert_raises ArgumentError do
|
491
|
-
breadcrumb :contact
|
492
|
-
breadcrumbs
|
493
|
-
end
|
494
|
-
|
495
|
-
breadcrumb :about
|
496
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
497
|
-
end
|
498
|
-
|
499
|
-
test "reloads only in development environment" do
|
500
|
-
path = setup_loading_from_tmp_folder
|
501
|
-
|
502
|
-
assert_equal ["development"], Gretel.reload_environments
|
503
|
-
|
504
|
-
File.open(path.join("site.rb"), "w") do |f|
|
505
|
-
f.write <<-EOT
|
506
|
-
crumb :root do
|
507
|
-
link "Home (loaded)", root_path
|
508
|
-
end
|
509
|
-
crumb :about do
|
510
|
-
link "About (loaded)", about_path
|
511
|
-
end
|
512
|
-
EOT
|
513
|
-
end
|
514
|
-
|
515
|
-
breadcrumb :about
|
516
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
517
|
-
|
518
|
-
sleep 1
|
519
|
-
|
520
|
-
File.open(path.join("site.rb"), "w") do |f|
|
521
|
-
f.write <<-EOT
|
522
|
-
crumb :root do
|
523
|
-
link "Home (reloaded)", "/test"
|
524
|
-
end
|
525
|
-
crumb :about do
|
526
|
-
link "About (reloaded)", "/reloaded"
|
527
|
-
end
|
528
|
-
EOT
|
529
|
-
end
|
530
|
-
|
531
|
-
breadcrumb :about
|
532
|
-
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
533
|
-
end
|
534
|
-
|
535
|
-
private
|
536
|
-
|
537
|
-
def setup_loading_from_tmp_folder
|
538
|
-
path = Rails.root.join("tmp", "testcrumbs")
|
539
|
-
FileUtils.rm_rf path
|
540
|
-
FileUtils.mkdir_p path
|
541
|
-
|
542
|
-
Gretel.breadcrumb_paths = [path.join("*.rb")]
|
543
|
-
|
544
|
-
path
|
545
|
-
end
|
546
|
-
end
|