gretel 3.0.5 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +7 -2
- data/.travis.yml +9 -3
- data/CHANGELOG.md +29 -1
- data/Gemfile +2 -13
- data/LICENSE.txt +2 -2
- data/README.md +34 -40
- data/Rakefile +1 -1
- data/coverage/coverage.txt +6 -0
- data/gretel.gemspec +9 -6
- data/lib/gretel.rb +4 -21
- data/lib/gretel/crumb.rb +10 -1
- data/lib/gretel/renderer.rb +119 -66
- data/lib/gretel/version.rb +2 -2
- data/lib/gretel/view_helpers.rb +2 -10
- data/test/dummy/app/assets/config/manifest.js +0 -0
- data/test/dummy/config/application.rb +3 -48
- data/test/dummy/config/breadcrumbs/test_crumbs.rb +5 -0
- data/test/dummy/config/environments/development.rb +0 -35
- data/test/dummy/config/environments/production.rb +0 -65
- data/test/dummy/config/environments/test.rb +0 -35
- data/test/dummy/config/routes.rb +4 -4
- data/test/dummy/db/migrate/20130122163007_create_projects.rb +1 -1
- data/test/dummy/db/migrate/20130122163051_create_issues.rb +1 -1
- data/test/dummy/db/schema.rb +16 -17
- data/test/gretel_test.rb +1 -2
- data/test/helper_methods_test.rb +167 -125
- data/test/test_helper.rb +15 -7
- metadata +70 -30
- data/lib/gretel/deprecated.rb +0 -2
- data/lib/gretel/deprecated/layout.rb +0 -15
- data/lib/gretel/deprecated/show_root_alone.rb +0 -12
- data/test/deprecated_test.rb +0 -25
data/lib/gretel/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Gretel
|
2
|
-
VERSION = "
|
3
|
-
end
|
2
|
+
VERSION = "4.0.0"
|
3
|
+
end
|
data/lib/gretel/view_helpers.rb
CHANGED
@@ -10,10 +10,6 @@ module Gretel
|
|
10
10
|
def breadcrumb(key = nil, *args)
|
11
11
|
if key.nil? || key.is_a?(Hash)
|
12
12
|
raise ArgumentError, "The `breadcrumb` method was called with #{key.inspect} as the key. This method is used to set the breadcrumb. Maybe you meant to call the `breadcrumbs` method (with an 's' in the end) which is used to render the breadcrumbs?"
|
13
|
-
elsif key.class.respond_to?(:model_name)
|
14
|
-
# Enables calling `breadcrumb @product` instead of `breadcrumb :product, @product`
|
15
|
-
args.unshift key
|
16
|
-
key = key.class.model_name.to_s.underscore.to_sym
|
17
13
|
end
|
18
14
|
@_gretel_renderer = Gretel::Renderer.new(self, key, *args)
|
19
15
|
end
|
@@ -48,12 +44,8 @@ module Gretel
|
|
48
44
|
# <% end %>
|
49
45
|
# <% end %>
|
50
46
|
# <% end %>
|
51
|
-
def breadcrumbs(options = {}
|
52
|
-
|
53
|
-
gretel_renderer.yield_links(options, &block)
|
54
|
-
else
|
55
|
-
gretel_renderer.render(options)
|
56
|
-
end
|
47
|
+
def breadcrumbs(options = {})
|
48
|
+
gretel_renderer.render(options)
|
57
49
|
end
|
58
50
|
|
59
51
|
# Returns or yields parent breadcrumb (second-to-last in the trail) if it is present.
|
File without changes
|
@@ -7,53 +7,8 @@ require "gretel"
|
|
7
7
|
|
8
8
|
module Dummy
|
9
9
|
class Application < Rails::Application
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# Custom directories with classes and modules you want to be autoloadable.
|
15
|
-
# config.autoload_paths += %W(#{config.root}/extras)
|
16
|
-
|
17
|
-
# Only load the plugins named here, in the order given (default is alphabetical).
|
18
|
-
# :all can be used as a placeholder for all plugins not explicitly named.
|
19
|
-
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
20
|
-
|
21
|
-
# Activate observers that should always be running.
|
22
|
-
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
23
|
-
|
24
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
25
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
26
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
27
|
-
|
28
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
29
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
30
|
-
# config.i18n.default_locale = :de
|
31
|
-
|
32
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
33
|
-
config.encoding = "utf-8"
|
34
|
-
|
35
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
36
|
-
config.filter_parameters += [:password]
|
37
|
-
|
38
|
-
# Enable escaping HTML in JSON.
|
39
|
-
config.active_support.escape_html_entities_in_json = true
|
40
|
-
|
41
|
-
# Use SQL instead of Active Record's schema dumper when creating the database.
|
42
|
-
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
43
|
-
# like if you have constraints or database-specific column types
|
44
|
-
# config.active_record.schema_format = :sql
|
45
|
-
|
46
|
-
# Enforce whitelist mode for mass assignment.
|
47
|
-
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
48
|
-
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
49
|
-
# parameters by using an attr_accessible or attr_protected declaration.
|
50
|
-
config.active_record.whitelist_attributes = true
|
51
|
-
|
52
|
-
# Enable the asset pipeline
|
53
|
-
config.assets.enabled = true
|
54
|
-
|
55
|
-
# Version of your assets, change this if you want to expire all your assets
|
56
|
-
config.assets.version = '1.0'
|
10
|
+
config.secret_token = "secret token"
|
11
|
+
config.active_support.deprecation = :log
|
12
|
+
config.eager_load = false
|
57
13
|
end
|
58
14
|
end
|
59
|
-
|
@@ -1,37 +1,2 @@
|
|
1
1
|
Dummy::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# In the development environment your application's code is reloaded on
|
5
|
-
# every request. This slows down response time but is perfect for development
|
6
|
-
# since you don't have to restart the web server when you make code changes.
|
7
|
-
config.cache_classes = false
|
8
|
-
|
9
|
-
# Log error messages when you accidentally call methods on nil.
|
10
|
-
config.whiny_nils = true
|
11
|
-
|
12
|
-
# Show full error reports and disable caching
|
13
|
-
config.consider_all_requests_local = true
|
14
|
-
config.action_controller.perform_caching = false
|
15
|
-
|
16
|
-
# Don't care if the mailer can't send
|
17
|
-
config.action_mailer.raise_delivery_errors = false
|
18
|
-
|
19
|
-
# Print deprecation notices to the Rails logger
|
20
|
-
config.active_support.deprecation = :log
|
21
|
-
|
22
|
-
# Only use best-standards-support built into browsers
|
23
|
-
config.action_dispatch.best_standards_support = :builtin
|
24
|
-
|
25
|
-
# Raise exception on mass assignment protection for Active Record models
|
26
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
27
|
-
|
28
|
-
# Log the query plan for queries taking more than this (works
|
29
|
-
# with SQLite, MySQL, and PostgreSQL)
|
30
|
-
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
31
|
-
|
32
|
-
# Do not compress assets
|
33
|
-
config.assets.compress = false
|
34
|
-
|
35
|
-
# Expands the lines which load the assets
|
36
|
-
config.assets.debug = true
|
37
2
|
end
|
@@ -1,67 +1,2 @@
|
|
1
1
|
Dummy::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# Code is not reloaded between requests
|
5
|
-
config.cache_classes = true
|
6
|
-
|
7
|
-
# Full error reports are disabled and caching is turned on
|
8
|
-
config.consider_all_requests_local = false
|
9
|
-
config.action_controller.perform_caching = true
|
10
|
-
|
11
|
-
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
-
config.serve_static_assets = false
|
13
|
-
|
14
|
-
# Compress JavaScripts and CSS
|
15
|
-
config.assets.compress = true
|
16
|
-
|
17
|
-
# Don't fallback to assets pipeline if a precompiled asset is missed
|
18
|
-
config.assets.compile = false
|
19
|
-
|
20
|
-
# Generate digests for assets URLs
|
21
|
-
config.assets.digest = true
|
22
|
-
|
23
|
-
# Defaults to nil and saved in location specified by config.assets.prefix
|
24
|
-
# config.assets.manifest = YOUR_PATH
|
25
|
-
|
26
|
-
# Specifies the header that your server uses for sending files
|
27
|
-
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
28
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
29
|
-
|
30
|
-
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
31
|
-
# config.force_ssl = true
|
32
|
-
|
33
|
-
# See everything in the log (default is :info)
|
34
|
-
# config.log_level = :debug
|
35
|
-
|
36
|
-
# Prepend all log lines with the following tags
|
37
|
-
# config.log_tags = [ :subdomain, :uuid ]
|
38
|
-
|
39
|
-
# Use a different logger for distributed setups
|
40
|
-
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
41
|
-
|
42
|
-
# Use a different cache store in production
|
43
|
-
# config.cache_store = :mem_cache_store
|
44
|
-
|
45
|
-
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
46
|
-
# config.action_controller.asset_host = "http://assets.example.com"
|
47
|
-
|
48
|
-
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
49
|
-
# config.assets.precompile += %w( search.js )
|
50
|
-
|
51
|
-
# Disable delivery errors, bad email addresses will be ignored
|
52
|
-
# config.action_mailer.raise_delivery_errors = false
|
53
|
-
|
54
|
-
# Enable threaded mode
|
55
|
-
# config.threadsafe!
|
56
|
-
|
57
|
-
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
58
|
-
# the I18n.default_locale when a translation can not be found)
|
59
|
-
config.i18n.fallbacks = true
|
60
|
-
|
61
|
-
# Send deprecation notices to registered listeners
|
62
|
-
config.active_support.deprecation = :notify
|
63
|
-
|
64
|
-
# Log the query plan for queries taking more than this (works
|
65
|
-
# with SQLite, MySQL, and PostgreSQL)
|
66
|
-
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
67
2
|
end
|
@@ -1,37 +1,2 @@
|
|
1
1
|
Dummy::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# The test environment is used exclusively to run your application's
|
5
|
-
# test suite. You never need to work with it otherwise. Remember that
|
6
|
-
# your test database is "scratch space" for the test suite and is wiped
|
7
|
-
# and recreated between test runs. Don't rely on the data there!
|
8
|
-
config.cache_classes = true
|
9
|
-
|
10
|
-
# Configure static asset server for tests with Cache-Control for performance
|
11
|
-
config.serve_static_assets = true
|
12
|
-
config.static_cache_control = "public, max-age=3600"
|
13
|
-
|
14
|
-
# Log error messages when you accidentally call methods on nil
|
15
|
-
config.whiny_nils = true
|
16
|
-
|
17
|
-
# Show full error reports and disable caching
|
18
|
-
config.consider_all_requests_local = true
|
19
|
-
config.action_controller.perform_caching = false
|
20
|
-
|
21
|
-
# Raise exceptions instead of rendering exception templates
|
22
|
-
config.action_dispatch.show_exceptions = false
|
23
|
-
|
24
|
-
# Disable request forgery protection in test environment
|
25
|
-
config.action_controller.allow_forgery_protection = false
|
26
|
-
|
27
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
-
# The :test delivery method accumulates sent emails in the
|
29
|
-
# ActionMailer::Base.deliveries array.
|
30
|
-
config.action_mailer.delivery_method = :test
|
31
|
-
|
32
|
-
# Raise exception on mass assignment protection for Active Record models
|
33
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
34
|
-
|
35
|
-
# Print deprecation notices to the stderr
|
36
|
-
config.active_support.deprecation = :stderr
|
37
2
|
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Dummy::Application.routes.draw do
|
2
2
|
root to: "dummy#dummy"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
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
7
|
|
8
8
|
resources :projects do
|
9
9
|
resources :issues
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
data/test/dummy/db/schema.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# This file is auto-generated from the current state of the database. Instead
|
3
2
|
# of editing this file, please use the migrations feature of Active Record to
|
4
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
5
4
|
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# from scratch.
|
10
|
-
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `rails
|
6
|
+
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
11
10
|
#
|
12
|
-
# It's strongly recommended
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
12
|
|
14
|
-
ActiveRecord::Schema.define(:
|
13
|
+
ActiveRecord::Schema.define(version: 2013_01_22_163051) do
|
15
14
|
|
16
|
-
create_table "issues", :
|
17
|
-
t.string
|
18
|
-
t.integer
|
19
|
-
t.datetime "created_at"
|
20
|
-
t.datetime "updated_at"
|
15
|
+
create_table "issues", force: :cascade do |t|
|
16
|
+
t.string "title"
|
17
|
+
t.integer "project_id"
|
18
|
+
t.datetime "created_at"
|
19
|
+
t.datetime "updated_at"
|
21
20
|
end
|
22
21
|
|
23
|
-
create_table "projects", :
|
24
|
-
t.string
|
25
|
-
t.datetime "created_at"
|
26
|
-
t.datetime "updated_at"
|
22
|
+
create_table "projects", force: :cascade do |t|
|
23
|
+
t.string "name"
|
24
|
+
t.datetime "created_at"
|
25
|
+
t.datetime "updated_at"
|
27
26
|
end
|
28
27
|
|
29
28
|
end
|
data/test/gretel_test.rb
CHANGED
@@ -11,7 +11,6 @@ class GretelTest < ActiveSupport::TestCase
|
|
11
11
|
Rails.root.join("app", "views", "breadcrumbs", "**", "*.rb")],
|
12
12
|
Gretel.breadcrumb_paths[-3..-1]
|
13
13
|
assert_equal ["development"], Gretel.reload_environments
|
14
|
-
assert !Gretel.suppress_deprecation_warnings?
|
15
14
|
end
|
16
15
|
|
17
16
|
test "configuration block" do
|
@@ -21,4 +20,4 @@ class GretelTest < ActiveSupport::TestCase
|
|
21
20
|
|
22
21
|
assert_equal ["development", "staging"], Gretel.reload_environments
|
23
22
|
end
|
24
|
-
end
|
23
|
+
end
|
data/test/helper_methods_test.rb
CHANGED
@@ -2,154 +2,167 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class HelperMethodsTest < ActionView::TestCase
|
4
4
|
include Gretel::ViewHelpers
|
5
|
+
|
6
|
+
self.fixture_path = File.expand_path("../../test/fixtures", __FILE__)
|
5
7
|
fixtures :all
|
8
|
+
|
6
9
|
helper :application
|
7
10
|
|
8
11
|
setup do
|
9
12
|
Gretel.reset!
|
10
13
|
end
|
11
14
|
|
15
|
+
def itemscope_value
|
16
|
+
ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES.include?("itemscope") ?
|
17
|
+
"itemscope" : ""
|
18
|
+
end
|
19
|
+
|
12
20
|
# Breadcrumb generation
|
13
21
|
|
14
|
-
test "
|
22
|
+
test "basic breadcrumb" do
|
15
23
|
breadcrumb :basic
|
16
|
-
|
17
|
-
breadcrumbs
|
24
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
25
|
+
breadcrumbs.to_s
|
18
26
|
end
|
19
27
|
|
20
|
-
test "
|
28
|
+
test "breadcrumb with root" do
|
21
29
|
breadcrumb :with_root
|
22
|
-
|
23
|
-
breadcrumbs
|
30
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
31
|
+
breadcrumbs.to_s
|
24
32
|
end
|
25
33
|
|
26
|
-
test "
|
34
|
+
test "breadcrumb with parent" do
|
27
35
|
breadcrumb :with_parent
|
28
|
-
|
29
|
-
breadcrumbs
|
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
|
30
38
|
end
|
31
39
|
|
32
|
-
test "
|
40
|
+
test "breadcrumb with autopath" do
|
33
41
|
breadcrumb :with_autopath, projects(:one)
|
34
|
-
|
35
|
-
breadcrumbs
|
42
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Test Project</span></div>},
|
43
|
+
breadcrumbs.to_s
|
36
44
|
end
|
37
45
|
|
38
|
-
test "
|
46
|
+
test "breadcrumb with parent object" do
|
39
47
|
breadcrumb :with_parent_object, issues(:one)
|
40
|
-
|
41
|
-
breadcrumbs
|
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
|
42
50
|
end
|
43
51
|
|
44
|
-
test "
|
52
|
+
test "multiple links" do
|
45
53
|
breadcrumb :multiple_links
|
46
|
-
|
47
|
-
breadcrumbs
|
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
|
48
56
|
end
|
49
57
|
|
50
|
-
test "
|
58
|
+
test "multiple links with parent" do
|
51
59
|
breadcrumb :multiple_links_with_parent
|
52
|
-
|
53
|
-
breadcrumbs
|
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
|
54
62
|
end
|
55
63
|
|
56
|
-
test "
|
64
|
+
test "semantic breadcrumb" do
|
57
65
|
breadcrumb :with_root
|
58
|
-
|
59
|
-
breadcrumbs(semantic: true)
|
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
|
60
68
|
end
|
61
69
|
|
62
70
|
test "doesn't show root alone" do
|
63
71
|
breadcrumb :root
|
64
|
-
|
72
|
+
assert_dom_equal "", breadcrumbs.to_s
|
65
73
|
end
|
66
74
|
|
67
75
|
test "displays single fragment" do
|
68
76
|
breadcrumb :root
|
69
|
-
|
70
|
-
breadcrumbs(display_single_fragment: true)
|
77
|
+
assert_dom_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
|
78
|
+
breadcrumbs(display_single_fragment: true).to_s
|
71
79
|
end
|
72
80
|
|
73
81
|
test "displays single non-root fragment" do
|
74
82
|
breadcrumb :basic
|
75
|
-
|
76
|
-
breadcrumbs(autoroot: false, display_single_fragment: true)
|
83
|
+
assert_dom_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
|
84
|
+
breadcrumbs(autoroot: false, display_single_fragment: true).to_s
|
77
85
|
end
|
78
86
|
|
79
|
-
test "
|
80
|
-
|
87
|
+
test "no breadcrumb" do
|
88
|
+
assert_dom_equal "", breadcrumbs.to_s
|
81
89
|
end
|
82
90
|
|
83
91
|
test "links current breadcrumb" do
|
84
92
|
breadcrumb :with_root
|
85
|
-
|
86
|
-
breadcrumbs(link_current: true)
|
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
|
87
95
|
end
|
88
96
|
|
89
|
-
test "
|
97
|
+
test "pretext" do
|
90
98
|
breadcrumb :basic
|
91
|
-
|
92
|
-
breadcrumbs(pretext: "You are here:
|
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
|
93
101
|
end
|
94
102
|
|
95
|
-
test "
|
103
|
+
test "posttext" do
|
96
104
|
breadcrumb :basic
|
97
|
-
|
98
|
-
breadcrumbs(posttext: "
|
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
|
99
107
|
end
|
100
108
|
|
101
109
|
test "autoroot disabled" do
|
102
110
|
breadcrumb :basic
|
103
|
-
|
111
|
+
assert_dom_equal "", breadcrumbs(autoroot: false).to_s
|
104
112
|
end
|
105
113
|
|
106
|
-
test "
|
114
|
+
test "separator" do
|
107
115
|
breadcrumb :with_root
|
108
|
-
|
109
|
-
breadcrumbs(separator: " » ")
|
116
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> » <span class="current">About</span></div>},
|
117
|
+
breadcrumbs(separator: " » ").to_s
|
110
118
|
end
|
111
119
|
|
112
|
-
test "
|
120
|
+
test "element id" do
|
113
121
|
breadcrumb :basic
|
114
|
-
|
115
|
-
breadcrumbs(id: "custom_id")
|
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
|
116
124
|
end
|
117
125
|
|
118
|
-
test "
|
126
|
+
test "custom container class" do
|
119
127
|
breadcrumb :basic
|
120
|
-
|
121
|
-
breadcrumbs(class: "custom_class")
|
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
|
122
130
|
end
|
123
131
|
|
124
|
-
test "
|
132
|
+
test "custom fragment class" do
|
125
133
|
breadcrumb :basic
|
126
|
-
|
127
|
-
breadcrumbs(
|
134
|
+
assert_dom_equal %{<div class="breadcrumbs"><a class="custom_fragment_class" href="/">Home</a> › <span class="custom_fragment_class current">About</span></div>},
|
135
|
+
breadcrumbs(fragment_class: "custom_fragment_class").to_s
|
128
136
|
end
|
129
137
|
|
130
|
-
test "
|
131
|
-
breadcrumb :
|
132
|
-
|
133
|
-
breadcrumbs
|
138
|
+
test "custom current class" do
|
139
|
+
breadcrumb :basic
|
140
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="custom_current_class">About</span></div>},
|
141
|
+
breadcrumbs(current_class: "custom_current_class").to_s
|
134
142
|
end
|
135
143
|
|
136
|
-
test "
|
137
|
-
breadcrumb :
|
138
|
-
|
139
|
-
breadcrumbs
|
144
|
+
test "custom pretext class" do
|
145
|
+
breadcrumb :basic
|
146
|
+
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>},
|
147
|
+
breadcrumbs(pretext: "You are here:", pretext_class: "custom_pretext_class").to_s
|
140
148
|
end
|
141
149
|
|
142
|
-
test "
|
143
|
-
breadcrumb :
|
150
|
+
test "custom posttext class" do
|
151
|
+
breadcrumb :basic
|
152
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span> <span class="custom_posttext_class">after breadcrumbs</span></div>},
|
153
|
+
breadcrumbs(posttext: "after breadcrumbs", posttext_class: "custom_posttext_class").to_s
|
154
|
+
end
|
144
155
|
|
145
|
-
|
146
|
-
|
147
|
-
|
156
|
+
test "unsafe html" do
|
157
|
+
breadcrumb :with_unsafe_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
|
148
161
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
162
|
+
test "safe html" do
|
163
|
+
breadcrumb :with_safe_html
|
164
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Test <strong>bold text</strong></span></div>},
|
165
|
+
breadcrumbs.to_s
|
153
166
|
end
|
154
167
|
|
155
168
|
test "parent breadcrumb" do
|
@@ -186,27 +199,36 @@ class HelperMethodsTest < ActionView::TestCase
|
|
186
199
|
assert_nil out
|
187
200
|
end
|
188
201
|
|
189
|
-
test "
|
190
|
-
breadcrumb :
|
202
|
+
test "link keys" do
|
203
|
+
breadcrumb :basic
|
204
|
+
assert_equal [:root, :basic], breadcrumbs.keys
|
205
|
+
end
|
191
206
|
|
192
|
-
|
193
|
-
|
207
|
+
test "using breadcrumbs as array" do
|
208
|
+
breadcrumb :basic
|
209
|
+
|
210
|
+
breadcrumbs.tap do |links|
|
211
|
+
assert_kind_of Array, links
|
212
|
+
assert_equal 2, links.count
|
194
213
|
end
|
214
|
+
end
|
195
215
|
|
196
|
-
|
216
|
+
test "sets current on last link in array" do
|
217
|
+
breadcrumb :multiple_links_with_parent
|
218
|
+
assert_equal [false, false, false, true], breadcrumbs.map(&:current?)
|
197
219
|
end
|
198
220
|
|
199
221
|
test "passing options to links" do
|
200
222
|
breadcrumb :with_link_options
|
201
223
|
|
202
|
-
breadcrumbs(autoroot: false) do |links|
|
224
|
+
breadcrumbs(autoroot: false).tap do |links|
|
203
225
|
links[0].tap do |link|
|
204
226
|
assert link.title?
|
205
227
|
assert_equal "My Title", link.title
|
206
|
-
|
228
|
+
|
207
229
|
assert link.other?
|
208
230
|
assert_equal "Other Option", link.other
|
209
|
-
|
231
|
+
|
210
232
|
assert !link.nonexistent?
|
211
233
|
assert_nil link.nonexistent
|
212
234
|
end
|
@@ -217,54 +239,54 @@ class HelperMethodsTest < ActionView::TestCase
|
|
217
239
|
end
|
218
240
|
end
|
219
241
|
|
220
|
-
|
221
|
-
breadcrumbs(autoroot: false)
|
242
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/about">Test</a> › <span class="current">Other Link</span></div>},
|
243
|
+
breadcrumbs(autoroot: false).to_s
|
222
244
|
end
|
223
245
|
|
224
246
|
test "without link" do
|
225
247
|
breadcrumb :without_link
|
226
|
-
|
227
|
-
breadcrumbs
|
248
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › Also without link › <span class="current">Without link</span></div>},
|
249
|
+
breadcrumbs.to_s
|
228
250
|
end
|
229
251
|
|
230
252
|
test "view context" do
|
231
253
|
breadcrumb :using_view_helper
|
232
|
-
|
233
|
-
breadcrumbs
|
254
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">TestTest</span></div>},
|
255
|
+
breadcrumbs.to_s
|
234
256
|
end
|
235
257
|
|
236
258
|
test "multiple arguments" do
|
237
259
|
breadcrumb :with_multiple_arguments, "One", "Two", "Three"
|
238
|
-
|
239
|
-
breadcrumbs
|
260
|
+
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>},
|
261
|
+
breadcrumbs.to_s
|
240
262
|
end
|
241
263
|
|
242
264
|
test "from views folder" do
|
243
265
|
breadcrumb :from_views
|
244
|
-
|
245
|
-
breadcrumbs
|
266
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Breadcrumb From View</span></div>},
|
267
|
+
breadcrumbs.to_s
|
246
268
|
end
|
247
269
|
|
248
270
|
test "with_breadcrumb" do
|
249
271
|
breadcrumb :basic
|
250
|
-
|
251
|
-
|
252
|
-
breadcrumbs
|
272
|
+
|
273
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
274
|
+
breadcrumbs.to_s
|
253
275
|
|
254
276
|
with_breadcrumb(:with_parent_object, issues(:one)) do
|
255
|
-
|
256
|
-
breadcrumbs
|
257
|
-
end
|
258
|
-
|
259
|
-
|
260
|
-
breadcrumbs
|
277
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/projects/1">Test Project</a> › <span class="current">Test Issue</span></div>},
|
278
|
+
breadcrumbs.to_s
|
279
|
+
end
|
280
|
+
|
281
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
282
|
+
breadcrumbs.to_s
|
261
283
|
end
|
262
284
|
|
263
285
|
test "calling breadcrumbs helper twice" do
|
264
286
|
breadcrumb :with_parent
|
265
287
|
2.times do
|
266
|
-
|
267
|
-
breadcrumbs
|
288
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/about">About</a> › <span class="current">Contact</span></div>},
|
289
|
+
breadcrumbs.to_s
|
268
290
|
end
|
269
291
|
end
|
270
292
|
|
@@ -279,7 +301,14 @@ class HelperMethodsTest < ActionView::TestCase
|
|
279
301
|
self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
|
280
302
|
|
281
303
|
breadcrumb :basic
|
282
|
-
assert_equal "/testpath?a=1&b=2", breadcrumbs
|
304
|
+
assert_equal "/testpath?a=1&b=2", breadcrumbs.last.url
|
305
|
+
end
|
306
|
+
|
307
|
+
test "current link url is not set to fullpath using link_current_to_request_path=false" do
|
308
|
+
self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
|
309
|
+
|
310
|
+
breadcrumb :basic
|
311
|
+
assert_equal "/about", breadcrumbs(:link_current_to_request_path => false).last.url
|
283
312
|
end
|
284
313
|
|
285
314
|
test "calling the breadcrumb method with wrong arguments" do
|
@@ -298,52 +327,65 @@ class HelperMethodsTest < ActionView::TestCase
|
|
298
327
|
|
299
328
|
test "inferred breadcrumb" do
|
300
329
|
breadcrumb Project.first
|
301
|
-
|
302
|
-
breadcrumbs
|
330
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">Test Project</span></div>},
|
331
|
+
breadcrumbs.to_s
|
332
|
+
end
|
333
|
+
|
334
|
+
test "inferred parent" do
|
335
|
+
breadcrumb :with_inferred_parent
|
336
|
+
|
337
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <a href="/projects/1">Test Project</a> › <span class="current">Test</span></div>},
|
338
|
+
breadcrumbs.to_s
|
303
339
|
end
|
304
340
|
|
305
341
|
# Styles
|
306
342
|
|
307
343
|
test "default style" do
|
308
344
|
breadcrumb :basic
|
309
|
-
|
310
|
-
breadcrumbs
|
345
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> › <span class="current">About</span></div>},
|
346
|
+
breadcrumbs.to_s
|
311
347
|
end
|
312
348
|
|
313
349
|
test "ordered list style" do
|
314
350
|
breadcrumb :basic
|
315
|
-
|
316
|
-
breadcrumbs(style: :ol)
|
351
|
+
assert_dom_equal %{<ol class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ol>},
|
352
|
+
breadcrumbs(style: :ol).to_s
|
317
353
|
end
|
318
354
|
|
319
355
|
test "unordered list style" do
|
320
356
|
breadcrumb :basic
|
321
|
-
|
322
|
-
breadcrumbs(style: :ul)
|
357
|
+
assert_dom_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
|
358
|
+
breadcrumbs(style: :ul).to_s
|
323
359
|
end
|
324
360
|
|
325
361
|
test "bootstrap style" do
|
326
362
|
breadcrumb :basic
|
327
|
-
|
328
|
-
breadcrumbs(style: :bootstrap)
|
363
|
+
assert_dom_equal %{<ol class="breadcrumb"><li><a href="/">Home</a></li><li class="active">About</li></ol>},
|
364
|
+
breadcrumbs(style: :bootstrap).to_s
|
365
|
+
end
|
366
|
+
|
367
|
+
test "bootstrap4 style" do
|
368
|
+
breadcrumb :basic
|
369
|
+
assert_dom_equal %{<ol class="breadcrumb"><li class="breadcrumb-item"><a href="/">Home</a></li><li class="breadcrumb-item active">About</li></ol>},
|
370
|
+
breadcrumbs(style: :bootstrap4).to_s
|
329
371
|
end
|
330
372
|
|
331
373
|
test "foundation5 style" do
|
332
374
|
breadcrumb :basic
|
333
|
-
|
334
|
-
breadcrumbs(style: :foundation5)
|
375
|
+
assert_dom_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
|
376
|
+
breadcrumbs(style: :foundation5).to_s
|
335
377
|
end
|
336
378
|
|
337
379
|
test "custom container and fragment tags" do
|
338
380
|
breadcrumb :basic
|
339
|
-
|
340
|
-
breadcrumbs(container_tag: :c, fragment_tag: :f)
|
381
|
+
assert_dom_equal %{<c class="breadcrumbs"><f><a href="/">Home</a></f> › <f class="current">About</f></c>},
|
382
|
+
breadcrumbs(container_tag: :c, fragment_tag: :f).to_s
|
341
383
|
end
|
342
384
|
|
343
385
|
test "custom semantic container and fragment tags" do
|
344
386
|
breadcrumb :basic
|
345
|
-
|
346
|
-
breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true)
|
387
|
+
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>},
|
388
|
+
breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true).to_s
|
347
389
|
end
|
348
390
|
|
349
391
|
test "unknown style" do
|
@@ -355,11 +397,11 @@ class HelperMethodsTest < ActionView::TestCase
|
|
355
397
|
|
356
398
|
test "register style" do
|
357
399
|
Gretel.register_style :test_style, { container_tag: :one, fragment_tag: :two }
|
358
|
-
|
400
|
+
|
359
401
|
breadcrumb :basic
|
360
402
|
|
361
|
-
|
362
|
-
breadcrumbs(style: :test_style)
|
403
|
+
assert_dom_equal %{<one class="breadcrumbs"><two><a href="/">Home</a></two><two class="current">About</two></one>},
|
404
|
+
breadcrumbs(style: :test_style).to_s
|
363
405
|
end
|
364
406
|
|
365
407
|
# Configuration reload
|
@@ -380,7 +422,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
380
422
|
end
|
381
423
|
|
382
424
|
breadcrumb :about
|
383
|
-
|
425
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
384
426
|
|
385
427
|
sleep 1 # File change interval is 1 second
|
386
428
|
|
@@ -396,7 +438,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
396
438
|
end
|
397
439
|
|
398
440
|
breadcrumb :about
|
399
|
-
|
441
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/test">Home (reloaded)</a> › <span class="current">About (reloaded)</span></div>}, breadcrumbs.to_s
|
400
442
|
end
|
401
443
|
|
402
444
|
test "reload configuration when file is added" do
|
@@ -425,7 +467,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
425
467
|
end
|
426
468
|
|
427
469
|
breadcrumb :about
|
428
|
-
|
470
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
429
471
|
end
|
430
472
|
|
431
473
|
test "reload configuration when file is deleted" do
|
@@ -453,7 +495,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
453
495
|
end
|
454
496
|
|
455
497
|
breadcrumb :contact
|
456
|
-
|
498
|
+
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
|
457
499
|
|
458
500
|
File.delete path.join("pages.rb")
|
459
501
|
|
@@ -463,7 +505,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
463
505
|
end
|
464
506
|
|
465
507
|
breadcrumb :about
|
466
|
-
|
508
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
467
509
|
end
|
468
510
|
|
469
511
|
test "reloads only in development environment" do
|
@@ -483,7 +525,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
483
525
|
end
|
484
526
|
|
485
527
|
breadcrumb :about
|
486
|
-
|
528
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
487
529
|
|
488
530
|
sleep 1
|
489
531
|
|
@@ -499,7 +541,7 @@ class HelperMethodsTest < ActionView::TestCase
|
|
499
541
|
end
|
500
542
|
|
501
543
|
breadcrumb :about
|
502
|
-
|
544
|
+
assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> › <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
|
503
545
|
end
|
504
546
|
|
505
547
|
private
|