middleman-navtree 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- metadata +4 -24
- data/.gitignore +0 -5
- data/Gemfile +0 -19
- data/LICENSE.md +0 -21
- data/README.md +0 -87
- data/Rakefile +0 -14
- data/features/support/env.rb +0 -4
- data/lib/middleman-navtree.rb +0 -14
- data/lib/middleman-navtree/extension.rb +0 -144
- data/lib/middleman-navtree/helpers.rb +0 -137
- data/lib/middleman-navtree/version.rb +0 -5
- data/lib/middleman_extension.rb +0 -1
- data/middleman-navtree.gemspec +0 -26
- data/screenshots/directory-structure.png +0 -0
- data/screenshots/ex1-fulltree.png +0 -0
- data/screenshots/ex2-subtree.png +0 -0
- data/screenshots/ex3-subsubtree.png +0 -0
- data/screenshots/ex4-depthlimit.png +0 -0
- data/screenshots/ex5-subtree_and_depthlimit.png +0 -0
- data/screenshots/previous-next.png +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2IzYWNhM2EwMjY3YWI4ZmYxZGY5YTI1ZjVlYzBkOWU4ZTUyZDljNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGFkZmQ3YWQ0MzQzM2JiZjM4M2Y0ZDA4ZmNjYzBhMDkzZTllNWQxOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTg1YmYzMjAxODYyNmRlNGVjMmVhNTc3ODljODRmMWFlZGZkNWRmNzY5ZDdi
|
10
|
+
YTk2YTVlZTFkYjg3ZjJjYjJmNTI2NjhjMzBiNzA2NjQ3ZTYyZDdlMzYzZmUz
|
11
|
+
ZTcxYTE2ODljNjhlMmIwZTA5YzE0Y2ZmMTVkNGQzZWQ4NzcxMTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YThjNGZmYTcwMThiZTVmZjIzNDUxNWIxNjcxYjM5NzFkNTNmYzQ1NzY4NWVl
|
14
|
+
NDQ1YzFiN2JlMjU2OGFiZGJlZjVlM2QwZmM0Y2QxODU5M2I1N2E4MTE1N2E0
|
15
|
+
YzI1MDA2NjliOTQwOWI5NWJmN2Q0NmQ5YTBlMzRmMmI2MmU2Y2E=
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-navtree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Braun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -45,26 +45,7 @@ email:
|
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
|
-
files:
|
49
|
-
- .gitignore
|
50
|
-
- Gemfile
|
51
|
-
- LICENSE.md
|
52
|
-
- README.md
|
53
|
-
- Rakefile
|
54
|
-
- features/support/env.rb
|
55
|
-
- lib/middleman-navtree.rb
|
56
|
-
- lib/middleman-navtree/extension.rb
|
57
|
-
- lib/middleman-navtree/helpers.rb
|
58
|
-
- lib/middleman-navtree/version.rb
|
59
|
-
- lib/middleman_extension.rb
|
60
|
-
- middleman-navtree.gemspec
|
61
|
-
- screenshots/directory-structure.png
|
62
|
-
- screenshots/ex1-fulltree.png
|
63
|
-
- screenshots/ex2-subtree.png
|
64
|
-
- screenshots/ex3-subsubtree.png
|
65
|
-
- screenshots/ex4-depthlimit.png
|
66
|
-
- screenshots/ex5-subtree_and_depthlimit.png
|
67
|
-
- screenshots/previous-next.png
|
48
|
+
files: []
|
68
49
|
homepage: https://github.com/bryanbraun/middleman-navtree
|
69
50
|
licenses:
|
70
51
|
- MIT
|
@@ -89,6 +70,5 @@ rubygems_version: 2.2.2
|
|
89
70
|
signing_key:
|
90
71
|
specification_version: 4
|
91
72
|
summary: For building navigation trees with Middleman
|
92
|
-
test_files:
|
93
|
-
- features/support/env.rb
|
73
|
+
test_files: []
|
94
74
|
has_rdoc:
|
data/.gitignore
DELETED
data/Gemfile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# If you have OpenSSL installed, we recommend updating
|
2
|
-
# the following line to use "https"
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in middleman-navtree.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
group :development do
|
9
|
-
gem 'rake'
|
10
|
-
gem 'rdoc'
|
11
|
-
gem 'yard'
|
12
|
-
end
|
13
|
-
|
14
|
-
group :test do
|
15
|
-
gem 'cucumber'
|
16
|
-
gem 'fivemat'
|
17
|
-
gem 'aruba'
|
18
|
-
gem 'rspec'
|
19
|
-
end
|
data/LICENSE.md
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2014 Bryan Braun
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
# Middleman-NavTree
|
2
|
-
|
3
|
-
`middleman-navtree` is an extension for the Middleman static site generator that lets you generate navigation trees and menus based on your site structure.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'middleman-navtree'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle install
|
14
|
-
|
15
|
-
Activate the extension with default options by adding the following to middleman's `config.rb`:
|
16
|
-
|
17
|
-
activate :navtree
|
18
|
-
|
19
|
-
Alternatively, you can specify the options you want. Here's an example showing the explicit defaults:
|
20
|
-
|
21
|
-
activate :navtree do |options|
|
22
|
-
options.data_file = 'data/tree.yml' # The data file where our navtree is stored.
|
23
|
-
options.source_dir = 'source' # The `source` directory we want to represent in our nav tree.
|
24
|
-
options.ignore_files = ['sitemap.xml', 'robots.txt'] # An array of files we want to ignore when building our tree.
|
25
|
-
options.ignore_dir = ['assets'] # An array of directories we want to ignore when building our tree.
|
26
|
-
options.home_title = 'Home' # The default link title of the home page (located at "/"), if otherwise not detected.
|
27
|
-
options.promote_files = ['index.html.erb'] # Any files we might want to promote to the front of our navigation
|
28
|
-
options.ext_whitelist = [] # If you add extensions (like '.md') to this array, it builds a whitelist of filetypes for inclusion in the navtree.
|
29
|
-
end
|
30
|
-
|
31
|
-
## Usage Examples
|
32
|
-
|
33
|
-
When you activate the extension, a tree.yml file will be added to your `data` folder, mimicking your directory structure. Suppose the structure looks like this:
|
34
|
-
|
35
|
-
![Directory Structure](screenshots/directory-structure.png)
|
36
|
-
|
37
|
-
We can print the entire navigation tree to our template with the `tree_to_html` helper:
|
38
|
-
|
39
|
-
<ul><%= tree_to_html(data.tree) %></ul>
|
40
|
-
|
41
|
-
Here's the tree.yml file and the resulting rendered navtree (styled):
|
42
|
-
|
43
|
-
![Full tree styled](screenshots/ex1-fulltree.png)
|
44
|
-
|
45
|
-
`data.tree` refers to the contents of `/data/tree.yml` (see http://middlemanapp.com/advanced/local-data/ for more information about data files).
|
46
|
-
|
47
|
-
You can just as easily print subtrees at any level:
|
48
|
-
|
49
|
-
<ul><%= tree_to_html(data.tree['chapter-1']) %></ul>
|
50
|
-
|
51
|
-
![Subtree styled](screenshots/ex2-subtree.png)
|
52
|
-
|
53
|
-
<ul><%= tree_to_html(data.tree['chapter-1']['exercises']) %></ul>
|
54
|
-
|
55
|
-
![Subsubtree styled](screenshots/ex3-subsubtree.png)
|
56
|
-
|
57
|
-
A second paramter allows you to limit the depth of your trees and subtrees:
|
58
|
-
|
59
|
-
<ul><%= tree_to_html(data.tree, 2) %></ul>
|
60
|
-
|
61
|
-
![Full tree with depth limit styled](screenshots/ex4-depthlimit.png)
|
62
|
-
|
63
|
-
You can combine both techniques to print menus at any level, with a specific depth:
|
64
|
-
|
65
|
-
<ul><%= tree_to_html(data.tree['chapter-1'], 1) %></ul>
|
66
|
-
|
67
|
-
![Subtree with depth limit styled](screenshots/ex5-subtree_and_depthlimit.png)
|
68
|
-
|
69
|
-
Another helper in the gem allows you to add next/previous links for paginating
|
70
|
-
through the tree. For example:
|
71
|
-
|
72
|
-
<%= previous_link(data.tree) %> <%= next_link(data.tree) %>
|
73
|
-
|
74
|
-
![Styled next/previous links](screenshots/previous-next.png)
|
75
|
-
|
76
|
-
You can likewise limit pagination to a specific subtree:
|
77
|
-
|
78
|
-
<%= previous_link(data.tree['chapter-2']) %><%= next_link(data.tree['chapter-2']) %>
|
79
|
-
|
80
|
-
|
81
|
-
## Contributing
|
82
|
-
|
83
|
-
1. Fork the project
|
84
|
-
2. Create your feature branch (git checkout -b my-new-feature)
|
85
|
-
3. Commit your changes (git commit -am 'Add some feature')
|
86
|
-
4. Push to your github repository (git push origin my-new-feature)
|
87
|
-
5. Submit a Pull Request
|
data/Rakefile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler::GemHelper.install_tasks
|
3
|
-
|
4
|
-
require 'cucumber/rake/task'
|
5
|
-
|
6
|
-
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
7
|
-
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'rake/clean'
|
11
|
-
|
12
|
-
task :test => ['cucumber']
|
13
|
-
|
14
|
-
task :default => :test
|
data/features/support/env.rb
DELETED
data/lib/middleman-navtree.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# Require core library
|
2
|
-
require 'middleman-core'
|
3
|
-
require 'middleman-navtree/version'
|
4
|
-
|
5
|
-
# Register extensions which can be activated
|
6
|
-
# Make sure we have the version of Middleman we expect
|
7
|
-
# Name param may be omited, it will default to underscored
|
8
|
-
# version of class name
|
9
|
-
|
10
|
-
|
11
|
-
::Middleman::Extensions.register(:navtree) do
|
12
|
-
require "middleman-navtree/extension"
|
13
|
-
::Middleman::NavTree::NavTreeExtension
|
14
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'middleman-navtree/helpers'
|
2
|
-
|
3
|
-
module Middleman
|
4
|
-
module NavTree
|
5
|
-
|
6
|
-
# Extension namespace
|
7
|
-
# @todo: Test the extension against a vanilla Middleman install.
|
8
|
-
# @todo: Test the extension against a middleman-blog install.
|
9
|
-
class NavTreeExtension < ::Middleman::Extension
|
10
|
-
# All the options for this extension
|
11
|
-
option :source_dir, 'source', 'The directory our tree will begin at.'
|
12
|
-
option :data_file, 'data/tree.yml', 'The file we will write our directory tree to.'
|
13
|
-
option :ignore_files, ['sitemap.xml', 'robots.txt'], 'A list of filenames we want to ignore when building our tree.'
|
14
|
-
option :ignore_dir, ['assets'], 'A list of directory names we want to ignore when building our tree.'
|
15
|
-
option :home_title, 'Home', 'The default link title of the home page (located at "/"), if otherwise not detected.'
|
16
|
-
option :promote_files, ['index.html.erb'], 'A list of files you want to push to the front of the tree (if they exist).'
|
17
|
-
option :ext_whitelist, [], 'A whitelist of filename extensions (post-render) that we are allowing in our navtree. Example: [".html"]'
|
18
|
-
|
19
|
-
# Helpers for use within templates and layouts.
|
20
|
-
self.defined_helpers = [ ::Middleman::NavTree::Helpers ]
|
21
|
-
|
22
|
-
def initialize(app, options_hash={}, &block)
|
23
|
-
# Call super to build options from the options_hash
|
24
|
-
super
|
25
|
-
|
26
|
-
# Require libraries only when activated
|
27
|
-
require 'yaml'
|
28
|
-
require 'titleize'
|
29
|
-
|
30
|
-
@existing_promotes = []
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
def after_configuration
|
35
|
-
# Add the user's config directories to the "ignore_dir" option because
|
36
|
-
# these are all things we won't need printed in a NavTree.
|
37
|
-
options.ignore_dir << app.settings.js_dir
|
38
|
-
options.ignore_dir << app.settings.css_dir
|
39
|
-
options.ignore_dir << app.settings.fonts_dir
|
40
|
-
options.ignore_dir << app.settings.images_dir
|
41
|
-
options.ignore_dir << app.settings.helpers_dir
|
42
|
-
options.ignore_dir << app.settings.layouts_dir
|
43
|
-
options.ignore_dir << app.settings.partials_dir
|
44
|
-
|
45
|
-
# Build a hash out of our directory information
|
46
|
-
tree_hash = scan_directory(options.source_dir, options)
|
47
|
-
|
48
|
-
# Promote any promoted files to the beginning of our hash.
|
49
|
-
tree_hash = promote_files(tree_hash, options)
|
50
|
-
|
51
|
-
# Write our directory tree to file as YAML.
|
52
|
-
# @todo: This step doesn't rebuild during live-reload, which causes errors if you move files
|
53
|
-
# around during development. It may not be that hard to set up. Low priority though.
|
54
|
-
IO.write(options.data_file, YAML::dump(tree_hash))
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
# Method for storing the directory structure in a hash.
|
59
|
-
# @todo: the order of the data is defined by the order in the hash, and technically, ruby hashes
|
60
|
-
# are unordered. This may be more robust if I defined an ordered hash type similar to
|
61
|
-
# this one in Rails: http://apidock.com/rails/ActiveSupport/OrderedHash
|
62
|
-
def scan_directory(path, options, name=nil)
|
63
|
-
data = {}
|
64
|
-
Dir.foreach(path) do |filename|
|
65
|
-
|
66
|
-
# Check to see if we should skip this file. We skip invisible files
|
67
|
-
# (starts with "."), ignored files, and promoted files (which are
|
68
|
-
# handled later in the process).
|
69
|
-
next if (filename[0] == '.')
|
70
|
-
next if (filename == '..' || filename == '.')
|
71
|
-
next if options.ignore_files.include? filename
|
72
|
-
|
73
|
-
if options.promote_files.include? filename
|
74
|
-
original_path = path.sub(/^#{options.source_dir}/, '') + '/' + filename
|
75
|
-
@existing_promotes << original_path
|
76
|
-
next
|
77
|
-
end
|
78
|
-
|
79
|
-
full_path = File.join(path, filename)
|
80
|
-
if File.directory?(full_path)
|
81
|
-
# This item is a directory.
|
82
|
-
# Check to see if we should ignore this directory.
|
83
|
-
next if options.ignore_dir.include? filename
|
84
|
-
|
85
|
-
# Loop through the method again.
|
86
|
-
data.store(filename, scan_directory(full_path, options, filename))
|
87
|
-
else
|
88
|
-
|
89
|
-
# This item is a file.
|
90
|
-
if !options.ext_whitelist.empty?
|
91
|
-
# Skip any whitelisted extensions.
|
92
|
-
next unless options.ext_whitelist.include? File.extname(filename)
|
93
|
-
end
|
94
|
-
|
95
|
-
original_path = path.sub(/^#{options.source_dir}/, '') + '/' + filename
|
96
|
-
data.store(filename, original_path)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
return data
|
101
|
-
end
|
102
|
-
|
103
|
-
# Method for appending promoted files to the front of our source tree.
|
104
|
-
# @todo: Currently, options.promote_files only expects a filename, which means that
|
105
|
-
# if multiple files in different directories have the same filename, they
|
106
|
-
# will both be promoted, and one will not appear (due to the 'no-two-identical
|
107
|
-
# -indices-in-a-hash' rule).
|
108
|
-
# @todo: This system also assumes filenames only have a single extension,
|
109
|
-
# which may not be the case (like index.html.erb)
|
110
|
-
# @todo: Basically, this is not elegent at all.
|
111
|
-
def promote_files(tree_hash, options)
|
112
|
-
|
113
|
-
if @existing_promotes.any?
|
114
|
-
ordered_matches = []
|
115
|
-
|
116
|
-
# The purpose of this loop is to get my list of existing promotes
|
117
|
-
# in the order specified in the options array, so it can be promoted
|
118
|
-
# properly.
|
119
|
-
options.promote_files.each do |filename|
|
120
|
-
# Get filename without extension (index.md => index)
|
121
|
-
filename_without_ext = filename.chomp(File.extname(filename))
|
122
|
-
# Test against each existing_promote, and store matches
|
123
|
-
@existing_promotes.each do |pathname|
|
124
|
-
# Get another filename without extension from the pathname (/book/index.html => index)
|
125
|
-
pathname_without_ext = File.basename(pathname, ".*")
|
126
|
-
# Add matches to our ordered matches array.
|
127
|
-
if filename_without_ext == pathname_without_ext
|
128
|
-
ordered_matches << [filename, pathname]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
# Promote all files found in both the promotes list and the file structure. This is an array
|
133
|
-
# of arrays
|
134
|
-
ordered_matches.reverse.each do |match|
|
135
|
-
tree_hash = Hash[match[0], match[1]].merge!(tree_hash)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
return tree_hash
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
module Middleman
|
2
|
-
module NavTree
|
3
|
-
# NavTree-related helpers that are available to the Middleman application in +config.rb+ and in templates.
|
4
|
-
module Helpers
|
5
|
-
|
6
|
-
# A recursive helper for converting source tree data from into HTML
|
7
|
-
def tree_to_html(value, depth = Float::INFINITY, key = nil, level = 0)
|
8
|
-
html = ''
|
9
|
-
|
10
|
-
if value.is_a?(String)
|
11
|
-
# This is a child item (a file). Get the Sitemap resource for this file.
|
12
|
-
# note: sitemap.extensionless_path converts the path to its 'post-build' extension.
|
13
|
-
this_resource = sitemap.find_resource_by_path(sitemap.extensionless_path(value))
|
14
|
-
# Define string for active states.
|
15
|
-
active = this_resource == current_page ? 'active' : ''
|
16
|
-
title = discover_title(this_resource)
|
17
|
-
link = link_to(title, sitemap.extensionless_path(value))
|
18
|
-
html << "<li class='child #{active}'>#{link}</li>"
|
19
|
-
else
|
20
|
-
# This is a directory.
|
21
|
-
if key.nil?
|
22
|
-
# The first level is the source directory, so it has no key and needs no list item.
|
23
|
-
value.each do |newkey, child|
|
24
|
-
html << tree_to_html(child, depth, newkey, level + 1)
|
25
|
-
end
|
26
|
-
# Continue rendering deeper levels of the tree, unless restricted by depth.
|
27
|
-
elsif depth >= (level + 1)
|
28
|
-
# This directory has a key and should be listed in the page hieararcy with HTML.
|
29
|
-
dir_name = key
|
30
|
-
html << "<li class='parent'><span class='parent-label'>#{dir_name.gsub(/-/, ' ').gsub(/_/, ' ').titleize}</span>"
|
31
|
-
html << '<ul>'
|
32
|
-
|
33
|
-
# Loop through all the directory's contents.
|
34
|
-
value.each do |newkey, child|
|
35
|
-
html << tree_to_html(child, depth, newkey, level + 1)
|
36
|
-
end
|
37
|
-
html << '</ul>'
|
38
|
-
html << '</li>'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
return html
|
43
|
-
end
|
44
|
-
|
45
|
-
# Pagination helpers
|
46
|
-
# @todo: One potential future feature is previous/next links for paginating on a
|
47
|
-
# single level instead of a flattened tree. I don't need it but it seems pretty easy.
|
48
|
-
def previous_link(sourcetree)
|
49
|
-
pagelist = flatten_source_tree(sourcetree)
|
50
|
-
position = get_current_position_in_page_list(pagelist)
|
51
|
-
# Skip link generation if position is nil (meaning, the current page isn't in our
|
52
|
-
# pagination pagelist).
|
53
|
-
if position
|
54
|
-
prev_page = pagelist[position - 1]
|
55
|
-
options = {:class => "previous"}
|
56
|
-
unless first_page?(pagelist)
|
57
|
-
link_to("Previous", prev_page, options)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def next_link(sourcetree)
|
63
|
-
pagelist = flatten_source_tree(sourcetree)
|
64
|
-
position = get_current_position_in_page_list(pagelist)
|
65
|
-
# Skip link generation if position is nil (meaning, the current page isn't in our
|
66
|
-
# pagination pagelist).
|
67
|
-
if position
|
68
|
-
next_page = pagelist[position + 1]
|
69
|
-
options = {:class => "next"}
|
70
|
-
unless last_page?(pagelist)
|
71
|
-
link_to("Next", next_page, options)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Helper for use in pagination methods.
|
77
|
-
def first_page?(pagelist)
|
78
|
-
return true if get_current_position_in_page_list(pagelist) == 0
|
79
|
-
end
|
80
|
-
|
81
|
-
# Helper for use in pagination methods.
|
82
|
-
def last_page?(pagelist)
|
83
|
-
return true if pagelist[get_current_position_in_page_list(pagelist)] == pagelist[-1]
|
84
|
-
end
|
85
|
-
|
86
|
-
# Method to flatten the source tree, for use in pagination methods.
|
87
|
-
# Note, I could do this with a lot less code using Glob. I should refactor
|
88
|
-
# in the future. See http://stackoverflow.com/a/2370823/1154642.
|
89
|
-
def flatten_source_tree(value, k = [], level = 0, flat_tree = [])
|
90
|
-
|
91
|
-
if value.is_a?(String)
|
92
|
-
# This is a child item (a file).
|
93
|
-
flat_tree.push(sitemap.extensionless_path(value))
|
94
|
-
elsif value.is_a?(Hash)
|
95
|
-
# This is a parent item (a directory).
|
96
|
-
value.each do |key, child|
|
97
|
-
flatten_source_tree(child, key, level + 1, flat_tree)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
return flat_tree
|
102
|
-
end
|
103
|
-
|
104
|
-
# Helper for use in pagination methods.
|
105
|
-
def get_current_position_in_page_list(pagelist)
|
106
|
-
pagelist.each_with_index do |page_path, index|
|
107
|
-
if page_path == "/" + current_page.path
|
108
|
-
return index
|
109
|
-
end
|
110
|
-
end
|
111
|
-
# If we reach this line, the current page path wasn't in our page list and we'll
|
112
|
-
# return false so the link generation is skipped.
|
113
|
-
return FALSE
|
114
|
-
end
|
115
|
-
|
116
|
-
# Utility helper for getting the page title
|
117
|
-
# Based on this: http://forum.middlemanapp.com/t/using-heading-from-page-as-title/44/3
|
118
|
-
# 1) Use the title from frontmatter metadata, or
|
119
|
-
# 2) peek into the page to find the H1, or
|
120
|
-
# 3) Use the home_title option (if this is the home page--defaults to "Home"), or
|
121
|
-
# 4) fallback to a filename-based-title
|
122
|
-
def discover_title(page = current_page)
|
123
|
-
if page.data.title
|
124
|
-
return page.data.title # Frontmatter title
|
125
|
-
elsif page.url == '/'
|
126
|
-
return extensions[:navtree].options[:home_title]
|
127
|
-
elsif match = page.render({:layout => false}).match(/<h.+>(.*?)<\/h1>/)
|
128
|
-
return match[1] # H1 title
|
129
|
-
else
|
130
|
-
filename = page.url.split(/\//).last.titleize
|
131
|
-
return filename.chomp(File.extname(filename))
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
data/lib/middleman_extension.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'middleman-navtree'
|
data/middleman-navtree.gemspec
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = "middleman-navtree"
|
6
|
-
s.version = "0.1.3"
|
7
|
-
s.licenses = ['MIT']
|
8
|
-
s.date = Date.today.to_s
|
9
|
-
|
10
|
-
s.summary = "For building navigation trees with Middleman"
|
11
|
-
s.description = "This extension copies the site structure to tree.yml and provides helpers for printing parts of the tree in your middleman templates."
|
12
|
-
|
13
|
-
s.platform = Gem::Platform::RUBY
|
14
|
-
s.authors = ["Bryan Braun"]
|
15
|
-
s.email = ["bbraun7@gmail.com"]
|
16
|
-
s.homepage = "https://github.com/bryanbraun/middleman-navtree"
|
17
|
-
|
18
|
-
s.files = `git ls-files`.split("\n")
|
19
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
-
s.require_paths = ["lib"]
|
22
|
-
|
23
|
-
# The version of middleman-core this extension depends on.
|
24
|
-
s.add_runtime_dependency("middleman-core", ["~> 3.3"])
|
25
|
-
s.add_runtime_dependency("titleize", ["~> 1.3"])
|
26
|
-
end
|
Binary file
|
Binary file
|
data/screenshots/ex2-subtree.png
DELETED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|