middleman-breadcrumbs 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +17 -12
- data/lib/middleman-breadcrumbs.rb +1 -3
- data/lib/middleman-breadcrumbs/breadcrumbs.rb +24 -1
- data/lib/middleman-breadcrumbs/version.rb +1 -1
- data/middleman-breadcrumbs.gemspec +2 -2
- data/spec/{breadcrumbs_helper_spec.rb → breadcrumbs_spec.rb} +45 -27
- metadata +21 -22
- data/lib/middleman-breadcrumbs/breadcrumbs_helper.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb327948a5ee3560e75c08cc83863aeeaf8eb696
|
4
|
+
data.tar.gz: cf55b9802002900e4968cdbe9065abfb2f8d35a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c823d04dc7ab7a6a69b79e72284cb50a948dc290083617545acb21d65443f587f12666ab01a6a2e35788deccf28eb8195a8e56e536d7d5820ab2ea618aafc44
|
7
|
+
data.tar.gz: 3d878201540499d3e3d4fd584dac972279273be754810e0a75530d534079d03b3457a2737cb0839b74e27f67239d8cc2ad48172cb91c428e456739407213d1be
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# middleman-breadcrumbs
|
4
4
|
|
5
|
-
Breadcrumbs helper for Middleman
|
5
|
+
Breadcrumbs helper for [Middleman](https://middlemanapp.com/)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -10,23 +10,28 @@ Install the gem as usual: put `gem 'middleman-breadcrumbs'` in Gemfile, then run
|
|
10
10
|
|
11
11
|
Put `activate :breadcrumbs` in config.rb (*not* in the `configure :build` block).
|
12
12
|
|
13
|
-
##
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
This gem has two configuration options, which are set in the [usual way for Middleman extensions](https://middlemanapp.com/advanced/configuration/#configuring-extensions).
|
14
16
|
|
15
|
-
|
17
|
+
<dl>
|
18
|
+
<dt>`:separator`</dt>
|
19
|
+
<dd>String that separates the breadcrumb levels. Default is ` > `.</dd>
|
20
|
+
<dt>`:wrapper`</dt>
|
21
|
+
<dd>Tag name (as a symbol) in which to wrap each breadcrumb level. Default is `nil`, which means no wrapping.</dd>
|
22
|
+
</dl>
|
16
23
|
|
17
|
-
|
24
|
+
For example, if you wanted to wrap the breadcrumb levels in `<li>` elements and separate them with bullets, you would put the following in `config.rb`:
|
18
25
|
|
19
|
-
|
26
|
+
```ruby
|
27
|
+
activate :breadcrumbs, separator: ' • ', wrapper: :li
|
28
|
+
```
|
20
29
|
|
21
|
-
The breadcrumb levels are separated with ` > ` by default. If you want a different separator, use the `:separator` option—e.g., `breadcrumbs(current_page, separator: '|||')`.
|
22
30
|
|
23
|
-
|
31
|
+
## Usage
|
24
32
|
|
25
|
-
|
33
|
+
In your view files, just call `breadcrumbs(current_page)` to display breadcrumbs. If you want to override the separator or wrapper defined in the `config.rb` file, pass the appropriate options to the `breadcrumbs` method:
|
26
34
|
|
27
35
|
```erb
|
28
|
-
|
29
|
-
<%= breadcrumbs current_page, wrapper: :li, separator: nil %>
|
30
|
-
</ul>
|
36
|
+
<%= breadcrumbs(current_page, separator: ' ||| ', wrapper: :div) %>
|
31
37
|
```
|
32
|
-
This will wrap each breadcrumb level in a `<li>` element.
|
@@ -1,5 +1,3 @@
|
|
1
1
|
Dir[File.join File.dirname(__FILE__), 'middleman-breadcrumbs', '**', '*.rb'].each {|file| puts file; require file }
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
::Middleman::Extensions.register :breadcrumbs, Breadcrumbs
|
3
|
+
::Middleman::Extensions.register :breadcrumbs, Breadcrumbs
|
@@ -1,9 +1,32 @@
|
|
1
1
|
require 'middleman'
|
2
2
|
require File.join(File.dirname(__FILE__), 'version')
|
3
|
+
require 'rack/utils'
|
4
|
+
require 'padrino-helpers'
|
3
5
|
|
4
6
|
class Breadcrumbs < Middleman::Extension
|
5
7
|
include BreadcrumbsVersion
|
6
|
-
|
8
|
+
include Padrino::Helpers
|
9
|
+
|
10
|
+
option :separator, ' > ', 'Default separator between breadcrumb levels'
|
11
|
+
option :wrapper, nil, 'Name of tag (as symbol) in which to wrap each breadcrumb level, or nil for no wrapping'
|
12
|
+
|
13
|
+
expose_to_template :breadcrumbs
|
14
|
+
|
15
|
+
def initialize(app, options_hash = {}, &block)
|
7
16
|
super
|
17
|
+
@separator = options.separator
|
18
|
+
@wrapper = options.wrapper
|
19
|
+
end
|
20
|
+
|
21
|
+
def breadcrumbs(page, separator: @separator, wrapper: @wrapper)
|
22
|
+
hierarchy = [page]
|
23
|
+
hierarchy.unshift hierarchy.first.parent while hierarchy.first.parent
|
24
|
+
hierarchy.collect {|page| wrap link_to(page.data.title, "/#{page.path}"), wrapper: wrapper }.join(h separator)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def wrap(content, wrapper: wrapper)
|
30
|
+
wrapper ? content_tag(wrapper) { content } : content
|
8
31
|
end
|
9
32
|
end
|
@@ -14,10 +14,10 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.required_ruby_version = '>= 2.0'
|
16
16
|
|
17
|
-
s.add_runtime_dependency "middleman", '>=
|
17
|
+
s.add_runtime_dependency "middleman", '>= 4.0.0'
|
18
18
|
[
|
19
19
|
'byebug',
|
20
|
-
['guard', '
|
20
|
+
['guard', '>= 2.10.5'],
|
21
21
|
'guard-minitest',
|
22
22
|
['faker', '~> 1.5.0'],
|
23
23
|
'rake'
|
@@ -1,35 +1,23 @@
|
|
1
1
|
require_relative './spec_helper'
|
2
2
|
require 'ostruct'
|
3
|
-
require 'middleman-breadcrumbs/
|
3
|
+
require 'middleman-breadcrumbs/breadcrumbs'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe Breadcrumbs do
|
6
6
|
before do
|
7
|
-
@
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
describe '.included' do
|
12
|
-
describe 'link_to is defined' do
|
13
|
-
it 'does not include Padrino::Helpers' do
|
14
|
-
methods = @helper_class.instance_methods
|
15
|
-
@helper_class.stub :instance_methods, methods + [:link_to] do
|
16
|
-
@helper_class.send :include, BreadcrumbsHelper
|
17
|
-
@helper_class.wont_include Padrino::Helpers
|
18
|
-
end
|
7
|
+
@app = Class.new do
|
8
|
+
[:after_configuration, :initialized, :instance_available].each do |method|
|
9
|
+
define_method(method) { true }
|
19
10
|
end
|
20
|
-
end
|
11
|
+
end.new
|
12
|
+
@helper = Breadcrumbs.new @app
|
13
|
+
end
|
21
14
|
|
22
|
-
|
23
|
-
|
24
|
-
@helper_class.send :include, BreadcrumbsHelper
|
25
|
-
@helper_class.must_include Padrino::Helpers
|
26
|
-
end
|
27
|
-
end
|
15
|
+
it 'includes Padrino::Helpers' do
|
16
|
+
Breadcrumbs.must_include Padrino::Helpers
|
28
17
|
end
|
29
18
|
|
30
19
|
describe '#breadcrumbs' do
|
31
20
|
before do
|
32
|
-
@helper.singleton_class.send :include, BreadcrumbsHelper
|
33
21
|
self.singleton_class.send :include, Padrino::Helpers
|
34
22
|
@page = page
|
35
23
|
end
|
@@ -52,7 +40,6 @@ describe BreadcrumbsHelper do
|
|
52
40
|
describe 'specified' do
|
53
41
|
it 'joins all links to parent pages with the specified separator' do
|
54
42
|
separator = Faker::Lorem.characters(5)
|
55
|
-
|
56
43
|
@helper.breadcrumbs(@page, separator: separator).must_equal breadcrumb_links.join separator
|
57
44
|
end
|
58
45
|
|
@@ -64,8 +51,23 @@ describe BreadcrumbsHelper do
|
|
64
51
|
end
|
65
52
|
|
66
53
|
describe 'not specified' do
|
67
|
-
|
68
|
-
|
54
|
+
describe 'default separator' do
|
55
|
+
describe 'specified in config' do
|
56
|
+
before do
|
57
|
+
@default_separator = Faker::Lorem.characters(5)
|
58
|
+
@helper = Breadcrumbs.new @app, separator: @default_separator
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'uses the specified default separator' do
|
62
|
+
@helper.breadcrumbs(@page).must_equal breadcrumb_links.join @default_separator
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'not specified in config' do
|
67
|
+
it 'uses " > " as the separator' do
|
68
|
+
@helper.breadcrumbs(@page).must_equal breadcrumb_links.join ' > '
|
69
|
+
end
|
70
|
+
end
|
69
71
|
end
|
70
72
|
end
|
71
73
|
end
|
@@ -80,8 +82,24 @@ describe BreadcrumbsHelper do
|
|
80
82
|
end
|
81
83
|
|
82
84
|
describe 'not specified' do
|
83
|
-
|
84
|
-
|
85
|
+
describe 'default wrapper' do
|
86
|
+
describe 'specified in config' do
|
87
|
+
before do
|
88
|
+
@default_wrapper = Faker::Lorem.word.to_sym
|
89
|
+
@helper = Breadcrumbs.new @app, wrapper: @default_wrapper
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'wraps breadcrumbs in the specified element type' do
|
93
|
+
wrapped_links = breadcrumb_links.collect {|link| content_tag(@default_wrapper) { link } }
|
94
|
+
@helper.breadcrumbs(@page, separator: nil).must_equal wrapped_links.join
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'not specified in config' do
|
99
|
+
it 'does not wrap breadcrumbs in tags' do
|
100
|
+
@helper.breadcrumbs(@page, separator: nil).must_equal breadcrumb_links.join
|
101
|
+
end
|
102
|
+
end
|
85
103
|
end
|
86
104
|
end
|
87
105
|
end
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-breadcrumbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marnen Laibow-Koser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: byebug
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: guard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 2.10.5
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.10.5
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: faker
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 1.5.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.5.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: Breadcrumbs helper for Middleman
|
@@ -112,10 +112,9 @@ files:
|
|
112
112
|
- bin/setup
|
113
113
|
- lib/middleman-breadcrumbs.rb
|
114
114
|
- lib/middleman-breadcrumbs/breadcrumbs.rb
|
115
|
-
- lib/middleman-breadcrumbs/breadcrumbs_helper.rb
|
116
115
|
- lib/middleman-breadcrumbs/version.rb
|
117
116
|
- middleman-breadcrumbs.gemspec
|
118
|
-
- spec/
|
117
|
+
- spec/breadcrumbs_spec.rb
|
119
118
|
- spec/spec_helper.rb
|
120
119
|
homepage: http://github.com/marnen/middleman-breadcrumbs
|
121
120
|
licenses:
|
@@ -127,20 +126,20 @@ require_paths:
|
|
127
126
|
- lib
|
128
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
128
|
requirements:
|
130
|
-
- -
|
129
|
+
- - ">="
|
131
130
|
- !ruby/object:Gem::Version
|
132
131
|
version: '2.0'
|
133
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
133
|
requirements:
|
135
|
-
- -
|
134
|
+
- - ">="
|
136
135
|
- !ruby/object:Gem::Version
|
137
136
|
version: '0'
|
138
137
|
requirements: []
|
139
138
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.4.
|
139
|
+
rubygems_version: 2.4.5
|
141
140
|
signing_key:
|
142
141
|
specification_version: 4
|
143
142
|
summary: Breadcrumbs helper for Middleman
|
144
143
|
test_files:
|
145
|
-
- spec/
|
144
|
+
- spec/breadcrumbs_spec.rb
|
146
145
|
- spec/spec_helper.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'rack/utils'
|
2
|
-
require 'padrino-helpers'
|
3
|
-
|
4
|
-
module BreadcrumbsHelper
|
5
|
-
def self.included(klass)
|
6
|
-
klass.send(:include, Padrino::Helpers) unless klass.instance_methods.include? :link_to
|
7
|
-
end
|
8
|
-
|
9
|
-
def breadcrumbs(page, separator: ' > ', wrapper: nil)
|
10
|
-
hierarchy = [page]
|
11
|
-
hierarchy.unshift hierarchy.first.parent while hierarchy.first.parent
|
12
|
-
hierarchy.collect {|page| wrap link_to(page.data.title, "/#{page.path}"), wrapper: wrapper }.join(h separator)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def wrap(content, wrapper: wrapper)
|
18
|
-
wrapper ? content_tag(wrapper) { content } : content
|
19
|
-
end
|
20
|
-
end
|