jekyll-menus 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/Gemfile +6 -0
- data/lib/jekyll-menus.rb +5 -0
- data/lib/jekyll/menus.rb +188 -0
- data/lib/jekyll/menus/drops.rb +13 -0
- data/lib/jekyll/menus/drops/all.rb +51 -0
- data/lib/jekyll/menus/drops/item.rb +72 -0
- data/lib/jekyll/menus/drops/menu.rb +50 -0
- data/lib/jekyll/menus/hook.rb +15 -0
- data/lib/jekyll/menus/utils.rb +24 -0
- data/lib/jekyll/menus/version.rb +9 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 965850706d2242ce29e43c7932c2d654b95289bb
|
4
|
+
data.tar.gz: ad2d2693926535f499cfb5fcb021a459054aca14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e653e6f926258c2ac86b0f41a9bf157b9072b9c418f037a58627ed983c73d70566dab4613f65fdc8eabba0923ef5d38f82df805c989b689b6ea2623a06f4ddcc
|
7
|
+
data.tar.gz: fbade891036ee15a967c9f3774037827f5425fd84360a69552db32e6e8cf9e9456934672cfe0034f0dace4fcca69c787e445cd96c91d72ef169bbce2c49a2899
|
data/Gemfile
ADDED
data/lib/jekyll-menus.rb
ADDED
data/lib/jekyll/menus.rb
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2015 Forestry.io - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class Menus
|
7
|
+
autoload :Utils, "jekyll/menus/utils"
|
8
|
+
autoload :Drops, "jekyll/menus/drops"
|
9
|
+
|
10
|
+
def initialize(site)
|
11
|
+
@site = site
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
|
16
|
+
def to_liquid_drop
|
17
|
+
Drops::All.new(Utils.deep_merge(
|
18
|
+
_config_menus, _page_menus
|
19
|
+
))
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
|
24
|
+
def _config_menus
|
25
|
+
mns = [@site.data["menu"], @site.data["menus"]]
|
26
|
+
out = {}; mns.compact.each do |menus|
|
27
|
+
menus.each do |key, menu|
|
28
|
+
if menu.is_a?(Hash) || menu.is_a?(Array)
|
29
|
+
(menu = [menu].flatten).each do |item|
|
30
|
+
_validate_config_menu_item(
|
31
|
+
item
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
else
|
36
|
+
_throw_invalid_menu_entry(
|
37
|
+
menu
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
out = Utils.deep_merge(out, {
|
42
|
+
key => menu
|
43
|
+
})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
out
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
|
52
|
+
def _page_menus
|
53
|
+
out = {}
|
54
|
+
|
55
|
+
@site.pages.select { |p| p.data.keys.grep(/menus?/).size > 0 }.each_with_object({}) do |page|
|
56
|
+
[page.data["menus"], page.data["menu"]].flatten.compact.map do |menu|
|
57
|
+
|
58
|
+
# --
|
59
|
+
# menu: key
|
60
|
+
# menu:
|
61
|
+
# - key1
|
62
|
+
# - key2
|
63
|
+
# --
|
64
|
+
|
65
|
+
if menu.is_a?(Array) || menu.is_a?(String)
|
66
|
+
_simple_front_matter_menu(menu, {
|
67
|
+
:mergeable => out, :page => page
|
68
|
+
})
|
69
|
+
|
70
|
+
#
|
71
|
+
|
72
|
+
elsif menu.is_a?(Hash)
|
73
|
+
menu.each do |key, item|
|
74
|
+
out[key] ||= []
|
75
|
+
|
76
|
+
# --
|
77
|
+
# menu:
|
78
|
+
# key: identifier
|
79
|
+
# --
|
80
|
+
|
81
|
+
if item.is_a?(String)
|
82
|
+
out[key] << _fill_front_matter_menu({ "identifier" => item }, {
|
83
|
+
:page => page
|
84
|
+
})
|
85
|
+
|
86
|
+
# --
|
87
|
+
# menu:
|
88
|
+
# key:
|
89
|
+
# url: /url
|
90
|
+
# --
|
91
|
+
|
92
|
+
elsif item.is_a?(Hash)
|
93
|
+
out[key] << _fill_front_matter_menu(item, {
|
94
|
+
:page => page
|
95
|
+
})
|
96
|
+
|
97
|
+
# --
|
98
|
+
# menu:
|
99
|
+
# key:
|
100
|
+
# - url: /url
|
101
|
+
# --
|
102
|
+
|
103
|
+
else
|
104
|
+
_throw_invalid_menu_entry(
|
105
|
+
item
|
106
|
+
)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# --
|
111
|
+
# menu:
|
112
|
+
# key: 3
|
113
|
+
# --
|
114
|
+
|
115
|
+
else
|
116
|
+
_throw_invalid_menu_entry(
|
117
|
+
menu
|
118
|
+
)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
out
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
|
128
|
+
private
|
129
|
+
def _simple_front_matter_menu(menu, mergeable: nil, page: nil)
|
130
|
+
if menu.is_a?(Array)
|
131
|
+
then menu.each do |item|
|
132
|
+
if !item.is_a?(String)
|
133
|
+
_throw_invalid_menu_entry(
|
134
|
+
item
|
135
|
+
)
|
136
|
+
|
137
|
+
else
|
138
|
+
_simple_front_matter_menu(item, {
|
139
|
+
:mergeable => mergeable, :page => page
|
140
|
+
})
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
else
|
145
|
+
mergeable[menu] ||= []
|
146
|
+
mergeable[menu] << _fill_front_matter_menu(nil, {
|
147
|
+
:page => page
|
148
|
+
})
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
#
|
153
|
+
|
154
|
+
private
|
155
|
+
def _fill_front_matter_menu(val, page: nil)
|
156
|
+
raise ArgumentError, "Kwd 'page' is required." unless page
|
157
|
+
val ||= {}
|
158
|
+
|
159
|
+
val["url"] ||= page.url
|
160
|
+
val["title"] ||= page.data["title"]
|
161
|
+
val["identifier"] ||= File.basename(page.name, page.ext)
|
162
|
+
val["weight"] ||= -1
|
163
|
+
val
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
|
168
|
+
private
|
169
|
+
def _validate_config_menu_item(item)
|
170
|
+
unless item.is_a?(Hash) && item.values_at("url", "title", "identifier").compact.size == 3
|
171
|
+
_throw_invalid_menu_entry(
|
172
|
+
item
|
173
|
+
)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
#
|
178
|
+
|
179
|
+
private
|
180
|
+
def _throw_invalid_menu_entry(data)
|
181
|
+
raise RuntimeError, "Invalid menu item given: #{
|
182
|
+
data.inspect
|
183
|
+
}"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
require "jekyll/menus/hook"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2015 Forestry.io - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class Menus
|
7
|
+
module Drops
|
8
|
+
autoload :Menu, "jekyll/menus/drops/menu"
|
9
|
+
autoload :All, "jekyll/menus/drops/all"
|
10
|
+
autoload :Item, "jekyll/menus/drops/item"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2015 Forestry.io - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class Menus
|
7
|
+
module Drops
|
8
|
+
class All < Liquid::Drop
|
9
|
+
def initialize(menus)
|
10
|
+
@menus = menus
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
|
15
|
+
def find
|
16
|
+
to_a.find do |menu|
|
17
|
+
yield menu
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
|
23
|
+
def to_a
|
24
|
+
@menus.keys.map do |identifier|
|
25
|
+
self[
|
26
|
+
identifier
|
27
|
+
]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
|
33
|
+
def each
|
34
|
+
to_a.each do |drop|
|
35
|
+
yield drop
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
|
41
|
+
def [](key)
|
42
|
+
if @menus.key?(key)
|
43
|
+
then Menu.new(@menus[key],
|
44
|
+
key, self
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2015 Forestry.io - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class Menus
|
7
|
+
module Drops
|
8
|
+
class Item < Liquid::Drop
|
9
|
+
def initialize(item, parent)
|
10
|
+
@parent = parent
|
11
|
+
@item =
|
12
|
+
item
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
|
17
|
+
def children
|
18
|
+
out = @parent.find { |menu| menu.identifier == @item["identifier"] }
|
19
|
+
|
20
|
+
if out
|
21
|
+
return out.to_a
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
|
27
|
+
def url
|
28
|
+
@item[
|
29
|
+
"url"
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
|
35
|
+
def title
|
36
|
+
@item[
|
37
|
+
"title"
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
|
43
|
+
def identifier
|
44
|
+
@item[
|
45
|
+
"identifier"
|
46
|
+
]
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
|
51
|
+
def weight
|
52
|
+
@item[
|
53
|
+
"weight"
|
54
|
+
]
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
|
59
|
+
def method_missing(method, *args)
|
60
|
+
if args.size == 0 && @item.has_key?(method.to_s)
|
61
|
+
return @item[
|
62
|
+
method.to_s
|
63
|
+
]
|
64
|
+
|
65
|
+
else
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2015 Forestry.io - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class Menus
|
7
|
+
module Drops
|
8
|
+
class Menu < Liquid::Drop
|
9
|
+
attr_reader :parent, :identifier, :menu
|
10
|
+
def initialize(menu, identifier, parent)
|
11
|
+
@parent = parent
|
12
|
+
@identifier = identifier
|
13
|
+
@menu = menu
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
|
18
|
+
def find
|
19
|
+
to_a.find do |item|
|
20
|
+
yield item
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
|
26
|
+
def select
|
27
|
+
to_a.select do |item|
|
28
|
+
yield item
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
|
34
|
+
def to_a
|
35
|
+
@menu.map { |item| Item.new(item, parent) }.sort_by(
|
36
|
+
&:weight
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
|
42
|
+
def each
|
43
|
+
to_a.each do |drop|
|
44
|
+
yield drop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2015 Forestry.io - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Drops
|
7
|
+
class SiteDrop
|
8
|
+
attr_accessor :menus
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Jekyll::Hooks.register :site, :pre_render do |site, payload|
|
14
|
+
payload.site.menus = Jekyll::Menus.new(site).to_liquid_drop
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2015 Forestry.io - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
class Menus
|
7
|
+
module Utils module_function
|
8
|
+
def deep_merge(old, _new)
|
9
|
+
return old | _new if old.is_a?(Array)
|
10
|
+
|
11
|
+
old.merge(_new) do |_, o, n|
|
12
|
+
(o.is_a?(Hash) && n.is_a?(Hash)) || (o.is_a?(Array) &&
|
13
|
+
n.is_a?(Array)) ? deep_merge(o, n) : n
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def deep_merge!(old, _new)
|
18
|
+
old.replace(deep_merge(
|
19
|
+
old, _new
|
20
|
+
))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-menus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jordon Bedwell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-14 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: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '4'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '4'
|
47
|
+
description: Menus (site navigation) for your Jekyll website
|
48
|
+
email:
|
49
|
+
- jordon@envygeeks.io
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- Gemfile
|
55
|
+
- lib/jekyll-menus.rb
|
56
|
+
- lib/jekyll/menus.rb
|
57
|
+
- lib/jekyll/menus/drops.rb
|
58
|
+
- lib/jekyll/menus/drops/all.rb
|
59
|
+
- lib/jekyll/menus/drops/item.rb
|
60
|
+
- lib/jekyll/menus/drops/menu.rb
|
61
|
+
- lib/jekyll/menus/hook.rb
|
62
|
+
- lib/jekyll/menus/utils.rb
|
63
|
+
- lib/jekyll/menus/version.rb
|
64
|
+
homepage: http://github.com/forestryio/jekyll-menus/
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.1.0
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.5.1
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Menus (navigation) for your very own Jekyll website.
|
88
|
+
test_files: []
|