glyph 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS.textile +1 -1
- data/CHANGELOG.textile +119 -222
- data/LICENSE.textile +1 -1
- data/README.textile +42 -23
- data/Rakefile +1 -3
- data/VERSION +1 -1
- data/benchmark.rb +72 -0
- data/book/config.yml +4 -4
- data/book/document.glyph +90 -57
- data/book/images/document_generation.png +0 -0
- data/book/lib/macros/reference.rb +75 -22
- data/book/output/html/glyph.html +3183 -2121
- data/book/output/html/images/document_generation.png +0 -0
- data/book/output/pdf/glyph.pdf +7370 -4913
- data/book/resources/document_generation.txt +34 -0
- data/book/snippets.yml +6 -0
- data/book/text/changelog.glyph +45 -34
- data/book/text/compiling/compiling.glyph +23 -0
- data/book/text/compiling/lite_mode.glyph +23 -0
- data/book/text/compiling/programmatic_usage.glyph +77 -0
- data/book/text/extending/bookmarks_headers.glyph +21 -0
- data/book/text/extending/further_reading.glyph +13 -0
- data/book/text/extending/internals.glyph +79 -0
- data/book/text/extending/interpreting.glyph +51 -0
- data/book/text/extending/macro_def.glyph +64 -0
- data/book/text/extending/params_attrs.glyph +70 -0
- data/book/text/extending/placeholders.glyph +34 -0
- data/book/text/extending/validators.glyph +16 -0
- data/book/text/getting_started/configuration.glyph +49 -0
- data/book/text/getting_started/create_project.glyph +41 -0
- data/book/text/getting_started/structure.glyph +55 -0
- data/book/text/introduction.glyph +49 -26
- data/book/text/license.glyph +1 -1
- data/book/text/macros/macros_block.glyph +99 -0
- data/book/text/macros/macros_core.glyph +208 -0
- data/book/text/macros/macros_filters.glyph +40 -0
- data/book/text/macros/macros_inline.glyph +50 -0
- data/book/text/macros/macros_structure.glyph +100 -0
- data/book/text/ref_commands.glyph +94 -73
- data/book/text/ref_config.glyph +34 -42
- data/book/text/ref_macros.glyph +1 -373
- data/book/text/text_editing/code.glyph +51 -0
- data/book/text/text_editing/conditionals.glyph +49 -0
- data/book/text/text_editing/evaluation.glyph +13 -0
- data/book/text/text_editing/glyph_files.glyph +7 -0
- data/book/text/text_editing/images.glyph +29 -0
- data/book/text/text_editing/inclusions.glyph +44 -0
- data/book/text/text_editing/links.glyph +53 -0
- data/book/text/text_editing/macro_intro.glyph +111 -0
- data/book/text/text_editing/raw_html.glyph +112 -0
- data/book/text/text_editing/sections.glyph +63 -0
- data/book/text/text_editing/stylesheets.glyph +36 -0
- data/book/text/troubleshooting/errors_command.glyph +39 -0
- data/book/text/troubleshooting/errors_generic.glyph +29 -0
- data/book/text/troubleshooting/errors_intro.glyph +3 -0
- data/book/text/troubleshooting/errors_macro.glyph +98 -0
- data/book/text/troubleshooting/errors_parser.glyph +29 -0
- data/config.yml +77 -58
- data/document.glyph +25 -25
- data/glyph.gemspec +57 -22
- data/lib/glyph.rb +54 -13
- data/lib/glyph/commands.rb +84 -17
- data/lib/glyph/config.rb +3 -3
- data/lib/glyph/document.rb +14 -8
- data/lib/glyph/interpreter.rb +18 -58
- data/lib/glyph/macro.rb +160 -55
- data/lib/glyph/macro_validators.rb +104 -12
- data/lib/glyph/node.rb +24 -0
- data/lib/glyph/parser.rb +278 -0
- data/lib/glyph/syntax_node.rb +225 -0
- data/macros/core.rb +212 -0
- data/macros/filters.rb +66 -15
- data/macros/html/block.rb +43 -105
- data/macros/html/inline.rb +11 -12
- data/macros/html/structure.rb +123 -58
- data/macros/xml.rb +33 -0
- data/spec/files/container.textile +2 -2
- data/spec/files/document.glyph +2 -2
- data/spec/files/document_with_toc.glyph +3 -3
- data/spec/files/included.textile +1 -1
- data/spec/files/ligature.jpg +0 -0
- data/spec/files/markdown.markdown +2 -1
- data/spec/lib/commands_spec.rb +46 -3
- data/spec/lib/document_spec.rb +4 -4
- data/spec/lib/glyph_spec.rb +17 -46
- data/spec/lib/interpreter_spec.rb +6 -25
- data/spec/lib/macro_spec.rb +141 -43
- data/spec/lib/macro_validators_spec.rb +27 -5
- data/spec/lib/node_spec.rb +26 -1
- data/spec/lib/parser_spec.rb +246 -0
- data/spec/lib/syntax_node_spec.rb +111 -0
- data/spec/macros/core_spec.rb +195 -0
- data/spec/macros/filters_spec.rb +38 -4
- data/spec/macros/macros_spec.rb +20 -176
- data/spec/macros/textile_spec.rb +13 -71
- data/spec/macros/xml_spec.rb +77 -0
- data/spec/spec_helper.rb +50 -10
- data/spec/tasks/load_spec.rb +13 -2
- data/styles/default.css +18 -6
- data/styles/pagination.css +1 -19
- data/tasks/generate.rake +2 -2
- data/tasks/load.rake +27 -17
- data/tasks/project.rake +1 -1
- metadata +75 -62
- data/book/script/compile.rb +0 -8
- data/book/script/prof +0 -1
- data/book/script/prof_results.htm +0 -21079
- data/book/text/authoring.glyph +0 -548
- data/book/text/extending.glyph +0 -224
- data/book/text/getting_started.glyph +0 -158
- data/book/text/troubleshooting.glyph +0 -179
- data/lib/glyph/glyph_language.rb +0 -538
- data/lib/glyph/glyph_language.treetop +0 -27
- data/macros/common.rb +0 -160
data/macros/html/block.rb
CHANGED
@@ -2,133 +2,90 @@
|
|
2
2
|
|
3
3
|
macro :note do
|
4
4
|
%{<div class="#{@name}">
|
5
|
-
<span class="note-title">#{@name.to_s.capitalize}</span>#{
|
5
|
+
<span class="note-title">#{@name.to_s.capitalize}</span>#{value}
|
6
6
|
|
7
7
|
</div>}
|
8
8
|
end
|
9
9
|
|
10
10
|
macro :box do
|
11
|
-
exact_parameters 2
|
11
|
+
exact_parameters 2
|
12
12
|
%{<div class="box">
|
13
|
-
<div class="box-title">#{
|
14
|
-
#{
|
13
|
+
<div class="box-title">#{param(0)}</div>
|
14
|
+
#{param(1)}
|
15
15
|
|
16
16
|
</div>}
|
17
17
|
end
|
18
18
|
|
19
|
-
macro :
|
20
|
-
|
19
|
+
macro :codeblock do
|
20
|
+
exact_parameters 1
|
21
21
|
%{
|
22
22
|
<div class="code">
|
23
23
|
<pre>
|
24
24
|
<code>
|
25
|
-
#{
|
25
|
+
#{value}
|
26
26
|
</code>
|
27
27
|
</pre>
|
28
28
|
</div>}
|
29
29
|
end
|
30
30
|
|
31
|
-
macro :
|
32
|
-
min_parameters 2
|
33
|
-
lang = params[0]
|
34
|
-
text = raw_params[1..raw_params.length-1].join '\\|'
|
35
|
-
text.gsub!(/\\(.)/){$1}
|
36
|
-
highlighter = Glyph["highlighters.current"].to_sym rescue nil
|
37
|
-
if !highlighter then
|
38
|
-
begin
|
39
|
-
require 'coderay'
|
40
|
-
highlighter = :coderay
|
41
|
-
rescue LoadError
|
42
|
-
begin
|
43
|
-
require 'uv'
|
44
|
-
highlighter = :ultraviolet
|
45
|
-
rescue LoadError
|
46
|
-
macro_error "No highlighter installed. Please run: gem install coderay"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
Glyph["highlighter.current"] = highlighter
|
50
|
-
end
|
51
|
-
target = Glyph["highlighters.target"]
|
52
|
-
result = ""
|
53
|
-
case highlighter.to_sym
|
54
|
-
when :coderay
|
55
|
-
begin
|
56
|
-
require 'coderay'
|
57
|
-
result = CodeRay.scan(text, lang).div(Glyph["highlighters.coderay"])
|
58
|
-
rescue LoadError
|
59
|
-
macro_error "CodeRay highlighter not installed. Please run: gem install coderay"
|
60
|
-
rescue Exception => e
|
61
|
-
macro_error e.message
|
62
|
-
end
|
63
|
-
when :ultraviolet
|
64
|
-
begin
|
65
|
-
require 'uv'
|
66
|
-
target = 'xhtml' if target == 'html'
|
67
|
-
result = Uv.parse(text.to_s, target.to_s, lang.to_s,
|
68
|
-
Glyph["highlighters.ultraviolet.line_numbers"],
|
69
|
-
Glyph["highlighters.ultraviolet.theme"].to_s)
|
70
|
-
rescue LoadError
|
71
|
-
macro_error "UltraViolet highlighter not installed. Please run: gem install ultraviolet"
|
72
|
-
rescue Exception => e
|
73
|
-
puts e.backtrace
|
74
|
-
macro_error e.message
|
75
|
-
end
|
76
|
-
else
|
77
|
-
macro_error "No highlighter installed. Please run: gem install coderay"
|
78
|
-
end
|
79
|
-
result
|
80
|
-
end
|
81
|
-
|
82
|
-
macro :title do
|
83
|
-
no_parameters
|
84
|
-
%{<h1>
|
85
|
-
#{Glyph["document.title"]}
|
86
|
-
</h1>}
|
87
|
-
end
|
88
|
-
|
89
|
-
macro :img do
|
31
|
+
macro :image do
|
90
32
|
min_parameters 1
|
91
33
|
max_parameters 3
|
92
|
-
image =
|
93
|
-
|
34
|
+
image = param(0)
|
35
|
+
alt = "@alt[-]" unless attr(:alt)
|
94
36
|
source_file = Glyph.lite? ? image : Glyph::PROJECT/"images/#{image}"
|
95
37
|
dest_file = Glyph.lite? ? image : "images/#{image}"
|
96
|
-
w = (width) ? "width=\"#{width}\"" : ''
|
97
|
-
height = params[2]
|
98
|
-
h = (height) ? "height=\"#{height}\"" : ''
|
99
38
|
Glyph.warning "Image '#{image}' not found" unless Pathname.new(dest_file).exist?
|
100
|
-
|
39
|
+
interpret "img[#{alt}@src[#{dest_file}]#{@node.attrs.join}]"
|
101
40
|
end
|
102
41
|
|
103
|
-
macro :
|
42
|
+
macro :figure do
|
104
43
|
min_parameters 1
|
105
44
|
max_parameters 2
|
106
|
-
image =
|
107
|
-
|
108
|
-
caption
|
109
|
-
caption =
|
45
|
+
image = param(0)
|
46
|
+
alt = "@alt[-]" unless attr(:alt)
|
47
|
+
caption = param(1) rescue nil
|
48
|
+
caption = "div[@class[caption]#{caption}]" if caption
|
110
49
|
source_file = Glyph.lite? ? image : Glyph::PROJECT/"images/#{image}"
|
111
50
|
dest_file = Glyph.lite? ? image : "images/#{image}"
|
112
51
|
Glyph.warning "Figure '#{image}' not found" unless Pathname.new(dest_file).exist?
|
113
|
-
%{
|
114
|
-
|
52
|
+
interpret %{div[@class[figure]
|
53
|
+
img[#{alt}@src[#{dest_file}]#{@node.attrs.join}]
|
115
54
|
#{caption}
|
116
|
-
|
55
|
+
]}
|
117
56
|
end
|
118
57
|
|
58
|
+
macro :title do
|
59
|
+
no_parameters
|
60
|
+
unless Glyph["document.title"].blank? then
|
61
|
+
%{<h1>
|
62
|
+
#{Glyph["document.title"]}
|
63
|
+
</h1>}
|
64
|
+
else
|
65
|
+
""
|
66
|
+
end
|
67
|
+
end
|
119
68
|
|
120
69
|
macro :subtitle do
|
121
70
|
no_parameters
|
71
|
+
unless Glyph["document.subtitle"].blank? then
|
122
72
|
%{<h2>
|
123
73
|
#{Glyph["document.subtitle"]}
|
124
74
|
</h2>}
|
75
|
+
else
|
76
|
+
""
|
77
|
+
end
|
125
78
|
end
|
126
79
|
|
127
80
|
macro :author do
|
128
81
|
no_parameters
|
82
|
+
unless Glyph['document.author'].blank? then
|
129
83
|
%{<div class="author">
|
130
84
|
by <em>#{Glyph["document.author"]}</em>
|
131
85
|
</div>}
|
86
|
+
else
|
87
|
+
""
|
88
|
+
end
|
132
89
|
end
|
133
90
|
|
134
91
|
macro :pubdate do
|
@@ -138,31 +95,12 @@ macro :pubdate do
|
|
138
95
|
</div>}
|
139
96
|
end
|
140
97
|
|
141
|
-
macro :
|
142
|
-
|
143
|
-
%{<
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
macro :tr do
|
149
|
-
exact_parameters 1, :level => :warning
|
150
|
-
%{<tr>
|
151
|
-
#{@value}
|
152
|
-
</tr>}
|
153
|
-
end
|
154
|
-
|
155
|
-
macro :td do
|
156
|
-
exact_parameters 1, :level => :warning
|
157
|
-
%{<td>
|
158
|
-
#{@value}
|
159
|
-
|
160
|
-
</td>}
|
161
|
-
end
|
162
|
-
|
163
|
-
macro :th do
|
164
|
-
exact_parameters 1, :level => :warning
|
165
|
-
%{<th>#{@value}</th>}
|
98
|
+
macro :revision do
|
99
|
+
unless Glyph["document.revision"].blank? then
|
100
|
+
%{<div class="revision">#{Glyph['document.revision']}</div>}
|
101
|
+
else
|
102
|
+
""
|
103
|
+
end
|
166
104
|
end
|
167
105
|
|
168
106
|
macro_alias :important => :note
|
data/macros/html/inline.rb
CHANGED
@@ -3,20 +3,18 @@
|
|
3
3
|
macro :anchor do
|
4
4
|
min_parameters 1
|
5
5
|
max_parameters 2
|
6
|
-
ident
|
6
|
+
ident = param(0)
|
7
|
+
title = param(1) rescue nil
|
7
8
|
macro_error "Bookmark '#{ident}' already exists" if bookmark? ident
|
8
9
|
bookmark :id => ident, :title => title
|
9
10
|
%{<a id="#{ident}">#{title}</a>}
|
10
11
|
end
|
11
12
|
|
12
|
-
macro :codeph do
|
13
|
-
%{<code>#@value</code>}
|
14
|
-
end
|
15
|
-
|
16
13
|
macro :link do
|
17
14
|
min_parameters 1
|
18
15
|
max_parameters 2
|
19
|
-
href
|
16
|
+
href = param(0)
|
17
|
+
title = param(1) rescue nil
|
20
18
|
if href.match /^#/ then
|
21
19
|
anchor = href.gsub(/^#/, '').to_sym
|
22
20
|
bmk = bookmark? anchor
|
@@ -31,12 +29,13 @@ macro :link do
|
|
31
29
|
end
|
32
30
|
end
|
33
31
|
title ||= href
|
34
|
-
%{<a href="#{href}">#{title}</a>}
|
32
|
+
%{<a href="#{href}">#{title.to_s}</a>}
|
35
33
|
end
|
36
34
|
|
37
35
|
macro :fmi do
|
38
36
|
exact_parameters 2, :level => :warning
|
39
|
-
topic
|
37
|
+
topic = param(0)
|
38
|
+
href = param(1)
|
40
39
|
link = placeholder do |document|
|
41
40
|
interpret "link[#{href}]"
|
42
41
|
end
|
@@ -45,18 +44,18 @@ end
|
|
45
44
|
|
46
45
|
macro :draftcomment do
|
47
46
|
if Glyph['document.draft'] then
|
48
|
-
%{<span class="comment"><span class="comment-pre"><strong>Comment:</strong> </span>#{
|
47
|
+
%{<span class="comment"><span class="comment-pre"><strong>Comment:</strong> </span>#{value}</span>}
|
49
48
|
else
|
50
49
|
""
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
53
|
macro :todo do
|
55
|
-
|
56
|
-
todo =
|
54
|
+
exact_parameters 1
|
55
|
+
todo = {:source => @source, :text => value}
|
57
56
|
@node[:document].todos << todo unless @node[:document].todos.include? todo
|
58
57
|
if Glyph['document.draft'] then
|
59
|
-
%{<span class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>#{
|
58
|
+
%{<span class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>#{value}</span>}
|
60
59
|
else
|
61
60
|
""
|
62
61
|
end
|
data/macros/html/structure.rb
CHANGED
@@ -1,67 +1,127 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
macro :
|
4
|
-
exact_parameters 1
|
5
|
-
|
6
|
-
|
3
|
+
macro :section do
|
4
|
+
exact_parameters 1
|
5
|
+
h = ""
|
6
|
+
h_title = attr :title
|
7
|
+
h_id = attr :id
|
8
|
+
h_notoc = attr :notoc
|
9
|
+
macro_warning "Please specify a title for section ##{h_id}" if h_id && !h_title
|
10
|
+
if h_title then
|
11
|
+
level = 1
|
12
|
+
@node.ascend do |n|
|
13
|
+
if n.is_a?(Glyph::MacroNode) && Glyph["system.structure.headers"].include?(n[:name]) then
|
14
|
+
level+=1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
h_id ||= "h_#{@node[:document].headers.length+1}"
|
18
|
+
h_id = h_id.to_sym
|
19
|
+
header :title => h_title, :level => level, :id => h_id, :notoc => h_notoc
|
20
|
+
@node[:header] = h_id
|
21
|
+
macro_error "Bookmark '#{h_id}' already exists" if bookmark? h_id
|
22
|
+
bookmark :id => h_id, :title => h_title
|
23
|
+
h = %{<h#{level} id="#{h_id}">#{h_title}</h#{level}>\n}
|
24
|
+
end
|
25
|
+
%{<div class="#{@name}">
|
26
|
+
#{h}#{value}
|
7
27
|
|
8
28
|
</div>}
|
9
29
|
end
|
10
30
|
|
11
|
-
macro :
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
macro :article do
|
32
|
+
exact_parameters 1
|
33
|
+
head = raw_attr(:head)
|
34
|
+
head ||= %{style[default.css]}
|
35
|
+
pre_title = raw_attr(:"pre-title")
|
36
|
+
post_title = raw_attr(:"post-title")
|
37
|
+
pubdate = @node.attr(:pubdate) ? "div[@class[pubdate]#{@node.attr(:pubdate).contents}]" : "pubdate[]"
|
38
|
+
halftitlepage = raw_attr(:halftitlepage)
|
39
|
+
halftitlepage ||= %{
|
40
|
+
#{pre_title}
|
41
|
+
title[]
|
42
|
+
subtitle[]
|
43
|
+
author[]
|
44
|
+
#{pubdate}
|
45
|
+
#{post_title}
|
46
|
+
}
|
47
|
+
interpret %{document[
|
48
|
+
head[#{head}]
|
49
|
+
body[
|
50
|
+
halftitlepage[
|
51
|
+
#{halftitlepage}
|
52
|
+
]
|
53
|
+
#{@node.value}
|
54
|
+
]
|
55
|
+
]}
|
56
|
+
end
|
57
|
+
|
58
|
+
macro :book do
|
59
|
+
no_parameters
|
60
|
+
head = raw_attr(:head)
|
61
|
+
head ||= %{style[default.css]}
|
62
|
+
pre_title = raw_attr(:"pre-title")
|
63
|
+
post_title = raw_attr(:"post-title")
|
64
|
+
titlepage = raw_attr(:titlepage)
|
65
|
+
pubdate = @node.attr(:pubdate) ? "div[@class[pubdate]#{@node.attr(:pubdate).contents}]" : "pubdate[]"
|
66
|
+
titlepage ||= %{
|
67
|
+
#{pre_title}
|
68
|
+
title[]
|
69
|
+
subtitle[]
|
70
|
+
revision[]
|
71
|
+
author[]
|
72
|
+
#{pubdate}
|
73
|
+
#{post_title}
|
74
|
+
}
|
75
|
+
frontmatter = raw_attr(:frontmatter)
|
76
|
+
bodymatter = raw_attr(:bodymatter)
|
77
|
+
backmatter = raw_attr(:backmatter)
|
78
|
+
frontmatter = "frontmatter[\n#{frontmatter}\n]" if frontmatter
|
79
|
+
bodymatter = "bodymatter[\n#{bodymatter}\n]" if bodymatter
|
80
|
+
backmatter = "backmatter[\n#{backmatter}\n]" if backmatter
|
81
|
+
interpret %{document[
|
82
|
+
head[#{head}]
|
83
|
+
body[
|
84
|
+
titlepage[
|
85
|
+
#{titlepage}
|
86
|
+
]
|
87
|
+
#{frontmatter}
|
88
|
+
#{bodymatter}
|
89
|
+
#{backmatter}
|
90
|
+
]
|
91
|
+
]}
|
29
92
|
end
|
30
93
|
|
94
|
+
|
31
95
|
macro :document do
|
32
|
-
exact_parameters 1
|
96
|
+
exact_parameters 1
|
33
97
|
%{<?xml version="1.0" encoding="utf-8"?>
|
34
98
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
35
99
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
36
|
-
#{
|
100
|
+
#{value}
|
37
101
|
|
38
102
|
</html>}
|
39
103
|
end
|
40
104
|
|
41
|
-
macro :body do
|
42
|
-
exact_parameters 1, :level => :warning
|
43
|
-
%{<body>
|
44
|
-
#{@value}
|
45
|
-
|
46
|
-
</body>}
|
47
|
-
end
|
48
|
-
|
49
105
|
macro :head do
|
50
|
-
exact_parameters 1
|
106
|
+
exact_parameters 1
|
107
|
+
author = Glyph['document.author'].blank? ? "" : %{<meta name="author" content="#{Glyph["document.author"]}" />
|
108
|
+
}
|
109
|
+
copy = Glyph['document.author'].blank? ? "" : %{<meta name="copyright" content="#{Glyph["document.author"]}" />}
|
51
110
|
%{<head>
|
52
111
|
<title>#{Glyph["document.title"]}</title>
|
53
|
-
|
54
|
-
|
112
|
+
#{author}
|
113
|
+
#{copy}
|
55
114
|
<meta name="generator" content="Glyph v#{Glyph::VERSION} (http://www.h3rald.com/glyph)" />
|
56
|
-
#{
|
115
|
+
#{value}
|
57
116
|
</head>
|
58
117
|
}
|
59
118
|
end
|
60
119
|
|
61
120
|
macro :style do
|
62
|
-
|
63
|
-
file = Pathname.new Glyph::
|
64
|
-
|
121
|
+
exact_parameters 1
|
122
|
+
file = Glyph.lite? ? Pathname.new(value) : Glyph::PROJECT/"styles/#{value}"
|
123
|
+
file = Pathname.new Glyph::HOME/'styles'/value unless file.exist?
|
124
|
+
macro_error "Stylesheet '#{value}' not found" unless file.exist?
|
65
125
|
style = ""
|
66
126
|
case file.extname
|
67
127
|
when ".css"
|
@@ -84,23 +144,29 @@ macro :style do
|
|
84
144
|
end
|
85
145
|
|
86
146
|
macro :toc do
|
87
|
-
|
147
|
+
max_parameters 1
|
148
|
+
depth = param 0
|
88
149
|
link_header = lambda do |header|
|
89
|
-
%{<a href="##{header[:id]}">#{header[:title]
|
150
|
+
%{<a href="##{header[:id]}">#{header[:title]}</a>}
|
90
151
|
end
|
91
152
|
toc = placeholder do |document|
|
92
153
|
descend_section = lambda do |n1, added_headers|
|
93
154
|
list = ""
|
94
155
|
added_headers ||= []
|
95
156
|
n1.descend do |n2, level|
|
96
|
-
if Glyph['structure.headers'].include?(n2[:
|
97
|
-
next if n2.find_parent{|node| Glyph['structure.special'].include? node[:
|
98
|
-
header_id = n2
|
157
|
+
if n2.is_a?(Glyph::MacroNode) && Glyph['system.structure.headers'].include?(n2[:name]) then
|
158
|
+
next if n2.find_parent{|node| Glyph['system.structure.special'].include? node[:name] }
|
159
|
+
header_id = n2[:header]
|
160
|
+
header_hash = document.header?(header_id)
|
161
|
+
next if depth && header_hash && (header_hash[:level]-1 > depth.to_i) || header_hash && header_hash[:notoc]
|
99
162
|
next if added_headers.include? header_id
|
100
163
|
added_headers << header_id
|
101
164
|
# Check if part of frontmatter, bodymatter or backmatter
|
102
|
-
container = n2.find_parent
|
103
|
-
|
165
|
+
container = n2.find_parent do |node|
|
166
|
+
node.is_a?(Glyph::MacroNode) &&
|
167
|
+
node[:name].in?([:frontmatter, :bodymatter, :appendix, :backmatter])
|
168
|
+
end[:name] rescue nil
|
169
|
+
list << "<li class=\"#{container} #{n2[:name]}\">#{link_header.call(header_hash)}</li>\n" if header_id
|
104
170
|
child_list = ""
|
105
171
|
n2.children.each do |c|
|
106
172
|
child_list << descend_section.call(c, added_headers)
|
@@ -110,8 +176,9 @@ macro :toc do
|
|
110
176
|
end
|
111
177
|
list
|
112
178
|
end
|
179
|
+
toc_title = attr(:title) || "Table of Contents"
|
113
180
|
%{<div class="contents">
|
114
|
-
<h2 class="toc-header" id="h_toc"
|
181
|
+
<h2 class="toc-header" id="h_toc">#{toc_title}</h2>
|
115
182
|
<ol class="toc">
|
116
183
|
#{descend_section.call(document.structure, nil)}
|
117
184
|
</ol>
|
@@ -124,15 +191,13 @@ end
|
|
124
191
|
# http://microformats.org/wiki/book-brainstorming
|
125
192
|
# http://en.wikipedia.org/wiki/Book_design
|
126
193
|
|
127
|
-
|
128
|
-
|
129
|
-
(Glyph['structure.frontmatter'] + Glyph['structure.bodymatter'] + Glyph['structure.backmatter']).
|
130
|
-
each {|s| macro_alias s => :div }
|
194
|
+
(Glyph['system.structure.frontmatter'] + Glyph['system.structure.bodymatter'] + Glyph['system.structure.backmatter']).
|
195
|
+
each {|s| macro_alias s => :section }
|
131
196
|
|
132
|
-
macro_alias :frontcover => :
|
133
|
-
macro_alias :titlepage => :
|
134
|
-
macro_alias :halftitlepage => :
|
135
|
-
macro_alias :frontmatter => :
|
136
|
-
macro_alias :bodymatter => :
|
137
|
-
macro_alias :backmatter => :
|
138
|
-
macro_alias :backcover => :
|
197
|
+
macro_alias :frontcover => :section
|
198
|
+
macro_alias :titlepage => :section
|
199
|
+
macro_alias :halftitlepage => :section
|
200
|
+
macro_alias :frontmatter => :section
|
201
|
+
macro_alias :bodymatter => :section
|
202
|
+
macro_alias :backmatter => :section
|
203
|
+
macro_alias :backcover => :section
|