middleman-breadcrumbs 0.2.0 → 0.3.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
2
  SHA1:
3
- metadata.gz: e54e14f32555c4b4e3b49bafcad3dfd8e87d3655
4
- data.tar.gz: 7e15f3e860f159ce68438bce687d40dbd1c895f6
3
+ metadata.gz: fa37cb3fa7f5f6c9acc99458288862060c9d0247
4
+ data.tar.gz: 5a74693d11318ef62bd3c6b9818c667e9ddecc4d
5
5
  SHA512:
6
- metadata.gz: e60c78c75b42d7f8dfda9d7f97253c49e13084307ee97cbe28f85bbc95782344c5ee38b5adf9a44b15eb1d5cd7235f1db1e1eafa5c999e9de3d65fbd6e9df31a
7
- data.tar.gz: b67ba7c704b4c61fc4dbc2890394a2632c7d2a76bcc3ecc298624858b19178ce10d251cf4cc63b4a447273110d3460cdb6d5947358a4a6262d496e1a0d050b07
6
+ metadata.gz: fd81e3bbfe2ab33dc2d370ec988cef61c0a5d3fb6b8c3fe5616d7c6fd71371bdb49d14fa8a81ee4a3662249e63a7d2a34157941cfc084a918f8e54c8b00f1308
7
+ data.tar.gz: d583f0a4cb89ddbd2c0e7dea0994e12563a6be369fa3de7ec0b7f5a2757e7d1544b5831384863ba80fd1bee1965375bbf69e0c92f9da35e260d523eea3dbde20
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.3.0 / 2015-10-27
6
+
7
+ * Add `:separator` and `:wrapper` options to support a wider range of output styles. [#2]
8
+ * Switch from ffaker to new improved Faker.
9
+
5
10
  ## 0.2.0 / 2015-10-25
6
11
 
7
12
  * Remove setup and console executables from gem. [#3]
data/README.md CHANGED
@@ -1,11 +1,26 @@
1
- middleman-breadcrumbs
2
- =====================
1
+ # middleman-breadcrumbs
3
2
 
4
3
  Breadcrumbs helper for Middleman
5
4
 
6
- Usage
7
- -----
5
+ ## Usage
8
6
 
9
7
  In config.rb: `activate :breadcrumbs`.
10
8
 
11
9
  In your view files, just call `breadcrumbs(current_page)`.
10
+
11
+ ### Options
12
+
13
+ #### `:separator`
14
+
15
+ The breadcrumb levels are separated with ` > ` by default. If you want a different separator, use the `:separator` option—e.g., `breadcrumbs(current_page, separator: '|||')`.
16
+
17
+ #### `:wrapper`
18
+
19
+ If you want to wrap each breadcrumb level in a tag, pass the tag name to the `:wrapper` option. For example, if you want your breadcrumbs in a list:
20
+
21
+ ```erb
22
+ <ul>
23
+ <%= breadcrumbs current_page, wrapper: :li, separator: nil %>
24
+ </ul>
25
+ ```
26
+ This will wrap each breadcrumb level in a `<li>` element.
@@ -6,9 +6,15 @@ module BreadcrumbsHelper
6
6
  klass.send(:include, Padrino::Helpers) unless klass.instance_methods.include? :link_to
7
7
  end
8
8
 
9
- def breadcrumbs(page)
9
+ def breadcrumbs(page, separator: ' > ', wrapper: nil)
10
10
  hierarchy = [page]
11
11
  hierarchy.unshift hierarchy.first.parent while hierarchy.first.parent
12
- hierarchy.collect {|page| link_to page.data.title, "/#{page.path}" }.join(h ' > ')
12
+ hierarchy.collect {|page| wrap link_to(page.data.title, "/#{page.path}"), wrapper: wrapper }.join(h separator)
13
13
  end
14
- end
14
+
15
+ private
16
+
17
+ def wrap(content, wrapper: wrapper)
18
+ wrapper ? content_tag(wrapper) { content } : content
19
+ end
20
+ end
@@ -1,2 +1,2 @@
1
1
  require File.join(File.dirname(__FILE__), 'breadcrumbs')
2
- Breadcrumbs::VERSION = '0.2.0'
2
+ Breadcrumbs::VERSION = '0.3.0'
@@ -13,7 +13,13 @@ Gem::Specification.new do |s|
13
13
  s.license = 'MIT'
14
14
 
15
15
  s.add_runtime_dependency "middleman", '>= 3.3.5'
16
- ['byebug', ['guard', '~> 2.10.5'], 'guard-minitest', 'ffaker', 'rake'].each {|gem| s.add_development_dependency *gem }
16
+ [
17
+ 'byebug',
18
+ ['guard', '~> 2.10.5'],
19
+ 'guard-minitest',
20
+ ['faker', '~> 1.5.0'],
21
+ 'rake'
22
+ ].each {|gem| s.add_development_dependency *gem }
17
23
 
18
24
  s.files = `git ls-files`.split("\n")
19
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
-
2
+ require 'ostruct'
3
3
  require 'middleman-breadcrumbs/breadcrumbs_helper'
4
4
 
5
5
  describe BreadcrumbsHelper do
@@ -41,15 +41,58 @@ describe BreadcrumbsHelper do
41
41
  end
42
42
 
43
43
  describe 'non-top-level page' do
44
- it 'joins all links to parent pages with > signs' do
45
- parent = page
46
- grandparent = page
47
- @page.parent = parent
48
- @page.parent.parent = grandparent
44
+ before do
45
+ @parent = page
46
+ @grandparent = page
47
+ @page.parent = @parent
48
+ @page.parent.parent = @grandparent
49
+ end
50
+
51
+ describe 'separator' do
52
+ describe 'specified' do
53
+ it 'joins all links to parent pages with the specified separator' do
54
+ separator = Faker::Lorem.characters(5)
55
+
56
+ @helper.breadcrumbs(@page, separator: separator).must_equal([@grandparent, @parent, @page].collect do |level|
57
+ link_to level.data.title, "/#{level.path}"
58
+ end.join separator)
59
+ end
60
+
61
+ describe 'nil' do
62
+ it 'does not use a separator' do
63
+ @helper.breadcrumbs(@page, separator: nil).must_equal ([@grandparent, @parent, @page].collect do |level|
64
+ link_to level.data.title, "/#{level.path}"
65
+ end.join)
66
+ end
67
+ end
68
+ end
49
69
 
50
- @helper.breadcrumbs(@page).must_equal([grandparent, parent, @page].collect do |level|
51
- link_to level.data.title, "/#{level.path}"
52
- end.join ' &gt; ')
70
+ describe 'not specified' do
71
+ it 'uses " > " as the separator' do
72
+ @helper.breadcrumbs(@page).must_equal([@grandparent, @parent, @page].collect do |level|
73
+ link_to level.data.title, "/#{level.path}"
74
+ end.join ' &gt; ')
75
+ end
76
+ end
77
+ end
78
+
79
+ describe 'wrapper' do
80
+ describe 'specified' do
81
+ it 'wraps breadcrumbs in the specified element type' do
82
+ wrapper = Faker::Lorem.word.to_sym
83
+ @helper.breadcrumbs(@page, wrapper: wrapper, separator: nil).must_equal([@grandparent, @parent, @page].collect do |level|
84
+ content_tag(wrapper) { link_to level.data.title, "/#{level.path}" }
85
+ end.join)
86
+ end
87
+ end
88
+
89
+ describe 'not specified' do
90
+ it 'does not wrap breadcrumbs in tags' do
91
+ @helper.breadcrumbs(@page, separator: nil).must_equal([@grandparent, @parent, @page].collect do |level|
92
+ link_to level.data.title, "/#{level.path}"
93
+ end.join)
94
+ end
95
+ end
53
96
  end
54
97
  end
55
98
  end
@@ -57,9 +100,9 @@ describe BreadcrumbsHelper do
57
100
  private
58
101
 
59
102
  def page
60
- path = Faker::Internet.http_url
103
+ path = Faker::Internet.url
61
104
  title = Faker::Lorem.sentence
62
105
  data = OpenStruct.new title: title
63
106
  OpenStruct.new data: data, path: path
64
107
  end
65
- end
108
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'minitest/autorun'
2
2
  require 'byebug'
3
3
  require 'middleman'
4
- require 'ffaker'
4
+ require 'faker'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-breadcrumbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2015-10-25 00:00:00.000000000 Z
11
+ date: 2015-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: ffaker
70
+ name: faker
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
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
- version: '0'
82
+ version: 1.5.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement