middleman-navtree 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +5 -0
- data/Gemfile +19 -0
- data/LICENSE.md +21 -0
- data/README.md +86 -0
- data/Rakefile +14 -0
- data/features/support/env.rb +4 -0
- data/lib/middleman-navtree.rb +14 -0
- data/lib/middleman-navtree/extension.rb +144 -0
- data/lib/middleman-navtree/helpers.rb +131 -0
- data/lib/middleman-navtree/version.rb +5 -0
- data/lib/middleman_extension.rb +1 -0
- data/middleman-navtree.gemspec +26 -0
- 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
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjU3OWMxZWFiNjE2ZGU5ZmU1Yjc3NzY2NGY1MGZjMTgwMGQ5NGU3YQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Y2M0Y2MzZTE1MzZjYjhiYWNkM2MwNGQwZDc5YTk0YTgxN2EzNDA0OQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTA1ZGZjMzMyYjQ1MDJhOTY1NjBkYzQ0NTU2YWY5NmIxOGFjNDM5ZGRlMDg5
|
10
|
+
NjkxMDAzN2VjZDk0MjRlNWZmMDE1MWVjNTliNzI4YjU1YTJiMzhiZmVmNWE0
|
11
|
+
ZTZhOWM1MTczMjBiZDM3MDY4NGRiMDdjMjk4MjhmZTFlM2RhNTA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTBjODk0YTNhODNjMWVjZjU0YmY2NWEzMWQzN2JjOWYwMjA0OTYwNTU3MjJm
|
14
|
+
Mjg1OThlMjVlZjM5ZDFhZGIyMWUzNTUzYmU4NjllY2RlMmZjMDE5ZGU5MWMw
|
15
|
+
YzIwYjNmZWE1MjM2MTViNWRjYmZiY2E3NDg4NzMyYWY5MTAyNmY=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
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
ADDED
@@ -0,0 +1,21 @@
|
|
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
ADDED
@@ -0,0 +1,86 @@
|
|
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.promote_files = ['index.html.erb'] # Any files we might want to promote to the front of our navigation
|
27
|
+
options.ext_whitelist = [] # If you add extensions (like '.md') to this array, it builds a whitelist of filetypes for inclusion in the navtree.
|
28
|
+
end
|
29
|
+
|
30
|
+
## Usage Examples
|
31
|
+
|
32
|
+
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:
|
33
|
+
|
34
|
+
![Directory Structure](screenshots/directory-structure.png)
|
35
|
+
|
36
|
+
We can print the entire navigation tree to our template with the `tree_to_html` helper:
|
37
|
+
|
38
|
+
<ul><%= tree_to_html(data.tree) %></ul>
|
39
|
+
|
40
|
+
Here's the tree.yml file and the resulting rendered navtree (styled):
|
41
|
+
|
42
|
+
![Full tree styled](screenshots/ex1-fulltree.png)
|
43
|
+
|
44
|
+
`data.tree` refers to the contents of `/data/tree.yml` (see http://middlemanapp.com/advanced/local-data/ for more information about data files).
|
45
|
+
|
46
|
+
You can just as easily print subtrees at any level:
|
47
|
+
|
48
|
+
<ul><%= tree_to_html(data.tree['chapter-1']) %></ul>
|
49
|
+
|
50
|
+
![Subtree styled](screenshots/ex2-subtree.png)
|
51
|
+
|
52
|
+
<ul><%= tree_to_html(data.tree['chapter-1']['exercises']) %></ul>
|
53
|
+
|
54
|
+
![Subsubtree styled](screenshots/ex3-subsubtree.png)
|
55
|
+
|
56
|
+
A second paramter allows you to limit the depth of your trees and subtrees:
|
57
|
+
|
58
|
+
<ul><%= tree_to_html(data.tree, 2) %></ul>
|
59
|
+
|
60
|
+
![Full tree with depth limit styled](screenshots/ex4-depthlimit.png)
|
61
|
+
|
62
|
+
You can combine both techniques to print menus at any level, with a specific depth:
|
63
|
+
|
64
|
+
<ul><%= tree_to_html(data.tree['chapter-1'], 1) %></ul>
|
65
|
+
|
66
|
+
![Subtree with depth limit styled](screenshots/ex5-subtree_and_depthlimit.png)
|
67
|
+
|
68
|
+
Another helper in the gem allows you to add next/previous links for paginating
|
69
|
+
through the tree. For example:
|
70
|
+
|
71
|
+
<%= previous_link(data.tree) %> <%= next_link(data.tree) %>
|
72
|
+
|
73
|
+
![Styled next/previous links](screenshots/previous-next.png)
|
74
|
+
|
75
|
+
You can likewise limit pagination to a specific subtree:
|
76
|
+
|
77
|
+
<%= previous_link(data.tree['chapter-2']) %><%= next_link(data.tree['chapter-2']) %>
|
78
|
+
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
1. Fork the project
|
83
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
84
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
85
|
+
4. Push to your github repository (git push origin my-new-feature)
|
86
|
+
5. Submit a Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,144 @@
|
|
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 :promote_files, ['index.html.erb'], 'A list of files you want to push to the front of the tree (if they exist).'
|
16
|
+
option :ext_whitelist, [], 'A whitelist of filename extensions (post-render) that we are allowing in our navtree. Example: [".html"]'
|
17
|
+
|
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(/^source/, '') + '/' + 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(/^source/, '') + '/' + 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
|
@@ -0,0 +1,131 @@
|
|
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
|
+
this_resource = sitemap.find_resource_by_path(sitemap.extensionless_path(value))
|
13
|
+
# Define string for active states.
|
14
|
+
active = this_resource == current_page ? 'active' : ''
|
15
|
+
title = discover_title(this_resource)
|
16
|
+
link = link_to(title, this_resource.url)
|
17
|
+
html << "<li class='child #{active}'>#{link}</li>"
|
18
|
+
else
|
19
|
+
# This is a directory.
|
20
|
+
if key.nil?
|
21
|
+
# The first level is the source directory, so it has no key and needs no list item.
|
22
|
+
value.each do |newkey, child|
|
23
|
+
html << tree_to_html(child, depth, newkey, level + 1)
|
24
|
+
end
|
25
|
+
# Continue rendering deeper levels of the tree, unless restricted by depth.
|
26
|
+
elsif depth >= (level + 1)
|
27
|
+
# This directory has a key and should be listed in the page hieararcy with HTML.
|
28
|
+
dir_name = key
|
29
|
+
html << "<li class='parent'><span class='parent-label'>#{dir_name.gsub(/-/, ' ').gsub(/_/, ' ').titleize}</span>"
|
30
|
+
html << '<ul>'
|
31
|
+
|
32
|
+
# Loop through all the directory's contents.
|
33
|
+
value.each do |newkey, child|
|
34
|
+
html << tree_to_html(child, depth, newkey, level + 1)
|
35
|
+
end
|
36
|
+
html << '</ul>'
|
37
|
+
html << '</li>'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
return html
|
42
|
+
end
|
43
|
+
|
44
|
+
# Pagination helpers
|
45
|
+
# @todo: One potential future feature is previous/next links for paginating on a
|
46
|
+
# single level instead of a flattened tree. I don't need it but it seems pretty easy.
|
47
|
+
def previous_link(sourcetree)
|
48
|
+
pagelist = flatten_source_tree(sourcetree)
|
49
|
+
position = get_current_position_in_page_list(pagelist)
|
50
|
+
# Skip link generation if position is nil (meaning, the current page isn't in our
|
51
|
+
# pagination pagelist).
|
52
|
+
if position
|
53
|
+
prev_page = pagelist[position - 1]
|
54
|
+
options = {:class => "previous"}
|
55
|
+
unless first_page?(pagelist)
|
56
|
+
link_to("Previous", prev_page, options)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def next_link(sourcetree)
|
62
|
+
pagelist = flatten_source_tree(sourcetree)
|
63
|
+
position = get_current_position_in_page_list(pagelist)
|
64
|
+
# Skip link generation if position is nil (meaning, the current page isn't in our
|
65
|
+
# pagination pagelist).
|
66
|
+
if position
|
67
|
+
next_page = pagelist[position + 1]
|
68
|
+
options = {:class => "next"}
|
69
|
+
unless last_page?(pagelist)
|
70
|
+
link_to("Next", next_page, options)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Helper for use in pagination methods.
|
76
|
+
def first_page?(pagelist)
|
77
|
+
return true if get_current_position_in_page_list(pagelist) == 0
|
78
|
+
end
|
79
|
+
|
80
|
+
# Helper for use in pagination methods.
|
81
|
+
def last_page?(pagelist)
|
82
|
+
return true if pagelist[get_current_position_in_page_list(pagelist)] == pagelist[-1]
|
83
|
+
end
|
84
|
+
|
85
|
+
# Method to flatten the source tree, for use in pagination methods.
|
86
|
+
def flatten_source_tree(value, k = [], level = 0, flat_tree = [])
|
87
|
+
|
88
|
+
if value.is_a?(String)
|
89
|
+
# This is a child item (a file).
|
90
|
+
flat_tree.push(sitemap.extensionless_path(value))
|
91
|
+
elsif value.is_a?(Hash)
|
92
|
+
# This is a parent item (a directory).
|
93
|
+
value.each do |key, child|
|
94
|
+
flatten_source_tree(child, key, level + 1, flat_tree)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
return flat_tree
|
99
|
+
end
|
100
|
+
|
101
|
+
# Helper for use in pagination methods.
|
102
|
+
def get_current_position_in_page_list(pagelist)
|
103
|
+
pagelist.each_with_index do |page_path, index|
|
104
|
+
if page_path == "/" + current_page.path
|
105
|
+
return index
|
106
|
+
end
|
107
|
+
end
|
108
|
+
# If we reach this line, the current page path wasn't in our page list and we'll
|
109
|
+
# return false so the link generation is skipped.
|
110
|
+
return FALSE
|
111
|
+
end
|
112
|
+
|
113
|
+
# Utility helper for getting the page title
|
114
|
+
# Based on this: http://forum.middlemanapp.com/t/using-heading-from-page-as-title/44/3
|
115
|
+
# 1) Use the title from frontmatter metadata, or
|
116
|
+
# 2) peek into the page to find the H1, or
|
117
|
+
# 3) fallback to a filename-based-title
|
118
|
+
def discover_title(page = current_page)
|
119
|
+
if page.data.title
|
120
|
+
return page.data.title # Frontmatter title
|
121
|
+
elsif match = page.render({:layout => false}).match(/<h.+>(.*?)<\/h1>/)
|
122
|
+
return match[1]
|
123
|
+
else
|
124
|
+
filename = page.url.split(/\//).last.titleize
|
125
|
+
return filename.chomp(File.extname(filename))
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'middleman-navtree'
|
@@ -0,0 +1,26 @@
|
|
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.1"
|
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
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-navtree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryan Braun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: titleize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
description: This extension copies the site structure to tree.yml and provides helpers
|
42
|
+
for printing parts of the tree in your middleman templates.
|
43
|
+
email:
|
44
|
+
- bbraun7@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
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
|
68
|
+
homepage: https://github.com/bryanbraun/middleman-navtree
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.2.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: For building navigation trees with Middleman
|
92
|
+
test_files:
|
93
|
+
- features/support/env.rb
|
94
|
+
has_rdoc:
|