jekyll-nested-menu-generator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +105 -0
- data/LICENSE.md +27 -0
- data/README.md +23 -0
- data/jekyll-nested-menu-generator.gemspec +19 -0
- data/lib/jekyll-nested-menu-generator.rb +75 -0
- data/spec/nested_menu_spec.rb +70 -0
- data/spec/spec_helper.rb +21 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cb45ee0365553b9ac6faf9081ecebaed43379898
|
4
|
+
data.tar.gz: ba27088d82105b6d650f778e562f39599fdfd11d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e79a38174b5c91d361ae35a322369cfdf4ff5e31ae89213305ce5130157ce3c35e1d49a34a3abfee24cd80d232dc7968d9018d12336fb1c46700509c6f445059
|
7
|
+
data.tar.gz: 5f6eadad685e24fe6e1dd62ebaf45cd232130fdd1114d8960e873092701b3c94faee66d9b3b078a6b9a1b9197d1fff2593b5eb5fbcf7ee5294cfb09c389f3ccf
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jekyll-nested-menu-generator (0.0.1)
|
5
|
+
jekyll
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
blankslate (2.1.2.4)
|
11
|
+
celluloid (0.16.0)
|
12
|
+
timers (~> 4.0.0)
|
13
|
+
classifier-reborn (2.0.3)
|
14
|
+
fast-stemmer (~> 1.0)
|
15
|
+
coderay (1.1.0)
|
16
|
+
coffee-script (2.3.0)
|
17
|
+
coffee-script-source
|
18
|
+
execjs
|
19
|
+
coffee-script-source (1.9.0)
|
20
|
+
colorator (0.1)
|
21
|
+
diff-lcs (1.2.5)
|
22
|
+
execjs (2.3.0)
|
23
|
+
fakefs (0.6.5)
|
24
|
+
fast-stemmer (1.0.2)
|
25
|
+
ffi (1.9.6)
|
26
|
+
hitimes (1.2.2)
|
27
|
+
jekyll (2.5.3)
|
28
|
+
classifier-reborn (~> 2.0)
|
29
|
+
colorator (~> 0.1)
|
30
|
+
jekyll-coffeescript (~> 1.0)
|
31
|
+
jekyll-gist (~> 1.0)
|
32
|
+
jekyll-paginate (~> 1.0)
|
33
|
+
jekyll-sass-converter (~> 1.0)
|
34
|
+
jekyll-watch (~> 1.1)
|
35
|
+
kramdown (~> 1.3)
|
36
|
+
liquid (~> 2.6.1)
|
37
|
+
mercenary (~> 0.3.3)
|
38
|
+
pygments.rb (~> 0.6.0)
|
39
|
+
redcarpet (~> 3.1)
|
40
|
+
safe_yaml (~> 1.0)
|
41
|
+
toml (~> 0.1.0)
|
42
|
+
jekyll-coffeescript (1.0.1)
|
43
|
+
coffee-script (~> 2.2)
|
44
|
+
jekyll-gist (1.1.0)
|
45
|
+
jekyll-paginate (1.1.0)
|
46
|
+
jekyll-sass-converter (1.3.0)
|
47
|
+
sass (~> 3.2)
|
48
|
+
jekyll-watch (1.2.1)
|
49
|
+
listen (~> 2.7)
|
50
|
+
kramdown (1.5.0)
|
51
|
+
liquid (2.6.2)
|
52
|
+
listen (2.8.5)
|
53
|
+
celluloid (>= 0.15.2)
|
54
|
+
rb-fsevent (>= 0.9.3)
|
55
|
+
rb-inotify (>= 0.9)
|
56
|
+
mercenary (0.3.5)
|
57
|
+
method_source (0.8.2)
|
58
|
+
mini_portile (0.6.2)
|
59
|
+
nokogiri (1.6.6.2)
|
60
|
+
mini_portile (~> 0.6.0)
|
61
|
+
parslet (1.5.0)
|
62
|
+
blankslate (~> 2.0)
|
63
|
+
posix-spawn (0.3.9)
|
64
|
+
pry (0.10.1)
|
65
|
+
coderay (~> 1.1.0)
|
66
|
+
method_source (~> 0.8.1)
|
67
|
+
slop (~> 3.4)
|
68
|
+
pygments.rb (0.6.2)
|
69
|
+
posix-spawn (~> 0.3.6)
|
70
|
+
yajl-ruby (~> 1.2.0)
|
71
|
+
rb-fsevent (0.9.4)
|
72
|
+
rb-inotify (0.9.5)
|
73
|
+
ffi (>= 0.5.0)
|
74
|
+
redcarpet (3.2.2)
|
75
|
+
rspec (3.2.0)
|
76
|
+
rspec-core (~> 3.2.0)
|
77
|
+
rspec-expectations (~> 3.2.0)
|
78
|
+
rspec-mocks (~> 3.2.0)
|
79
|
+
rspec-core (3.2.0)
|
80
|
+
rspec-support (~> 3.2.0)
|
81
|
+
rspec-expectations (3.2.0)
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
+
rspec-support (~> 3.2.0)
|
84
|
+
rspec-mocks (3.2.0)
|
85
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
+
rspec-support (~> 3.2.0)
|
87
|
+
rspec-support (3.2.0)
|
88
|
+
safe_yaml (1.0.4)
|
89
|
+
sass (3.4.11)
|
90
|
+
slop (3.6.0)
|
91
|
+
timers (4.0.1)
|
92
|
+
hitimes
|
93
|
+
toml (0.1.2)
|
94
|
+
parslet (~> 1.5.0)
|
95
|
+
yajl-ruby (1.2.1)
|
96
|
+
|
97
|
+
PLATFORMS
|
98
|
+
ruby
|
99
|
+
|
100
|
+
DEPENDENCIES
|
101
|
+
fakefs
|
102
|
+
jekyll-nested-menu-generator!
|
103
|
+
nokogiri
|
104
|
+
pry
|
105
|
+
rspec
|
data/LICENSE.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2015, GovDelivery, Inc.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
3. Neither the name of GovDelivery nor the names of its contributors may be
|
15
|
+
used to endorse or promote products derived from this software without
|
16
|
+
specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
19
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/govdelivery/jekyll-nested-menu-generator.svg?branch=master)](https://travis-ci.org/govdelivery/jekyll-nested-menu-generator)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/jekyll-nested-menu-generator.svg)](http://badge.fury.io/rb/jekyll-nested-menu-generator)
|
3
|
+
|
4
|
+
jekyll-nested-menu-generator
|
5
|
+
=======================
|
6
|
+
|
7
|
+
Provides a tag that will generated a nested navigation menu for files contained
|
8
|
+
in a specified folder. Generated menus are cached during site build.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add the following to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'jekyll-nested-menu-generator'
|
15
|
+
|
16
|
+
and then execute:
|
17
|
+
|
18
|
+
bundle install
|
19
|
+
|
20
|
+
Or install it manually:
|
21
|
+
|
22
|
+
gem install jekyll-nested-menu-generator
|
23
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'jekyll-nested-menu-generator'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2015-02-04'
|
5
|
+
s.authors = ['GovDelivery']
|
6
|
+
s.email = 'support@govdelivery.com'
|
7
|
+
s.homepage = 'https://github.com/govdelivery/jekyll-nested-menu-generator'
|
8
|
+
s.license = 'BSD-3-Clause'
|
9
|
+
s.summary = 'Tag for generating a nested navigation menu.'
|
10
|
+
s.description = %q{Provides a tag that generates a nested navigation menu for
|
11
|
+
a specificed folder. Useful for automatically generating
|
12
|
+
a multilevel menu that mirrors your directory structure,
|
13
|
+
or generating a menu of generated pages.}
|
14
|
+
|
15
|
+
s.add_runtime_dependency 'jekyll'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($\)
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Jekyll
|
2
|
+
|
3
|
+
class NestedMenuTag < Liquid::Tag
|
4
|
+
|
5
|
+
def initialize(tag_name, menu_root, tokens)
|
6
|
+
@menu_root = menu_root.strip
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(context)
|
11
|
+
menu(context)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def menu(context)
|
16
|
+
site_data_key = "#{@menu_root}_menu_items"
|
17
|
+
root_string = "/#{@menu_root}"
|
18
|
+
if not context['site']['data'].include?(site_data_key)
|
19
|
+
menu_hash = {}
|
20
|
+
menu_items = ''
|
21
|
+
context['site']['pages'].find_all{|page| page.url.start_with?(root_string)}.each do |page|
|
22
|
+
path_parts = page.path.split('/')
|
23
|
+
path_parts.shift
|
24
|
+
menu_hash = build_menu_hash(page, path_parts, menu_hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
context['site']['data'][site_data_key] = build_menu_string(menu_hash)
|
28
|
+
end
|
29
|
+
|
30
|
+
context['site']['data'][site_data_key]
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_menu_hash(page, path_parts, menu_hash=nil)
|
34
|
+
if path_parts.empty?
|
35
|
+
return page
|
36
|
+
end
|
37
|
+
|
38
|
+
menu_hash = {} if menu_hash.nil?
|
39
|
+
path_part = path_parts.shift
|
40
|
+
|
41
|
+
menu_hash[path_part] = build_menu_hash(page, path_parts, menu_hash[path_part])
|
42
|
+
|
43
|
+
menu_hash
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_menu_string(menu_hash)
|
47
|
+
menu_string = ''
|
48
|
+
menu_hash.each do |dir_name, dir|
|
49
|
+
item_string_part = ''
|
50
|
+
|
51
|
+
# Seperate the child pages from other decendent pages
|
52
|
+
if dir.is_a?(Jekyll::Page)
|
53
|
+
dir_hash = {}
|
54
|
+
dir_hash[dir.name] = dir
|
55
|
+
dir = dir_hash
|
56
|
+
end
|
57
|
+
pages = dir.select{ |k, v| v.is_a?(Jekyll::Page) }
|
58
|
+
dir = dir.reject{ |k, v| v.is_a?(Jekyll::Page) }
|
59
|
+
|
60
|
+
pages.each do |file_name, page|
|
61
|
+
item_string_part << "<a href='#{page.url}'>#{page.data['title'].split('/').last}</a>"
|
62
|
+
end
|
63
|
+
|
64
|
+
if not dir.empty?
|
65
|
+
item_string_part << build_menu_string(dir)
|
66
|
+
end
|
67
|
+
|
68
|
+
menu_string << "<li>#{item_string_part}</li>"
|
69
|
+
end
|
70
|
+
"<ul>#{menu_string}</ul>"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
Liquid::Template.register_tag('nested_menu', Jekyll::NestedMenuTag)
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative './spec_helper.rb'
|
2
|
+
|
3
|
+
def test_content
|
4
|
+
content = <<EOF
|
5
|
+
---
|
6
|
+
title: Test!
|
7
|
+
---
|
8
|
+
|
9
|
+
I'm testing things
|
10
|
+
EOF
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'nested_menu', fakefs:true do
|
14
|
+
|
15
|
+
def setup_page(*args)
|
16
|
+
dir, file = args
|
17
|
+
dir, file = ['', dir] if file.nil?
|
18
|
+
@page = Page.new(@site, source_dir, dir, file)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
let(:page) { '{% nested_menu files %}' }
|
24
|
+
|
25
|
+
before(:all) do
|
26
|
+
FakeFS.activate!
|
27
|
+
@site = Jekyll::Site.new(Jekyll.configuration({
|
28
|
+
"source" => source_dir,
|
29
|
+
"destination" => dest_dir,
|
30
|
+
"skip_config_files" => true
|
31
|
+
}))
|
32
|
+
|
33
|
+
[
|
34
|
+
'files/one',
|
35
|
+
'files/two',
|
36
|
+
'files/three',
|
37
|
+
'files/one/a',
|
38
|
+
'files/one/b',
|
39
|
+
'content',
|
40
|
+
'images'
|
41
|
+
].each do |dir|
|
42
|
+
FileUtils.mkdir_p(File.join(source_dir, dir)) if not File.directory? File.join(source_dir, dir)
|
43
|
+
File.open(File.join(source_dir, dir, 'index.md'), 'w') { |f| f << test_content }
|
44
|
+
@site.pages << Jekyll::Page.new(@site, source_dir, dir, 'index.md')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:all) do
|
49
|
+
FakeFS.deactivate!
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'Yields a nested menu of items in the specificed folder' do
|
53
|
+
t = Liquid::Template.parse(page)
|
54
|
+
o = t.render!({'site' => {
|
55
|
+
'pages' => @site.pages,
|
56
|
+
'data' => {}
|
57
|
+
}})
|
58
|
+
|
59
|
+
o_obj = Nokogiri::XML.parse(o)
|
60
|
+
expect(o_obj.xpath('/ul')).not_to be_empty
|
61
|
+
expect(o_obj.xpath('/ul/li[1]/a[.="Test!"][@href="/files/one/index.html"]')).not_to be_empty
|
62
|
+
expect(o_obj.xpath('/ul/li[2]/a[.="Test!"][@href="/files/two/index.html"]')).not_to be_empty
|
63
|
+
expect(o_obj.xpath('/ul/li[3]/a[.="Test!"][@href="/files/three/index.html"]')).not_to be_empty
|
64
|
+
expect(o_obj.xpath('/ul/li[1]/ul/li[1]/a[.="Test!"][@href="/files/one/a/index.html"]')).not_to be_empty
|
65
|
+
expect(o_obj.xpath('/ul/li[1]/ul/li[2]/a[.="Test!"][@href="/files/one/b/index.html"]')).not_to be_empty
|
66
|
+
expect(o_obj.xpath('//a[@href="/content/index.html"]')).to be_empty
|
67
|
+
expect(o_obj.xpath('//a[@href="/images/index.html"]')).to be_empty
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
require 'rspec'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'fakefs/spec_helpers'
|
5
|
+
require_relative '../lib/jekyll-nested-menu-generator.rb'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.include FakeFS::SpecHelpers, fakefs:true
|
9
|
+
end
|
10
|
+
|
11
|
+
def dest_dir(*subdirs)
|
12
|
+
test_dir('dest', *subdirs)
|
13
|
+
end
|
14
|
+
|
15
|
+
def source_dir(*subdirs)
|
16
|
+
test_dir('source', *subdirs)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_dir(*subdirs)
|
20
|
+
File.join(File.dirname(__FILE__), *subdirs)
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-nested-menu-generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GovDelivery
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
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
|
+
description: |-
|
28
|
+
Provides a tag that generates a nested navigation menu for
|
29
|
+
a specificed folder. Useful for automatically generating
|
30
|
+
a multilevel menu that mirrors your directory structure,
|
31
|
+
or generating a menu of generated pages.
|
32
|
+
email: support@govdelivery.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- ".ruby-version"
|
38
|
+
- ".travis.yml"
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.md
|
42
|
+
- README.md
|
43
|
+
- jekyll-nested-menu-generator.gemspec
|
44
|
+
- lib/jekyll-nested-menu-generator.rb
|
45
|
+
- spec/nested_menu_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
homepage: https://github.com/govdelivery/jekyll-nested-menu-generator
|
48
|
+
licenses:
|
49
|
+
- BSD-3-Clause
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.4.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Tag for generating a nested navigation menu.
|
71
|
+
test_files: []
|