middleman-listpages 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -6,8 +6,8 @@ ability to list the child pages of a given page.
|
|
6
6
|
# Install
|
7
7
|
|
8
8
|
Add `middleman-listpages` to your `Gemfile`
|
9
|
-
```
|
10
|
-
gem "middleman-listpages",
|
9
|
+
```ruby
|
10
|
+
gem "middleman-listpages", "~> 0.0.1"
|
11
11
|
```
|
12
12
|
|
13
13
|
Then open your `config.rb` and add:
|
@@ -21,16 +21,64 @@ To display all pages:
|
|
21
21
|
<%= list_pages %>
|
22
22
|
```
|
23
23
|
|
24
|
+
This will generate HTML like this (assuming "Apples" is the current page):
|
25
|
+
```html
|
26
|
+
<ul>
|
27
|
+
<li class='active'><a href="/apples/">Apples</a></li>
|
28
|
+
<li>
|
29
|
+
<a href="/oranges/">Oranges</a>
|
30
|
+
<ul>
|
31
|
+
<li><a href="/oranges/navel/">Navel Oranges</a></li>
|
32
|
+
<li><a href="/oranges/clementine/">Clementine Oranges</a></li>
|
33
|
+
</ul>
|
34
|
+
</li>
|
35
|
+
</ul>
|
36
|
+
```
|
37
|
+
|
24
38
|
To display all children of current page:
|
25
39
|
```erb
|
26
40
|
<%= list_pages current_page %>
|
27
41
|
```
|
28
42
|
|
29
|
-
|
43
|
+
You can use the `:depth` option to specify how many levels deep to display:
|
30
44
|
```erb
|
31
45
|
<%= list_pages current_page, :depth => 1 %>
|
32
46
|
```
|
33
47
|
|
48
|
+
If you want to use options when displaying the root page, pass `nil` as the
|
49
|
+
first agrument:
|
50
|
+
```erb
|
51
|
+
<%= list_pages nil, :depth => 1 %>
|
52
|
+
```
|
53
|
+
|
54
|
+
To display the root page as well:
|
55
|
+
```erb
|
56
|
+
<%= list_pages nil, :include_root => true %>
|
57
|
+
```
|
58
|
+
|
59
|
+
This will generate:
|
60
|
+
```html
|
61
|
+
<ul>
|
62
|
+
<li><a href="/index.html">Index Page Title</a>
|
63
|
+
<li class='active'><a href="/apples/">Apples</a></li>
|
64
|
+
<li>
|
65
|
+
<a href="/oranges/">Oranges</a>
|
66
|
+
<ul>
|
67
|
+
<li><a href="/oranges/navel/">Navel Oranges</a></li>
|
68
|
+
<li><a href="/oranges/clementine/">Clementine Oranges</a></li>
|
69
|
+
</ul>
|
70
|
+
</li>
|
71
|
+
</ul>
|
72
|
+
```
|
73
|
+
|
74
|
+
This will generate HTML like this (assuming "Apples" is the current page):
|
75
|
+
```html
|
76
|
+
<ul>
|
77
|
+
<li class='active'><a href="/apples/">Apples</a></li>
|
78
|
+
<li><a href="/oranges/">Oranges</a></li>
|
79
|
+
</ul>
|
80
|
+
```
|
81
|
+
|
34
82
|
To display all children of a specific page:
|
35
83
|
```erb
|
36
84
|
<%= list_pages sitemap.find_resource_by_destination_path('index.html') %>
|
@@ -43,15 +91,11 @@ Since you might have sub LIs inside that, you'll probably want to reset the CSS
|
|
43
91
|
of the inner LIs via something like this:
|
44
92
|
|
45
93
|
```css
|
46
|
-
li {
|
47
|
-
|
94
|
+
li, li.active li {
|
95
|
+
font-weight: normal;
|
48
96
|
}
|
49
97
|
|
50
98
|
li.active {
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
li.active li {
|
55
|
-
font-weight: normal;
|
99
|
+
font-weight: bold;
|
56
100
|
}
|
57
101
|
```
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
1
3
|
module Middleman
|
2
4
|
module ListPages
|
3
5
|
class << self
|
@@ -16,26 +18,38 @@ module Middleman
|
|
16
18
|
end
|
17
19
|
|
18
20
|
page ||= sitemap.find_resource_by_destination_path('index.html')
|
19
|
-
children = filter_children(page.children, opts
|
21
|
+
children = filter_children(page.children, opts.slice(:extensions))
|
20
22
|
|
21
23
|
if children.empty?
|
22
24
|
""
|
23
25
|
else
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
child_html = children.map do |child|
|
27
|
+
my_opts = opts.dup
|
28
|
+
my_opts[:current_depth] += 1
|
29
|
+
sub_list = list_pages(child, my_opts)
|
30
|
+
li_for(child, sub_list, my_opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
render('_list', binding)
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
30
|
-
def li_for(page, opts={})
|
31
|
-
child_html = list_pages(page, opts)
|
37
|
+
def li_for(page, sub_list=nil, opts={})
|
32
38
|
active = (page.path == current_page.path)
|
33
39
|
|
34
|
-
|
40
|
+
render('_list_item', binding)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def render(path, bound)
|
46
|
+
full_path = File.join(File.dirname(__FILE__), "#{path}.erb")
|
47
|
+
template = ERB.new(File.read full_path)
|
48
|
+
template.result bound
|
35
49
|
end
|
36
50
|
|
37
|
-
def filter_children(children,
|
38
|
-
extensions
|
51
|
+
def filter_children(children, opts=nil)
|
52
|
+
extensions = opts[:extensions] || ".html"
|
39
53
|
extensions = Array(extensions)
|
40
54
|
|
41
55
|
children.reject { |p| p.data.title.nil? }.select do |p|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-listpages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -41,6 +41,8 @@ files:
|
|
41
41
|
- features/.gitkeep
|
42
42
|
- fixtures/.gitkeep
|
43
43
|
- lib/middleman-listpages.rb
|
44
|
+
- lib/middleman-listpages/_list.erb
|
45
|
+
- lib/middleman-listpages/_list_item.erb
|
44
46
|
- lib/middleman-listpages/extension.rb
|
45
47
|
- lib/middleman-listpages/version.rb
|
46
48
|
- lib/middleman_extension.rb
|
@@ -59,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
61
|
version: '0'
|
60
62
|
segments:
|
61
63
|
- 0
|
62
|
-
hash:
|
64
|
+
hash: 4217439097059215008
|
63
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
66
|
none: false
|
65
67
|
requirements:
|
@@ -68,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
70
|
version: '0'
|
69
71
|
segments:
|
70
72
|
- 0
|
71
|
-
hash:
|
73
|
+
hash: 4217439097059215008
|
72
74
|
requirements: []
|
73
75
|
rubyforge_project: middleman-listpages
|
74
76
|
rubygems_version: 1.8.23
|