nanoc-toolbox 0.0.2 → 0.0.3
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/.gitignore +1 -0
- data/CHANGELOG.md +10 -1
- data/Gemfile.lock +14 -1
- data/README.md +8 -3
- data/lib/nanoc/toolbox/filters/html_tidy.rb +21 -0
- data/lib/nanoc/toolbox/filters.rb +6 -0
- data/lib/nanoc/toolbox/helpers/gravatar.rb +143 -0
- data/lib/nanoc/toolbox/helpers/html_tag.rb +47 -0
- data/lib/nanoc/toolbox/helpers/navigation.rb +97 -101
- data/lib/nanoc/toolbox/helpers.rb +3 -0
- data/lib/nanoc/toolbox/version.rb +12 -1
- data/lib/nanoc/toolbox.rb +8 -1
- data/nanoc-toolbox.gemspec +2 -0
- data/spec/filters/html_tidy_spec.rb +24 -0
- data/spec/helpers/gravatar_spec.rb +85 -0
- data/spec/helpers/html_tag_spec.rb +24 -0
- data/spec/helpers/navigation_spec.rb +81 -0
- data/spec/spec_helper.rb +11 -0
- metadata +44 -25
- data/doc/Nanoc/Toolbox/Helpers/Navigation.html +0 -999
- data/doc/Nanoc/Toolbox/Helpers.html +0 -93
- data/doc/Nanoc/Toolbox.html +0 -105
- data/doc/Nanoc.html +0 -93
- data/doc/_index.html +0 -137
- data/doc/class_list.html +0 -36
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -53
- data/doc/css/style.css +0 -310
- data/doc/file.CHANGELOG.html +0 -70
- data/doc/file.LICENSE.html +0 -77
- data/doc/file.README.html +0 -73
- data/doc/file_list.html +0 -44
- data/doc/frames.html +0 -13
- data/doc/index.html +0 -73
- data/doc/js/app.js +0 -203
- data/doc/js/full_list.js +0 -149
- data/doc/js/jquery.js +0 -154
- data/doc/method_list.html +0 -67
- data/doc/top-level-namespace.html +0 -88
@@ -1,5 +1,16 @@
|
|
1
1
|
module Nanoc
|
2
2
|
module Toolbox
|
3
|
-
|
3
|
+
# Holds information about library version.
|
4
|
+
module Version
|
5
|
+
MAJOR = 0
|
6
|
+
MINOR = 0
|
7
|
+
PATCH = 3
|
8
|
+
BUILD = nil
|
9
|
+
|
10
|
+
STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
|
11
|
+
end
|
12
|
+
|
13
|
+
# The current library version.
|
14
|
+
VERSION = Version::STRING
|
4
15
|
end
|
5
16
|
end
|
data/lib/nanoc/toolbox.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
+
require 'nanoc3'
|
1
2
|
require 'nanoc/toolbox/version'
|
2
3
|
require 'nanoc/toolbox/helpers'
|
4
|
+
require 'nanoc/toolbox/filters'
|
5
|
+
|
6
|
+
# The namescope of the project
|
3
7
|
module Nanoc
|
8
|
+
|
9
|
+
# The nanoc-toolbox is a collection of filters and helpers
|
10
|
+
# for the static site generator tool nanoc
|
4
11
|
module Toolbox
|
5
|
-
# Your code goes here...
|
6
12
|
end
|
13
|
+
|
7
14
|
end
|
data/nanoc-toolbox.gemspec
CHANGED
@@ -15,8 +15,10 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.required_rubygems_version = ">= 1.3.6"
|
16
16
|
|
17
17
|
s.add_dependency "nanoc", ">= 3.1.6"
|
18
|
+
s.add_dependency "nokogiri", ">= 1.4.4"
|
18
19
|
|
19
20
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
21
|
+
s.add_development_dependency "rspec", ">= 1.0.0"
|
20
22
|
|
21
23
|
s.files = `git ls-files`.split("\n")
|
22
24
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Nanoc::Toolbox::Filters::HtmlTidy do
|
4
|
+
before(:each) do
|
5
|
+
@filter = described_class.new
|
6
|
+
@invalid_output = "<h1>"
|
7
|
+
@valid_output = <<-EOS
|
8
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
9
|
+
<html><body><h1></h1></body></html>
|
10
|
+
EOS
|
11
|
+
|
12
|
+
end
|
13
|
+
describe ".run" do
|
14
|
+
it "tidy non-coherent html to a well-formed document" do
|
15
|
+
@filter.run(@invalid_output).should == @valid_output
|
16
|
+
end
|
17
|
+
|
18
|
+
it "calls Nokogiri to parse the content" do
|
19
|
+
Nokogiri::HTML::Document.should_receive(:parse).with(@invalid_output).and_return(Nokogiri::HTML::Document.new)
|
20
|
+
@filter.run(@invalid_output)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class GravatarDummyClass
|
4
|
+
end
|
5
|
+
|
6
|
+
describe Nanoc::Toolbox::Helpers::Gravatar do
|
7
|
+
before(:each) do
|
8
|
+
@gravatar = GravatarDummyClass.new
|
9
|
+
@gravatar.extend(described_class)
|
10
|
+
|
11
|
+
@email = 'anouar@adlani.com'
|
12
|
+
@avatar = 'avatar/4d076af1db60b16e1ce080505baf821c'
|
13
|
+
@secure_host = {
|
14
|
+
true => 'https://secure.gratatar.com/' + @avatar,
|
15
|
+
false => 'http://gravatar.com/' + @avatar
|
16
|
+
}
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#@gravatar.gravatar_url" do
|
21
|
+
context "when no parameters passed in the options" do
|
22
|
+
it "converts an email address to the a gravatar URL" do
|
23
|
+
@gravatar.gravatar_url(@email).should == @secure_host[false]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "converts an email address to the a secure gravatar URL when requested" do
|
27
|
+
@gravatar.gravatar_url(@email, :secure => true).should == @secure_host[true]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raise an Argument error when the email is invalid" do
|
31
|
+
lambda{@gravatar.gravatar_url('')}.should raise_error(ArgumentError)
|
32
|
+
lambda{@gravatar.gravatar_url('a@a.c')}.should raise_error(ArgumentError)
|
33
|
+
lambda{@gravatar.gravatar_url('@example.com')}.should raise_error(ArgumentError)
|
34
|
+
lambda{@gravatar.gravatar_url('name@name@example.com')}.should raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "strips the additionnal spaces before and after the email" do
|
38
|
+
@gravatar.gravatar_url(" \n #{@email} \n").should == @secure_host[false]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
context "when parameters passed in the options" do
|
44
|
+
|
45
|
+
it "removes unknown parameters" do
|
46
|
+
@gravatar.gravatar_url(@email, :blabl => 'jsdfsdfsd').should == @secure_host[false]
|
47
|
+
end
|
48
|
+
|
49
|
+
it "removes empty or nil parameters" do
|
50
|
+
@gravatar.gravatar_url(@email, :size => '', :rating => nil).should == @secure_host[false]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should sort the url parameters" do
|
54
|
+
@gravatar.gravatar_url(@email, :size => 45, :default_icon => 'monsterid', :rating => 'x').should == @secure_host[false] + '?default_icon=monsterid&rating=x&size=45'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "accepts well formed option and render them" do
|
58
|
+
@gravatar.gravatar_url(@email, :size => 45, :rating => 'x').should == @secure_host[false] + '?rating=x&size=45'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "ignores the bad type or the out of rnage parameters" do
|
62
|
+
@gravatar.gravatar_url(@email, :size => '45', :rating => 'xssss').should == @secure_host[false] + '?size=45'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#gravatar_image" do
|
68
|
+
|
69
|
+
it "converts an email to an html tag" do
|
70
|
+
@gravatar.gravatar_image(@email).should == %[<img src="#{@secure_host[false]}" />]
|
71
|
+
end
|
72
|
+
|
73
|
+
it "converts an email to an html tag with options for the gravatar" do
|
74
|
+
@gravatar.gravatar_image(@email, :size => 45, :default_icon => 'monsterid', :rating => 'xss').should == %[<img src="#{@secure_host[false]}?default_icon=monsterid&size=45" />]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "converts an email to an html tag with options for the img tag" do
|
78
|
+
@gravatar.gravatar_image(@email, :height => 10).should == %[<img height="10" src="#{@secure_host[false]}" />]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "converts an email to an html tag with options for the gravatar and for the img" do
|
82
|
+
@gravatar.gravatar_image(@email, :height => 10, :size => 45, :default_icon => 'monsterid', :rating => 'xss').should == %[<img height="10" src="#{@secure_host[false]}?default_icon=monsterid&size=45" />]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
include Nanoc::Toolbox::Helpers::HtmlTag
|
3
|
+
|
4
|
+
describe Nanoc::Toolbox::Helpers::HtmlTag do
|
5
|
+
describe "#tag" do
|
6
|
+
it "returns an simple self-closing tag by default" do
|
7
|
+
tag("br").should == "<br />"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns an simple self-closing tag with option" do
|
11
|
+
tag("hr", :class => "thin").should == %[<hr class="thin" />]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#content_tag" do
|
16
|
+
it "returns an simple with content tag by default" do
|
17
|
+
content_tag("b", "Hello").should == "<b>Hello</b>"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns an simple with content tag with options" do
|
21
|
+
content_tag("b", "Hello", :class => "highlight").should == %[<b class="highlight">Hello</b>]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
|
4
|
+
class NavigationDummyClass
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Nanoc::Toolbox::Helpers::Navigation do
|
8
|
+
before(:each) do
|
9
|
+
@navigation = NavigationDummyClass.new
|
10
|
+
@navigation.extend(described_class)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".render_menu" do
|
14
|
+
context "when no options specified" do
|
15
|
+
it "returns nil when the menu is empty" do
|
16
|
+
@navigation.render_menu([]).should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns a simple ordered list when given a 1 level menu" do
|
20
|
+
sections = [{:title => "Title", :link => "http://example.com" }]
|
21
|
+
html_menu = %[<ol><li><a href="http://example.com">Title</a></li></ol>]
|
22
|
+
|
23
|
+
@navigation.render_menu(sections).should == html_menu
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns a nested ordered list when given a multi level menu" do
|
27
|
+
sections = [{:title => "Title", :link => "http://example.com", :subsections => [{:title => "Title", :link => "http://example.com" },{:title => "Title", :link => "http://example.com" }] }]
|
28
|
+
html_menu = %[<ol><li><a href="http://example.com">Title</a><ol><li><a href="http://example.com">Title</a></li><li><a href="http://example.com">Title</a></li></ol></li></ol>]
|
29
|
+
|
30
|
+
@navigation.render_menu(sections).should == html_menu
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns only 3 levels when nothing is specified in the options" do
|
34
|
+
sections = [
|
35
|
+
{:title => "Title", :link => "http://example.com", :subsections => [
|
36
|
+
{:title => "Title", :link => "http://example.com", :subsections => [
|
37
|
+
{:title => "Title", :link => "http://example.com", :subsections => [
|
38
|
+
{:title => "Title", :link => "http://example.com"}
|
39
|
+
]}
|
40
|
+
]}
|
41
|
+
]}]
|
42
|
+
html_menu = %[<ol><li><a href="http://example.com">Title</a><ol><li><a href="http://example.com">Title</a><ol><li><a href="http://example.com">Title</a></li></ol></li></ol></li></ol>]
|
43
|
+
@navigation.render_menu(sections).should == html_menu
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns menu within an html ordered list (<ol> <li>) when nothing is specified in the options" do
|
47
|
+
sections = [{:title => "Title", :link => "http://example.com" }]
|
48
|
+
@navigation.render_menu(sections).should =~ /^<ol><li>/
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when no options specified" do
|
53
|
+
it "returns menu within a html unordered list (<ul> <li>) when it is specified in the options" do
|
54
|
+
sections = [{:title => "Title", :link => "http://example.com" }]
|
55
|
+
@navigation.render_menu(sections, :collection_tag => 'ul').should =~ /^<ul><li>/
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns menu within a div/span when it is specified in the options" do
|
59
|
+
sections = [{:title => "Title", :link => "http://example.com" }]
|
60
|
+
@navigation.render_menu(sections, :collection_tag => 'div', :item_tag => 'span').should =~ /^<div><span>/
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns only 2 levels when it's specified in the options" do
|
64
|
+
sections = [
|
65
|
+
{:title => "Title", :link => "http://example.com", :subsections => [
|
66
|
+
{:title => "Title", :link => "http://example.com", :subsections => [
|
67
|
+
{:title => "Title", :link => "http://example.com", :subsections => [
|
68
|
+
{:title => "Title", :link => "http://example.com"}
|
69
|
+
]}
|
70
|
+
]}
|
71
|
+
]}]
|
72
|
+
html_menu = %[<ol><li><a href="http://example.com">Title</a><ol><li><a href="http://example.com">Title</a></li></ol></li></ol>]
|
73
|
+
@navigation.render_menu(sections, :depth => 2).should == html_menu
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ".toc_for" do
|
79
|
+
it "should return a toc for a page"
|
80
|
+
end
|
81
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Anouar ADLANI
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-12 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -33,9 +33,24 @@ dependencies:
|
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: nokogiri
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 4
|
46
|
+
- 4
|
47
|
+
version: 1.4.4
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: bundler
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
54
|
none: false
|
40
55
|
requirements:
|
41
56
|
- - ">="
|
@@ -46,7 +61,22 @@ dependencies:
|
|
46
61
|
- 0
|
47
62
|
version: 1.0.0
|
48
63
|
type: :development
|
49
|
-
version_requirements: *
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rspec
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 0
|
76
|
+
- 0
|
77
|
+
version: 1.0.0
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
50
80
|
description: The nanoc-toolbox is a collection of filters and helpers for the static site generator tool nanoc
|
51
81
|
email:
|
52
82
|
- anouar@adlani.com
|
@@ -65,31 +95,20 @@ files:
|
|
65
95
|
- LICENSE.md
|
66
96
|
- README.md
|
67
97
|
- Rakefile
|
68
|
-
- doc/Nanoc.html
|
69
|
-
- doc/Nanoc/Toolbox.html
|
70
|
-
- doc/Nanoc/Toolbox/Helpers.html
|
71
|
-
- doc/Nanoc/Toolbox/Helpers/Navigation.html
|
72
|
-
- doc/_index.html
|
73
|
-
- doc/class_list.html
|
74
|
-
- doc/css/common.css
|
75
|
-
- doc/css/full_list.css
|
76
|
-
- doc/css/style.css
|
77
|
-
- doc/file.CHANGELOG.html
|
78
|
-
- doc/file.LICENSE.html
|
79
|
-
- doc/file.README.html
|
80
|
-
- doc/file_list.html
|
81
|
-
- doc/frames.html
|
82
|
-
- doc/index.html
|
83
|
-
- doc/js/app.js
|
84
|
-
- doc/js/full_list.js
|
85
|
-
- doc/js/jquery.js
|
86
|
-
- doc/method_list.html
|
87
|
-
- doc/top-level-namespace.html
|
88
98
|
- lib/nanoc/toolbox.rb
|
99
|
+
- lib/nanoc/toolbox/filters.rb
|
100
|
+
- lib/nanoc/toolbox/filters/html_tidy.rb
|
89
101
|
- lib/nanoc/toolbox/helpers.rb
|
102
|
+
- lib/nanoc/toolbox/helpers/gravatar.rb
|
103
|
+
- lib/nanoc/toolbox/helpers/html_tag.rb
|
90
104
|
- lib/nanoc/toolbox/helpers/navigation.rb
|
91
105
|
- lib/nanoc/toolbox/version.rb
|
92
106
|
- nanoc-toolbox.gemspec
|
107
|
+
- spec/filters/html_tidy_spec.rb
|
108
|
+
- spec/helpers/gravatar_spec.rb
|
109
|
+
- spec/helpers/html_tag_spec.rb
|
110
|
+
- spec/helpers/navigation_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
93
112
|
has_rdoc: true
|
94
113
|
homepage: http://aadlani.github.com/nanoc-toolbox/
|
95
114
|
licenses: []
|
@@ -1,999 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<meta name="Content-Type" content="text/html; charset=utf-8" />
|
6
|
-
<title>Module: Nanoc::Toolbox::Helpers::Navigation</title>
|
7
|
-
<link rel="stylesheet" href="../../../css/style.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
-
<link rel="stylesheet" href="../../../css/common.css" type="text/css" media="screen" charset="utf-8" />
|
9
|
-
|
10
|
-
<script type="text/javascript" charset="utf-8">
|
11
|
-
relpath = '../../..';
|
12
|
-
if (relpath != '') relpath += '/';
|
13
|
-
</script>
|
14
|
-
<script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
|
15
|
-
<script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
|
16
|
-
|
17
|
-
</head>
|
18
|
-
<body>
|
19
|
-
<script type="text/javascript" charset="utf-8">
|
20
|
-
if (window.top.frames.main) document.body.className = 'frames';
|
21
|
-
</script>
|
22
|
-
|
23
|
-
<div id="header">
|
24
|
-
<div id="menu">
|
25
|
-
|
26
|
-
<a href="../../../_index.html">Index (N)</a> »
|
27
|
-
<span class='title'><span class='object_link'><a href="../../../Nanoc.html" title="Nanoc (module)">Nanoc</a></span></span> » <span class='title'><span class='object_link'><a href="../../Toolbox.html" title="Nanoc::Toolbox (module)">Toolbox</a></span></span> » <span class='title'><span class='object_link'><a href="../Helpers.html" title="Nanoc::Toolbox::Helpers (module)">Helpers</a></span></span>
|
28
|
-
»
|
29
|
-
<span class="title">Navigation</span>
|
30
|
-
|
31
|
-
|
32
|
-
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="search">
|
36
|
-
<a id="class_list_link" href="#">Class List</a>
|
37
|
-
<a id="method_list_link" href="#">Method List</a>
|
38
|
-
<a id ="file_list_link" href="#">File List</a>
|
39
|
-
</div>
|
40
|
-
|
41
|
-
<div class="clear"></div>
|
42
|
-
</div>
|
43
|
-
|
44
|
-
<iframe id="search_frame"></iframe>
|
45
|
-
|
46
|
-
<div id="content"><h1>Module: Nanoc::Toolbox::Helpers::Navigation
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
</h1>
|
51
|
-
|
52
|
-
<dl class="box">
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
<dt class="r1 last">Defined in:</dt>
|
62
|
-
<dd class="r1 last">lib/nanoc/toolbox/helpers/navigation.rb</dd>
|
63
|
-
|
64
|
-
</dl>
|
65
|
-
<div class="clear"></div>
|
66
|
-
|
67
|
-
<h2>Overview</h2><div class="docstring">
|
68
|
-
<div class="discussion">
|
69
|
-
<p>
|
70
|
-
NANOC Helper for the Navigation related stuff. This module contains
|
71
|
-
functions for generating navigation menus for your pages, like navigation
|
72
|
-
menu, breadcrumbs or a table of content for a given Item
|
73
|
-
</p>
|
74
|
-
|
75
|
-
|
76
|
-
</div>
|
77
|
-
</div>
|
78
|
-
<div class="tags">
|
79
|
-
<h3>Author:</h3>
|
80
|
-
<ul class="author">
|
81
|
-
|
82
|
-
<li>
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
<div class='inline'><p>
|
89
|
-
Anouar ADLANI <anouar@adlani.com>
|
90
|
-
</p>
|
91
|
-
</div>
|
92
|
-
|
93
|
-
</li>
|
94
|
-
|
95
|
-
</ul>
|
96
|
-
|
97
|
-
</div>
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
<h2>
|
102
|
-
Instance Method Summary
|
103
|
-
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
104
|
-
</h2>
|
105
|
-
|
106
|
-
<ul class="summary">
|
107
|
-
|
108
|
-
<li class="public ">
|
109
|
-
<span class="summary_signature">
|
110
|
-
|
111
|
-
<a href="#breadcrumb_for-instance_method" title="#breadcrumb_for (instance method)">- (String) <strong>breadcrumb_for</strong>(identifier, params = {}) </a>
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
</span>
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
<span class="summary_desc"><div class='inline'><p>
|
125
|
-
Generate a Breadcrumb for a given item.
|
126
|
-
</p>
|
127
|
-
</div></span>
|
128
|
-
|
129
|
-
</li>
|
130
|
-
|
131
|
-
|
132
|
-
<li class="public ">
|
133
|
-
<span class="summary_signature">
|
134
|
-
|
135
|
-
<a href="#navigation_for-instance_method" title="#navigation_for (instance method)">- (String) <strong>navigation_for</strong>(identifier, params = {}) </a>
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
</span>
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
<span class="summary_desc"><div class='inline'><p>
|
149
|
-
Generate a navigation menu for a given item.
|
150
|
-
</p>
|
151
|
-
</div></span>
|
152
|
-
|
153
|
-
</li>
|
154
|
-
|
155
|
-
|
156
|
-
<li class="public ">
|
157
|
-
<span class="summary_signature">
|
158
|
-
|
159
|
-
<a href="#render_menu-instance_method" title="#render_menu (instance method)">- (String) <strong>render_menu</strong>(items, params = {}) </a>
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
</span>
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
<span class="summary_desc"><div class='inline'><p>
|
173
|
-
Render a Hash to a HTML List by default.
|
174
|
-
</p>
|
175
|
-
</div></span>
|
176
|
-
|
177
|
-
</li>
|
178
|
-
|
179
|
-
|
180
|
-
<li class="public ">
|
181
|
-
<span class="summary_signature">
|
182
|
-
|
183
|
-
<a href="#toc_for-instance_method" title="#toc_for (instance method)">- (String) <strong>toc_for</strong>(item_rep, params = {}) </a>
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
</span>
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
<span class="summary_desc"><div class='inline'><p>
|
197
|
-
Generate a Table of Content for a given item.
|
198
|
-
</p>
|
199
|
-
</div></span>
|
200
|
-
|
201
|
-
</li>
|
202
|
-
|
203
|
-
|
204
|
-
</ul>
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
<div id="instance_method_details" class="method_details_list">
|
210
|
-
<h2>Instance Method Details</h2>
|
211
|
-
|
212
|
-
|
213
|
-
<div class="method_details first">
|
214
|
-
<p class="signature first" id="breadcrumb_for-instance_method">
|
215
|
-
|
216
|
-
- (<tt>String</tt>) <strong>breadcrumb_for</strong>(identifier, params = {})
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
</p><div class="docstring">
|
221
|
-
<div class="discussion">
|
222
|
-
<p>
|
223
|
-
Generate a Breadcrumb for a given item. The breadcrumbs, is starting with
|
224
|
-
the root item and ending with the item itself.
|
225
|
-
</p>
|
226
|
-
<p>
|
227
|
-
Requires the Helper: Nanoc3::Helpers::Breadcrumbs
|
228
|
-
</p>
|
229
|
-
|
230
|
-
|
231
|
-
</div>
|
232
|
-
</div>
|
233
|
-
<div class="tags">
|
234
|
-
<h3>Parameters:</h3>
|
235
|
-
<ul class="param">
|
236
|
-
|
237
|
-
<li>
|
238
|
-
|
239
|
-
<span class='type'>(<tt>String</tt>)</span>
|
240
|
-
|
241
|
-
|
242
|
-
<span class='name'>identifier</span>
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
—
|
247
|
-
<div class='inline'><ul>
|
248
|
-
<li><p>
|
249
|
-
the identifier string of element
|
250
|
-
</p>
|
251
|
-
</li>
|
252
|
-
</ul>
|
253
|
-
</div>
|
254
|
-
|
255
|
-
</li>
|
256
|
-
|
257
|
-
<li>
|
258
|
-
|
259
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
260
|
-
|
261
|
-
|
262
|
-
<span class='name'>params</span>
|
263
|
-
|
264
|
-
|
265
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
266
|
-
|
267
|
-
|
268
|
-
—
|
269
|
-
<div class='inline'><ul>
|
270
|
-
<li><p>
|
271
|
-
The Optional parameters
|
272
|
-
</p>
|
273
|
-
</li>
|
274
|
-
</ul>
|
275
|
-
</div>
|
276
|
-
|
277
|
-
</li>
|
278
|
-
|
279
|
-
</ul>
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
<h3>Options Hash (<tt>params</tt>):</h3>
|
287
|
-
<ul class="option">
|
288
|
-
|
289
|
-
<li>
|
290
|
-
<span class="type">(<tt>String</tt>)</span>
|
291
|
-
<span class="name">:collection_tag</span>
|
292
|
-
<span class="default">
|
293
|
-
|
294
|
-
— default:
|
295
|
-
<tt>'ol'</tt>
|
296
|
-
|
297
|
-
</span>
|
298
|
-
— <div class='inline'><p>
|
299
|
-
collection englobing tag name
|
300
|
-
</p>
|
301
|
-
</div>
|
302
|
-
</tr>
|
303
|
-
|
304
|
-
<li>
|
305
|
-
<span class="type">(<tt>String</tt>)</span>
|
306
|
-
<span class="name">:item_tag</span>
|
307
|
-
<span class="default">
|
308
|
-
|
309
|
-
— default:
|
310
|
-
<tt>'li'</tt>
|
311
|
-
|
312
|
-
</span>
|
313
|
-
— <div class='inline'><p>
|
314
|
-
item englobing tag name
|
315
|
-
</p>
|
316
|
-
</div>
|
317
|
-
</tr>
|
318
|
-
|
319
|
-
</ul>
|
320
|
-
|
321
|
-
<h3>Returns:</h3>
|
322
|
-
<ul class="return">
|
323
|
-
|
324
|
-
<li>
|
325
|
-
|
326
|
-
<span class='type'>(<tt>String</tt>)</span>
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
—
|
332
|
-
<div class='inline'><p>
|
333
|
-
The output ready to be displayed by the caller
|
334
|
-
</p>
|
335
|
-
</div>
|
336
|
-
|
337
|
-
</li>
|
338
|
-
|
339
|
-
</ul>
|
340
|
-
|
341
|
-
<h3>See Also:</h3>
|
342
|
-
<ul class="see">
|
343
|
-
|
344
|
-
<li>Nanoc3::Helpers::Breadcrumbs#breadcrumbs_for_identifier</li>
|
345
|
-
|
346
|
-
</ul>
|
347
|
-
|
348
|
-
</div><table class="source_code">
|
349
|
-
<tr>
|
350
|
-
<td>
|
351
|
-
<pre class="lines">
|
352
|
-
|
353
|
-
|
354
|
-
88
|
355
|
-
89
|
356
|
-
90
|
357
|
-
91
|
358
|
-
92
|
359
|
-
93
|
360
|
-
94
|
361
|
-
95
|
362
|
-
96
|
363
|
-
97</pre>
|
364
|
-
</td>
|
365
|
-
<td>
|
366
|
-
<pre class="code"><span class="info file"># File 'lib/nanoc/toolbox/helpers/navigation.rb', line 88</span>
|
367
|
-
|
368
|
-
<span class='kw'>def</span> <span class='id breadcrumb_for'>breadcrumb_for</span><span class='lparen'>(</span><span class='id identifier'>identifier</span><span class='comma'>,</span> <span class='id params'>params</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
369
|
-
|
370
|
-
<span class='comment'># Parse params or set to default values
|
371
|
-
</span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ul</span><span class='tstring_end'>'</span></span>
|
372
|
-
<span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>li</span><span class='tstring_end'>'</span></span>
|
373
|
-
|
374
|
-
<span class='comment'># Retreive the breadcrumbs trail and format them
|
375
|
-
</span> <span class='id sections'>sections</span> <span class='op'>=</span> <span class='id find_breadcrumbs_trail'>find_breadcrumbs_trail</span><span class='lparen'>(</span><span class='id identifier'>identifier</span><span class='rparen'>)</span>
|
376
|
-
<span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id sections'>sections</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
|
377
|
-
<span class='kw'>end</span></pre>
|
378
|
-
</td>
|
379
|
-
</tr>
|
380
|
-
</table>
|
381
|
-
</div>
|
382
|
-
|
383
|
-
<div class="method_details ">
|
384
|
-
<p class="signature " id="navigation_for-instance_method">
|
385
|
-
|
386
|
-
- (<tt>String</tt>) <strong>navigation_for</strong>(identifier, params = {})
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
</p><div class="docstring">
|
391
|
-
<div class="discussion">
|
392
|
-
<p>
|
393
|
-
Generate a navigation menu for a given item. The menu will be generated
|
394
|
-
form the identifier of the desired root element. The root itself will not
|
395
|
-
be rendered. It generate the menu by parsing all the descendent of the
|
396
|
-
passed item.
|
397
|
-
</p>
|
398
|
-
|
399
|
-
|
400
|
-
</div>
|
401
|
-
</div>
|
402
|
-
<div class="tags">
|
403
|
-
<h3>Parameters:</h3>
|
404
|
-
<ul class="param">
|
405
|
-
|
406
|
-
<li>
|
407
|
-
|
408
|
-
<span class='type'>(<tt>String</tt>)</span>
|
409
|
-
|
410
|
-
|
411
|
-
<span class='name'>identifier</span>
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
—
|
416
|
-
<div class='inline'><ul>
|
417
|
-
<li><p>
|
418
|
-
the identifier string of the root element
|
419
|
-
</p>
|
420
|
-
</li>
|
421
|
-
</ul>
|
422
|
-
</div>
|
423
|
-
|
424
|
-
</li>
|
425
|
-
|
426
|
-
<li>
|
427
|
-
|
428
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
429
|
-
|
430
|
-
|
431
|
-
<span class='name'>params</span>
|
432
|
-
|
433
|
-
|
434
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
435
|
-
|
436
|
-
|
437
|
-
—
|
438
|
-
<div class='inline'><ul>
|
439
|
-
<li><p>
|
440
|
-
The Optional parameters
|
441
|
-
</p>
|
442
|
-
</li>
|
443
|
-
</ul>
|
444
|
-
</div>
|
445
|
-
|
446
|
-
</li>
|
447
|
-
|
448
|
-
</ul>
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
<h3>Options Hash (<tt>params</tt>):</h3>
|
456
|
-
<ul class="option">
|
457
|
-
|
458
|
-
<li>
|
459
|
-
<span class="type">(<tt>Interger</tt>)</span>
|
460
|
-
<span class="name">:depth</span>
|
461
|
-
<span class="default">
|
462
|
-
|
463
|
-
— default:
|
464
|
-
<tt>3</tt>
|
465
|
-
|
466
|
-
</span>
|
467
|
-
— <div class='inline'><p>
|
468
|
-
maximum depth of the rendered menu
|
469
|
-
</p>
|
470
|
-
</div>
|
471
|
-
</tr>
|
472
|
-
|
473
|
-
<li>
|
474
|
-
<span class="type">(<tt>String</tt>)</span>
|
475
|
-
<span class="name">:collection_tag</span>
|
476
|
-
<span class="default">
|
477
|
-
|
478
|
-
— default:
|
479
|
-
<tt>'ol'</tt>
|
480
|
-
|
481
|
-
</span>
|
482
|
-
— <div class='inline'><p>
|
483
|
-
collection englobing tag name
|
484
|
-
</p>
|
485
|
-
</div>
|
486
|
-
</tr>
|
487
|
-
|
488
|
-
<li>
|
489
|
-
<span class="type">(<tt>String</tt>)</span>
|
490
|
-
<span class="name">:item_tag</span>
|
491
|
-
<span class="default">
|
492
|
-
|
493
|
-
— default:
|
494
|
-
<tt>'li'</tt>
|
495
|
-
|
496
|
-
</span>
|
497
|
-
— <div class='inline'><p>
|
498
|
-
item englobing tag name
|
499
|
-
</p>
|
500
|
-
</div>
|
501
|
-
</tr>
|
502
|
-
|
503
|
-
</ul>
|
504
|
-
|
505
|
-
<h3>Returns:</h3>
|
506
|
-
<ul class="return">
|
507
|
-
|
508
|
-
<li>
|
509
|
-
|
510
|
-
<span class='type'>(<tt>String</tt>)</span>
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
—
|
516
|
-
<div class='inline'><p>
|
517
|
-
The output ready to be displayed by the caller
|
518
|
-
</p>
|
519
|
-
</div>
|
520
|
-
|
521
|
-
</li>
|
522
|
-
|
523
|
-
</ul>
|
524
|
-
|
525
|
-
</div><table class="source_code">
|
526
|
-
<tr>
|
527
|
-
<td>
|
528
|
-
<pre class="lines">
|
529
|
-
|
530
|
-
|
531
|
-
22
|
532
|
-
23
|
533
|
-
24
|
534
|
-
25
|
535
|
-
26
|
536
|
-
27
|
537
|
-
28
|
538
|
-
29
|
539
|
-
30
|
540
|
-
31
|
541
|
-
32
|
542
|
-
33
|
543
|
-
34
|
544
|
-
35
|
545
|
-
36
|
546
|
-
37
|
547
|
-
38
|
548
|
-
39
|
549
|
-
40</pre>
|
550
|
-
</td>
|
551
|
-
<td>
|
552
|
-
<pre class="code"><span class="info file"># File 'lib/nanoc/toolbox/helpers/navigation.rb', line 22</span>
|
553
|
-
|
554
|
-
<span class='kw'>def</span> <span class='id navigation_for'>navigation_for</span><span class='lparen'>(</span><span class='id identifier'>identifier</span><span class='comma'>,</span> <span class='id params'>params</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
555
|
-
<span class='comment'># Parse params or set to default values
|
556
|
-
</span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='int'>3</span>
|
557
|
-
<span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ol</span><span class='tstring_end'>'</span></span>
|
558
|
-
<span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>li</span><span class='tstring_end'>'</span></span>
|
559
|
-
|
560
|
-
<span class='comment'># Decrease the depth level
|
561
|
-
</span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>-=</span> <span class='int'>1</span>
|
562
|
-
|
563
|
-
<span class='comment'># Get root item for which we need to draw the navigation
|
564
|
-
</span> <span class='id root'>root</span> <span class='op'>=</span> <span class='ivar'>@items</span><span class='period'>.</span><span class='id find'>find</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id i'>i</span><span class='op'>|</span> <span class='id i'>i</span><span class='period'>.</span><span class='id identifier'>identifier</span> <span class='op'>==</span> <span class='id identifier'>identifier</span> <span class='rbrace'>}</span>
|
565
|
-
|
566
|
-
<span class='comment'># Do not render if there is no child
|
567
|
-
</span> <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id root'>root</span><span class='period'>.</span><span class='id children'>children</span>
|
568
|
-
|
569
|
-
<span class='comment'># Find all sections, and render them
|
570
|
-
</span> <span class='id sections'>sections</span> <span class='op'>=</span> <span class='id find_item_tree'>find_item_tree</span><span class='lparen'>(</span><span class='id root'>root</span><span class='rparen'>)</span>
|
571
|
-
<span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id sections'>sections</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
|
572
|
-
<span class='kw'>end</span></pre>
|
573
|
-
</td>
|
574
|
-
</tr>
|
575
|
-
</table>
|
576
|
-
</div>
|
577
|
-
|
578
|
-
<div class="method_details ">
|
579
|
-
<p class="signature " id="render_menu-instance_method">
|
580
|
-
|
581
|
-
- (<tt>String</tt>) <strong>render_menu</strong>(items, params = {})
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
</p><div class="docstring">
|
586
|
-
<div class="discussion">
|
587
|
-
<p>
|
588
|
-
Render a Hash to a HTML List by default
|
589
|
-
</p>
|
590
|
-
<p>
|
591
|
-
Hash structure should be construct like this:
|
592
|
-
</p>
|
593
|
-
<pre class="code">
|
594
|
-
Link: is an hash with the following key
|
595
|
-
* :title => The content of the link
|
596
|
-
* :link => The link
|
597
|
-
* :subsections => nil or an Array of Links
|
598
|
-
|
599
|
-
[{:title => 'Title', :link => 'http://example.com', :subsections => [{}, {}, ...]},{...}]
|
600
|
-
</pre>
|
601
|
-
<p>
|
602
|
-
Results to an output like the following (by default):
|
603
|
-
</p>
|
604
|
-
<pre class="code">
|
605
|
-
<ul>
|
606
|
-
<li>
|
607
|
-
<a href="http://example.com">Title</a>
|
608
|
-
<ul>
|
609
|
-
<li><a href="">Title</a></li>
|
610
|
-
</ul>
|
611
|
-
</li>
|
612
|
-
<li><a href="http://example.com">Title</a></li>
|
613
|
-
<li><a href="http://example.com">Title</a></li>
|
614
|
-
</ul></pre>
|
615
|
-
|
616
|
-
|
617
|
-
</div>
|
618
|
-
</div>
|
619
|
-
<div class="tags">
|
620
|
-
<h3>Parameters:</h3>
|
621
|
-
<ul class="param">
|
622
|
-
|
623
|
-
<li>
|
624
|
-
|
625
|
-
<span class='type'>(<tt>Array</tt>)</span>
|
626
|
-
|
627
|
-
|
628
|
-
<span class='name'>items</span>
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
—
|
633
|
-
<div class='inline'><ul>
|
634
|
-
<li><p>
|
635
|
-
The array of links that need to be rendered
|
636
|
-
</p>
|
637
|
-
</li>
|
638
|
-
</ul>
|
639
|
-
</div>
|
640
|
-
|
641
|
-
</li>
|
642
|
-
|
643
|
-
<li>
|
644
|
-
|
645
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
646
|
-
|
647
|
-
|
648
|
-
<span class='name'>params</span>
|
649
|
-
|
650
|
-
|
651
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
652
|
-
|
653
|
-
|
654
|
-
—
|
655
|
-
<div class='inline'><ul>
|
656
|
-
<li><p>
|
657
|
-
The Optional parameters
|
658
|
-
</p>
|
659
|
-
</li>
|
660
|
-
</ul>
|
661
|
-
</div>
|
662
|
-
|
663
|
-
</li>
|
664
|
-
|
665
|
-
</ul>
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
<h3>Options Hash (<tt>params</tt>):</h3>
|
673
|
-
<ul class="option">
|
674
|
-
|
675
|
-
<li>
|
676
|
-
<span class="type">(<tt>String</tt>)</span>
|
677
|
-
<span class="name">:collection_tag</span>
|
678
|
-
<span class="default">
|
679
|
-
|
680
|
-
— default:
|
681
|
-
<tt>'ol'</tt>
|
682
|
-
|
683
|
-
</span>
|
684
|
-
— <div class='inline'><p>
|
685
|
-
collection englobing tag name
|
686
|
-
</p>
|
687
|
-
</div>
|
688
|
-
</tr>
|
689
|
-
|
690
|
-
<li>
|
691
|
-
<span class="type">(<tt>String</tt>)</span>
|
692
|
-
<span class="name">:item_tag</span>
|
693
|
-
<span class="default">
|
694
|
-
|
695
|
-
— default:
|
696
|
-
<tt>'li'</tt>
|
697
|
-
|
698
|
-
</span>
|
699
|
-
— <div class='inline'><p>
|
700
|
-
item englobing tag name
|
701
|
-
</p>
|
702
|
-
</div>
|
703
|
-
</tr>
|
704
|
-
|
705
|
-
</ul>
|
706
|
-
|
707
|
-
<h3>Returns:</h3>
|
708
|
-
<ul class="return">
|
709
|
-
|
710
|
-
<li>
|
711
|
-
|
712
|
-
<span class='type'>(<tt>String</tt>)</span>
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
—
|
718
|
-
<div class='inline'><p>
|
719
|
-
The output ready to be displayed by the caller
|
720
|
-
</p>
|
721
|
-
</div>
|
722
|
-
|
723
|
-
</li>
|
724
|
-
|
725
|
-
</ul>
|
726
|
-
|
727
|
-
</div><table class="source_code">
|
728
|
-
<tr>
|
729
|
-
<td>
|
730
|
-
<pre class="lines">
|
731
|
-
|
732
|
-
|
733
|
-
128
|
734
|
-
129
|
735
|
-
130
|
736
|
-
131
|
737
|
-
132
|
738
|
-
133
|
739
|
-
134
|
740
|
-
135
|
741
|
-
136
|
742
|
-
137
|
743
|
-
138
|
744
|
-
139
|
745
|
-
140
|
746
|
-
141
|
747
|
-
142
|
748
|
-
143
|
749
|
-
144
|
750
|
-
145
|
751
|
-
146
|
752
|
-
147
|
753
|
-
148
|
754
|
-
149
|
755
|
-
150
|
756
|
-
151</pre>
|
757
|
-
</td>
|
758
|
-
<td>
|
759
|
-
<pre class="code"><span class="info file"># File 'lib/nanoc/toolbox/helpers/navigation.rb', line 128</span>
|
760
|
-
|
761
|
-
<span class='kw'>def</span> <span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id items'>items</span><span class='comma'>,</span> <span class='id params'>params</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
762
|
-
|
763
|
-
<span class='comment'># Parse params or set to default values
|
764
|
-
</span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='int'>3</span>
|
765
|
-
<span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ol</span><span class='tstring_end'>'</span></span>
|
766
|
-
<span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>li</span><span class='tstring_end'>'</span></span>
|
767
|
-
|
768
|
-
<span class='comment'># Decrease the depth level
|
769
|
-
</span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>-=</span> <span class='int'>1</span>
|
770
|
-
|
771
|
-
<span class='id rendered_menu'>rendered_menu</span> <span class='op'>=</span> <span class='id items'>items</span><span class='period'>.</span><span class='id map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id item'>item</span><span class='op'>|</span>
|
772
|
-
|
773
|
-
<span class='comment'># Render only if there is depth left
|
774
|
-
</span> <span class='kw'>if</span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id to_i'>to_i</span> <span class='op'>>=</span> <span class='int'>0</span> <span class='op'>&&</span> <span class='id item'>item</span><span class='lbracket'>[</span><span class='symbol'>:subsections</span><span class='rbracket'>]</span>
|
775
|
-
<span class='id output'>output</span> <span class='op'>=</span> <span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id item'>item</span><span class='lbracket'>[</span><span class='symbol'>:subsections</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
|
776
|
-
<span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>+=</span> <span class='int'>1</span> <span class='comment'># Increase the depth level after the call of navigation_for
|
777
|
-
</span> <span class='kw'>end</span>
|
778
|
-
<span class='id output'>output</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span>
|
779
|
-
<span class='id content_tag'>content_tag</span><span class='lparen'>(</span><span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id link_to'>link_to</span><span class='lparen'>(</span><span class='id item'>item</span><span class='lbracket'>[</span><span class='symbol'>:title</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id item'>item</span><span class='lbracket'>[</span><span class='symbol'>:link</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>+</span> <span class='id output'>output</span><span class='rparen'>)</span>
|
780
|
-
|
781
|
-
<span class='kw'>end</span><span class='period'>.</span><span class='id join'>join</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
782
|
-
|
783
|
-
<span class='id content_tag'>content_tag</span><span class='lparen'>(</span><span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id rendered_menu'>rendered_menu</span><span class='rparen'>)</span>
|
784
|
-
<span class='kw'>end</span></pre>
|
785
|
-
</td>
|
786
|
-
</tr>
|
787
|
-
</table>
|
788
|
-
</div>
|
789
|
-
|
790
|
-
<div class="method_details ">
|
791
|
-
<p class="signature " id="toc_for-instance_method">
|
792
|
-
|
793
|
-
- (<tt>String</tt>) <strong>toc_for</strong>(item_rep, params = {})
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
</p><div class="docstring">
|
798
|
-
<div class="discussion">
|
799
|
-
<p>
|
800
|
-
Generate a Table of Content for a given item. The toc will be generated
|
801
|
-
form the item content. The parsing is done with Nokogiri through XPath.
|
802
|
-
</p>
|
803
|
-
|
804
|
-
|
805
|
-
</div>
|
806
|
-
</div>
|
807
|
-
<div class="tags">
|
808
|
-
<h3>Parameters:</h3>
|
809
|
-
<ul class="param">
|
810
|
-
|
811
|
-
<li>
|
812
|
-
|
813
|
-
<span class='type'>(<tt>String</tt>)</span>
|
814
|
-
|
815
|
-
|
816
|
-
<span class='name'>item_rep</span>
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
—
|
821
|
-
<div class='inline'><ul>
|
822
|
-
<li><p>
|
823
|
-
the representation of desired item
|
824
|
-
</p>
|
825
|
-
</li>
|
826
|
-
</ul>
|
827
|
-
</div>
|
828
|
-
|
829
|
-
</li>
|
830
|
-
|
831
|
-
<li>
|
832
|
-
|
833
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
834
|
-
|
835
|
-
|
836
|
-
<span class='name'>params</span>
|
837
|
-
|
838
|
-
|
839
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
840
|
-
|
841
|
-
|
842
|
-
—
|
843
|
-
<div class='inline'><ul>
|
844
|
-
<li><p>
|
845
|
-
The Optional parameters
|
846
|
-
</p>
|
847
|
-
</li>
|
848
|
-
</ul>
|
849
|
-
</div>
|
850
|
-
|
851
|
-
</li>
|
852
|
-
|
853
|
-
</ul>
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
<h3>Options Hash (<tt>params</tt>):</h3>
|
861
|
-
<ul class="option">
|
862
|
-
|
863
|
-
<li>
|
864
|
-
<span class="type">(<tt>Interger</tt>)</span>
|
865
|
-
<span class="name">:depth</span>
|
866
|
-
<span class="default">
|
867
|
-
|
868
|
-
— default:
|
869
|
-
<tt>3</tt>
|
870
|
-
|
871
|
-
</span>
|
872
|
-
— <div class='inline'><p>
|
873
|
-
maximum depth of the rendered menu
|
874
|
-
</p>
|
875
|
-
</div>
|
876
|
-
</tr>
|
877
|
-
|
878
|
-
<li>
|
879
|
-
<span class="type">(<tt>String</tt>)</span>
|
880
|
-
<span class="name">:collection_tag</span>
|
881
|
-
<span class="default">
|
882
|
-
|
883
|
-
— default:
|
884
|
-
<tt>'ol'</tt>
|
885
|
-
|
886
|
-
</span>
|
887
|
-
— <div class='inline'><p>
|
888
|
-
collection englobing tag name
|
889
|
-
</p>
|
890
|
-
</div>
|
891
|
-
</tr>
|
892
|
-
|
893
|
-
<li>
|
894
|
-
<span class="type">(<tt>String</tt>)</span>
|
895
|
-
<span class="name">:item_tag</span>
|
896
|
-
<span class="default">
|
897
|
-
|
898
|
-
— default:
|
899
|
-
<tt>'li'</tt>
|
900
|
-
|
901
|
-
</span>
|
902
|
-
— <div class='inline'><p>
|
903
|
-
item englobing tag name
|
904
|
-
</p>
|
905
|
-
</div>
|
906
|
-
</tr>
|
907
|
-
|
908
|
-
</ul>
|
909
|
-
|
910
|
-
<h3>Returns:</h3>
|
911
|
-
<ul class="return">
|
912
|
-
|
913
|
-
<li>
|
914
|
-
|
915
|
-
<span class='type'>(<tt>String</tt>)</span>
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
—
|
921
|
-
<div class='inline'><p>
|
922
|
-
The output ready to be displayed by the caller
|
923
|
-
</p>
|
924
|
-
</div>
|
925
|
-
|
926
|
-
</li>
|
927
|
-
|
928
|
-
</ul>
|
929
|
-
|
930
|
-
<h3>See Also:</h3>
|
931
|
-
<ul class="see">
|
932
|
-
|
933
|
-
<li><a href="http://nokogiri.org/" target="_parent" title="http://nokogiri.org/">http://nokogiri.org/</a></li>
|
934
|
-
|
935
|
-
</ul>
|
936
|
-
|
937
|
-
</div><table class="source_code">
|
938
|
-
<tr>
|
939
|
-
<td>
|
940
|
-
<pre class="lines">
|
941
|
-
|
942
|
-
|
943
|
-
55
|
944
|
-
56
|
945
|
-
57
|
946
|
-
58
|
947
|
-
59
|
948
|
-
60
|
949
|
-
61
|
950
|
-
62
|
951
|
-
63
|
952
|
-
64
|
953
|
-
65
|
954
|
-
66
|
955
|
-
67
|
956
|
-
68
|
957
|
-
69
|
958
|
-
70
|
959
|
-
71
|
960
|
-
72</pre>
|
961
|
-
</td>
|
962
|
-
<td>
|
963
|
-
<pre class="code"><span class="info file"># File 'lib/nanoc/toolbox/helpers/navigation.rb', line 55</span>
|
964
|
-
|
965
|
-
<span class='kw'>def</span> <span class='id toc_for'>toc_for</span><span class='lparen'>(</span><span class='id item_rep'>item_rep</span><span class='comma'>,</span> <span class='id params'>params</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
966
|
-
<span class='id require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nokogiri</span><span class='tstring_end'>'</span></span>
|
967
|
-
|
968
|
-
<span class='comment'># Parse params or set to default values
|
969
|
-
</span> <span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:depth</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='int'>3</span>
|
970
|
-
<span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:collection_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ol</span><span class='tstring_end'>'</span></span>
|
971
|
-
<span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:item_tag</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>li</span><span class='tstring_end'>'</span></span>
|
972
|
-
<span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:path</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>div[@class="section"]</span><span class='tstring_end'>'</span></span>
|
973
|
-
|
974
|
-
<span class='comment'># Retreive the parsed content and init nokogiri
|
975
|
-
</span> <span class='id compiled_content'>compiled_content</span> <span class='op'>=</span> <span class='id item_rep'>item_rep</span><span class='period'>.</span><span class='id instance_eval'>instance_eval</span> <span class='lbrace'>{</span> <span class='ivar'>@content</span><span class='lbracket'>[</span><span class='symbol'>:pre</span><span class='rbracket'>]</span> <span class='rbrace'>}</span>
|
976
|
-
<span class='id doc'>doc</span> <span class='op'>=</span> <span class='const'>Nokogiri</span><span class='op'>::</span><span class='const'>HTML</span><span class='lparen'>(</span><span class='id compiled_content'>compiled_content</span><span class='rparen'>)</span>
|
977
|
-
<span class='id doc_root'>doc_root</span> <span class='op'>=</span> <span class='id doc'>doc</span><span class='period'>.</span><span class='id xpath'>xpath</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/html/body</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id first'>first</span>
|
978
|
-
|
979
|
-
<span class='comment'># Find all sections, and render them
|
980
|
-
</span> <span class='id sections'>sections</span> <span class='op'>=</span> <span class='id find_toc_sections'>find_toc_sections</span><span class='lparen'>(</span><span class='id doc_root'>doc_root</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id params'>params</span><span class='lbracket'>[</span><span class='symbol'>:path</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='int'>2</span><span class='rparen'>)</span>
|
981
|
-
<span class='id render_menu'>render_menu</span><span class='lparen'>(</span><span class='id sections'>sections</span><span class='comma'>,</span> <span class='id params'>params</span><span class='rparen'>)</span>
|
982
|
-
<span class='kw'>end</span></pre>
|
983
|
-
</td>
|
984
|
-
</tr>
|
985
|
-
</table>
|
986
|
-
</div>
|
987
|
-
|
988
|
-
</div>
|
989
|
-
|
990
|
-
</div>
|
991
|
-
|
992
|
-
<div id="footer">
|
993
|
-
Generated on Thu Jan 6 16:04:02 2011 by
|
994
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
995
|
-
0.6.4 (ruby-1.9.2).
|
996
|
-
</div>
|
997
|
-
|
998
|
-
</body>
|
999
|
-
</html>
|