glyph 0.3.0 → 0.4.0
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 +7 -0
- data/AUTHORS.textile +8 -7
- data/CHANGELOG.textile +89 -8
- data/LICENSE.textile +1 -2
- data/README.textile +89 -61
- data/Rakefile +12 -10
- data/VERSION +1 -1
- data/benchmark.rb +1 -1
- data/book/config.yml +18 -4
- data/book/document.glyph +269 -45
- data/book/images/glyph/commands_tasks.png +0 -0
- data/book/images/{document_generation.png → glyph/document_generation.png} +0 -0
- data/book/images/glyph/glyph.eps +123 -0
- data/book/images/glyph/glyph.png +0 -0
- data/book/images/glyph/glyph.svg +29 -0
- data/book/lib/commands/commands.rb +11 -0
- data/book/lib/layouts/bookindex.glyph +127 -0
- data/book/lib/layouts/bookpage.glyph +129 -0
- data/book/lib/layouts/project.glyph +26 -0
- data/book/lib/macros/reference.rb +27 -7
- data/book/lib/tasks/tasks.rake +52 -0
- data/book/snippets.yml +1 -1
- data/book/text/{acknowledgement.glyph → acknowledgements.glyph} +4 -2
- data/book/text/changelog.glyph +29 -3
- data/book/text/compiling/compiling.glyph +44 -20
- data/book/text/compiling/lite_mode.glyph +0 -4
- data/book/text/compiling/programmatic_usage.glyph +1 -5
- data/book/text/config/document.glyph +35 -0
- data/book/text/config/filters.glyph +28 -0
- data/book/text/config/options.glyph +25 -0
- data/book/text/config/output.glyph +83 -0
- data/book/text/extending/bookmarks_headers.glyph +0 -5
- data/book/text/extending/command.glyph +56 -0
- data/book/text/extending/commands_tasks.glyph +39 -0
- data/book/text/extending/further_reading.glyph +0 -3
- data/book/text/extending/internals.glyph +3 -5
- data/book/text/extending/interpreting.glyph +0 -4
- data/book/text/extending/layouts.glyph +68 -0
- data/book/text/extending/macro_def.glyph +0 -5
- data/book/text/extending/output_format.glyph +78 -0
- data/book/text/extending/params_attrs.glyph +0 -3
- data/book/text/extending/placeholders.glyph +0 -4
- data/book/text/extending/task.glyph +46 -0
- data/book/text/extending/validators.glyph +5 -6
- data/book/text/getting_started/configuration.glyph +1 -5
- data/book/text/getting_started/create_project.glyph +1 -5
- data/book/text/getting_started/structure.glyph +0 -4
- data/book/text/introduction.glyph +100 -75
- data/book/text/license.glyph +1 -2
- data/book/text/macros/macros_block.glyph +8 -4
- data/book/text/macros/macros_core.glyph +0 -3
- data/book/text/macros/macros_filters.glyph +2 -7
- data/book/text/macros/macros_inline.glyph +0 -4
- data/book/text/macros/macros_structure.glyph +0 -4
- data/book/text/ref_commands.glyph +29 -7
- data/book/text/stats/bookmarks.glyph +49 -0
- data/book/text/stats/links.glyph +90 -0
- data/book/text/stats/macros.glyph +73 -0
- data/book/text/stats/snippets.glyph +50 -0
- data/book/text/stats/stats.glyph +79 -0
- data/book/text/text_editing/attribute_intro.glyph +22 -0
- data/book/text/text_editing/code.glyph +0 -5
- data/book/text/text_editing/conditionals.glyph +0 -4
- data/book/text/text_editing/esc_quot.glyph +64 -0
- data/book/text/text_editing/evaluation.glyph +0 -3
- data/book/text/text_editing/glyph_files.glyph +0 -3
- data/book/text/text_editing/images.glyph +0 -5
- data/book/text/text_editing/inclusions.glyph +0 -4
- data/book/text/text_editing/links.glyph +2 -7
- data/book/text/text_editing/macro_intro.glyph +1 -98
- data/book/text/text_editing/raw_html.glyph +0 -87
- data/book/text/text_editing/section_aliases.glyph +28 -0
- data/book/text/text_editing/sections.glyph +1 -32
- data/book/text/text_editing/stylesheets.glyph +3 -5
- data/book/text/text_editing/topics.glyph +33 -0
- data/book/text/text_editing/xml_fallback.glyph +73 -0
- data/book/text/troubleshooting/errors_command.glyph +0 -3
- data/book/text/troubleshooting/errors_generic.glyph +21 -6
- data/book/text/troubleshooting/errors_macro.glyph +11 -8
- data/book/text/troubleshooting/errors_parser.glyph +0 -3
- data/config.yml +60 -25
- data/glyph.gemspec +90 -36
- data/layouts/web/index.glyph +16 -0
- data/layouts/web/topic.glyph +15 -0
- data/layouts/web5/index.glyph +16 -0
- data/layouts/web5/topic.glyph +17 -0
- data/lib/glyph.rb +36 -49
- data/lib/glyph/analyzer.rb +253 -0
- data/lib/glyph/bookmark.rb +92 -0
- data/lib/glyph/commands.rb +9 -221
- data/lib/glyph/commands/add.rb +8 -0
- data/lib/glyph/commands/compile.rb +93 -0
- data/lib/glyph/commands/config.rb +38 -0
- data/lib/glyph/commands/init.rb +6 -0
- data/lib/glyph/commands/outline.rb +45 -0
- data/lib/glyph/commands/stats.rb +48 -0
- data/lib/glyph/commands/todo.rb +29 -0
- data/lib/glyph/config.rb +2 -0
- data/lib/glyph/document.rb +61 -30
- data/lib/glyph/interpreter.rb +2 -2
- data/lib/glyph/macro.rb +14 -5
- data/lib/glyph/macro_helpers.rb +280 -0
- data/lib/glyph/macro_validators.rb +37 -2
- data/lib/glyph/reporter.rb +182 -0
- data/lib/glyph/syntax_node.rb +37 -10
- data/lib/glyph/system_extensions.rb +8 -45
- data/lib/glyph/utils.rb +148 -0
- data/macros/core.rb +10 -15
- data/macros/filters.rb +4 -5
- data/macros/html/block.rb +46 -30
- data/macros/html/inline.rb +9 -35
- data/macros/html/structure.rb +59 -72
- data/macros/html5/block.rb +69 -0
- data/macros/html5/inline.rb +24 -0
- data/macros/html5/structure.rb +139 -0
- data/macros/xml.rb +1 -1
- data/spec/files/custom_command.rb +6 -0
- data/spec/files/custom_tasks.rake +6 -0
- data/spec/files/document_for_stats.glyph +12 -0
- data/spec/files/references.glyph +4 -0
- data/spec/files/web1.glyph +11 -0
- data/spec/files/web2.glyph +10 -0
- data/spec/files/web_doc.glyph +23 -0
- data/spec/lib/analyzer_spec.rb +137 -0
- data/spec/lib/bookmark_spec.rb +64 -0
- data/spec/lib/commands_spec.rb +30 -5
- data/spec/lib/document_spec.rb +49 -9
- data/spec/lib/glyph_spec.rb +21 -1
- data/spec/lib/macro_spec.rb +6 -6
- data/spec/lib/macro_validators_spec.rb +24 -0
- data/spec/lib/reporter_spec.rb +132 -0
- data/spec/macros/core_spec.rb +2 -3
- data/spec/macros/filters_spec.rb +2 -2
- data/spec/macros/html5_spec.rb +101 -0
- data/spec/macros/macros_spec.rb +16 -6
- data/spec/macros/web5_spec.rb +32 -0
- data/spec/macros/web_spec.rb +59 -0
- data/spec/macros/xml_spec.rb +1 -1
- data/spec/spec_helper.rb +24 -4
- data/spec/tasks/generate_spec.rb +54 -0
- data/spec/tasks/load_spec.rb +29 -3
- data/spec/tasks/project_spec.rb +21 -3
- data/styles/default.css +40 -4
- data/styles/pagination.css +59 -41
- data/tasks/generate.rake +110 -31
- data/tasks/load.rake +39 -7
- data/tasks/project.rake +9 -7
- metadata +115 -34
- data/book/images/glyph.png +0 -0
- data/book/images/glyph.svg +0 -351
- data/book/output/html/glyph.html +0 -4482
- data/book/output/html/images/document_generation.png +0 -0
- data/book/output/html/images/glyph.png +0 -0
- data/book/output/html/images/glyph.svg +0 -351
- data/book/output/pdf/glyph.pdf +4 -10254
- data/book/script/authors +0 -1
- data/book/script/changelog +0 -1
- data/book/script/license +0 -1
- data/book/script/readme +0 -1
- data/book/text/ref_config.glyph +0 -100
- data/book/text/ref_macros.glyph +0 -6
- data/book/text/troubleshooting/errors_intro.glyph +0 -3
data/macros/core.rb
CHANGED
|
@@ -69,7 +69,7 @@ macro :include do
|
|
|
69
69
|
macro_warning e.message, e
|
|
70
70
|
end
|
|
71
71
|
else
|
|
72
|
-
if Glyph["
|
|
72
|
+
if Glyph["options.filter_by_file_extension"] && !ext.in?(['rb','glyph']) then
|
|
73
73
|
if Glyph::MACROS.include?(ext.to_sym) then
|
|
74
74
|
contents = "#{ext}[#{contents}]"
|
|
75
75
|
else
|
|
@@ -77,7 +77,9 @@ macro :include do
|
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
begin
|
|
80
|
-
|
|
80
|
+
folder = Glyph.lite? ? "" : "text/"
|
|
81
|
+
topic = (attr(:topic) && Glyph.multiple_output_files?) ? folder+v : nil
|
|
82
|
+
update_source v, folder+v, topic
|
|
81
83
|
interpret contents
|
|
82
84
|
rescue Glyph::MutualInclusionError => e
|
|
83
85
|
raise
|
|
@@ -135,18 +137,21 @@ macro :condition do
|
|
|
135
137
|
end
|
|
136
138
|
|
|
137
139
|
macro :eq do
|
|
140
|
+
within :condition
|
|
138
141
|
min_parameters 1
|
|
139
142
|
max_parameters 2
|
|
140
143
|
(param(0).to_s == param(1).to_s) ? true : nil
|
|
141
144
|
end
|
|
142
145
|
|
|
143
146
|
macro :not do
|
|
147
|
+
within :condition
|
|
144
148
|
max_parameters 1
|
|
145
149
|
v = param(0).to_s
|
|
146
150
|
(v.blank? || v == "false") ? true : nil
|
|
147
151
|
end
|
|
148
152
|
|
|
149
153
|
macro :and do
|
|
154
|
+
within :condition
|
|
150
155
|
min_parameters 1
|
|
151
156
|
max_parameters 2
|
|
152
157
|
res_a = !param(0).blank?
|
|
@@ -155,6 +160,7 @@ macro :and do
|
|
|
155
160
|
end
|
|
156
161
|
|
|
157
162
|
macro :or do
|
|
163
|
+
within :condition
|
|
158
164
|
min_parameters 1
|
|
159
165
|
max_parameters 2
|
|
160
166
|
res_a = !param(0).blank?
|
|
@@ -163,6 +169,7 @@ macro :or do
|
|
|
163
169
|
end
|
|
164
170
|
|
|
165
171
|
macro :match do
|
|
172
|
+
within :condition
|
|
166
173
|
exact_parameters 2
|
|
167
174
|
val = param(0).to_s
|
|
168
175
|
regexp = param(1).to_s
|
|
@@ -184,19 +191,7 @@ macro "rewrite:" do
|
|
|
184
191
|
macro_error "Macro '#{macro_name}' cannot be defined by itself"
|
|
185
192
|
end
|
|
186
193
|
end
|
|
187
|
-
|
|
188
|
-
Glyph.macro macro_name do
|
|
189
|
-
s = string.dup
|
|
190
|
-
# Parameters
|
|
191
|
-
s.gsub!(/\{\{(\d+)\}\}/) do
|
|
192
|
-
raw_param($1.to_i).strip
|
|
193
|
-
end
|
|
194
|
-
# Attributes
|
|
195
|
-
s.gsub!(/\{\{([^\[\]\|\\\s]+)\}\}/) do
|
|
196
|
-
raw_attr($1.to_sym).strip
|
|
197
|
-
end
|
|
198
|
-
interpret s
|
|
199
|
-
end
|
|
194
|
+
Glyph.rewrite macro_name, raw_param(1).dup
|
|
200
195
|
nil
|
|
201
196
|
end
|
|
202
197
|
|
data/macros/filters.rb
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
macro :textile do
|
|
4
4
|
exact_parameters 1
|
|
5
|
-
rc = nil
|
|
6
5
|
begin
|
|
7
6
|
require 'RedCloth'
|
|
8
|
-
rc = RedCloth.new value, Glyph::CONFIG.get("filters.redcloth.restrictions")
|
|
9
7
|
rescue Exception
|
|
10
8
|
macro_error "RedCloth gem not installed. Please run: gem install RedCloth"
|
|
11
9
|
end
|
|
12
|
-
|
|
10
|
+
rc = RedCloth.new value, Glyph::CONFIG.get("filters.redcloth.restrictions")
|
|
11
|
+
target = Glyph["output.#{Glyph['document.output']}.filter_target"]
|
|
13
12
|
case target.to_sym
|
|
14
13
|
when :html
|
|
15
14
|
rc.to_html.gsub /<p><\/p>/, ''
|
|
@@ -63,7 +62,7 @@ macro :markdown do
|
|
|
63
62
|
else
|
|
64
63
|
macro_error "No supported MarkDown converter installed. Please run: gem install bluecloth"
|
|
65
64
|
end
|
|
66
|
-
target = Glyph["
|
|
65
|
+
target = Glyph["output.#{Glyph['document.output']}.filter_target"]
|
|
67
66
|
if target.to_sym == :html then
|
|
68
67
|
md.to_html
|
|
69
68
|
else
|
|
@@ -98,7 +97,7 @@ macro :highlight do
|
|
|
98
97
|
end
|
|
99
98
|
end
|
|
100
99
|
Glyph["highlighter.current"] = highlighter
|
|
101
|
-
target = Glyph["
|
|
100
|
+
target = Glyph["output.#{Glyph['document.output']}.filter_target"]
|
|
102
101
|
result = ""
|
|
103
102
|
case highlighter.to_sym
|
|
104
103
|
when :coderay
|
data/macros/html/block.rb
CHANGED
|
@@ -33,10 +33,9 @@ macro :image do
|
|
|
33
33
|
max_parameters 3
|
|
34
34
|
image = param(0)
|
|
35
35
|
alt = "@alt[-]" unless attr(:alt)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
interpret "img[#{alt}@src[#{dest_file}]#{@node.attrs.join}]"
|
|
36
|
+
image_element_for image, alt do |alt, dest_file|
|
|
37
|
+
interpret "img[#{alt}@src[#{Glyph["output.#{Glyph['document.output']}.base"]}#{dest_file}]#{@node.attrs.join}]"
|
|
38
|
+
end
|
|
40
39
|
end
|
|
41
40
|
|
|
42
41
|
macro :figure do
|
|
@@ -44,47 +43,39 @@ macro :figure do
|
|
|
44
43
|
max_parameters 2
|
|
45
44
|
image = param(0)
|
|
46
45
|
alt = "@alt[-]" unless attr(:alt)
|
|
47
|
-
caption = param(1) rescue nil
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
interpret %{div[@class[figure]
|
|
53
|
-
img[#{alt}@src[#{dest_file}]#{@node.attrs.join}]
|
|
54
|
-
#{caption}
|
|
46
|
+
caption = "div[@class[caption]#{param(1)}]" rescue nil
|
|
47
|
+
figure_element_for image, alt, caption do |alt, dest_file, caption|
|
|
48
|
+
interpret %{div[@class[figure]
|
|
49
|
+
img[#{alt}@src[#{Glyph["output.#{Glyph['document.output']}.base"]}#{dest_file}]#{@node.attrs.join}]
|
|
50
|
+
#{caption}
|
|
55
51
|
]}
|
|
52
|
+
end
|
|
56
53
|
end
|
|
57
54
|
|
|
58
55
|
macro :title do
|
|
59
56
|
no_parameters
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
title_element do
|
|
58
|
+
%{<h1>
|
|
59
|
+
#{Glyph["document.title"]}
|
|
63
60
|
</h1>}
|
|
64
|
-
else
|
|
65
|
-
""
|
|
66
61
|
end
|
|
67
62
|
end
|
|
68
63
|
|
|
69
64
|
macro :subtitle do
|
|
70
65
|
no_parameters
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
#{Glyph["document.subtitle"]}
|
|
66
|
+
subtitle_element do
|
|
67
|
+
%{<h2>
|
|
68
|
+
#{Glyph["document.subtitle"]}
|
|
74
69
|
</h2>}
|
|
75
|
-
else
|
|
76
|
-
""
|
|
77
70
|
end
|
|
78
71
|
end
|
|
79
72
|
|
|
80
73
|
macro :author do
|
|
81
74
|
no_parameters
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
author_element do
|
|
76
|
+
%{<div class="author">
|
|
84
77
|
by <em>#{Glyph["document.author"]}</em>
|
|
85
78
|
</div>}
|
|
86
|
-
else
|
|
87
|
-
""
|
|
88
79
|
end
|
|
89
80
|
end
|
|
90
81
|
|
|
@@ -96,11 +87,36 @@ macro :pubdate do
|
|
|
96
87
|
end
|
|
97
88
|
|
|
98
89
|
macro :revision do
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
no_parameters
|
|
91
|
+
revision_element do
|
|
92
|
+
%{<div class="revision">#{Glyph['document.revision']}</div>}
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
macro :navigation do
|
|
97
|
+
exact_parameters 1
|
|
98
|
+
procs = {}
|
|
99
|
+
procs[:contents] = lambda do
|
|
100
|
+
%{<a href="#{Glyph["output.#{Glyph['document.output']}.base"]}index.html">Contents</a>}
|
|
101
|
+
end
|
|
102
|
+
procs[:previous] = lambda do |topic|
|
|
103
|
+
if topic then
|
|
104
|
+
%{<a href="#{Glyph["output.#{Glyph['document.output']}.base"]}#{topic[:src].gsub(/\..+$/, '.html')}">#{topic[:title]} ←</a>}
|
|
105
|
+
else
|
|
106
|
+
""
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
procs[:next] = lambda do |topic|
|
|
110
|
+
if topic then
|
|
111
|
+
%{<a href="#{Glyph["output.#{Glyph['document.output']}.base"]}#{topic[:src].gsub(/\..+$/, '.html')}">→ #{topic[:title]}</a>}
|
|
112
|
+
else
|
|
113
|
+
""
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
procs[:navigation] = lambda do |contents, prev_link, next_link|
|
|
117
|
+
%{<div class="navigation">#{prev_link}#{contents}#{next_link}</div>}
|
|
103
118
|
end
|
|
119
|
+
navigation_element_for param(0).to_sym, procs
|
|
104
120
|
end
|
|
105
121
|
|
|
106
122
|
macro_alias :important => :note
|
data/macros/html/inline.rb
CHANGED
|
@@ -3,61 +3,35 @@
|
|
|
3
3
|
macro :anchor do
|
|
4
4
|
min_parameters 1
|
|
5
5
|
max_parameters 2
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
macro_error "Bookmark '#{ident}' already exists" if bookmark? ident
|
|
9
|
-
bookmark :id => ident, :title => title
|
|
10
|
-
%{<a id="#{ident}">#{title}</a>}
|
|
6
|
+
bookmark :id => param(0), :title => param(1), :file => @source_file
|
|
7
|
+
%{<a id="#{param(0)}">#{(param(1) rescue nil)}</a>}
|
|
11
8
|
end
|
|
12
9
|
|
|
13
10
|
macro :link do
|
|
14
11
|
min_parameters 1
|
|
15
12
|
max_parameters 2
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if href.match /^#/ then
|
|
19
|
-
anchor = href.gsub(/^#/, '').to_sym
|
|
20
|
-
bmk = bookmark? anchor
|
|
21
|
-
if bmk then
|
|
22
|
-
title ||= bmk[:title]
|
|
23
|
-
else
|
|
24
|
-
plac = placeholder do |document|
|
|
25
|
-
macro_error "Bookmark '#{anchor}' does not exist" unless document.bookmarks[anchor]
|
|
26
|
-
document.bookmarks[anchor][:title]
|
|
27
|
-
end
|
|
28
|
-
title ||= plac
|
|
29
|
-
end
|
|
13
|
+
link_element_for param(0), param(1) do |target, title|
|
|
14
|
+
%{<a href="#{target}">#{title}</a>}
|
|
30
15
|
end
|
|
31
|
-
title ||= href
|
|
32
|
-
%{<a href="#{href}">#{title.to_s}</a>}
|
|
33
16
|
end
|
|
34
17
|
|
|
35
18
|
macro :fmi do
|
|
36
19
|
exact_parameters 2, :level => :warning
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
link = placeholder do |document|
|
|
40
|
-
interpret "link[#{href}]"
|
|
20
|
+
fmi_element_for param(0), param(1) do |topic, link|
|
|
21
|
+
%{<span class="fmi">for more information on #{topic}, see #{link}</span>}
|
|
41
22
|
end
|
|
42
|
-
%{<span class="fmi">for more information on #{topic}, see #{link}</span>}
|
|
43
23
|
end
|
|
44
24
|
|
|
45
25
|
macro :draftcomment do
|
|
46
|
-
|
|
26
|
+
draftcomment_element do |value|
|
|
47
27
|
%{<span class="comment"><span class="comment-pre"><strong>Comment:</strong> </span>#{value}</span>}
|
|
48
|
-
else
|
|
49
|
-
""
|
|
50
28
|
end
|
|
51
29
|
end
|
|
52
30
|
|
|
53
31
|
macro :todo do
|
|
54
32
|
exact_parameters 1
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if Glyph['document.draft'] then
|
|
58
|
-
%{<span class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>#{value}</span>}
|
|
59
|
-
else
|
|
60
|
-
""
|
|
33
|
+
todo_element do |value|
|
|
34
|
+
%{<span class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>#{value}</span>}
|
|
61
35
|
end
|
|
62
36
|
end
|
|
63
37
|
|
data/macros/html/structure.rb
CHANGED
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
3
|
macro :section do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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}
|
|
4
|
+
max_parameters 1
|
|
5
|
+
if raw_attribute(:src) && Glyph.multiple_output_files? then
|
|
6
|
+
required_attribute :title
|
|
24
7
|
end
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
procs = {}
|
|
9
|
+
procs[:title] = lambda do |level, ident, title|
|
|
10
|
+
%{<h#{level} id="#{ident}">#{title}</h#{level}>\n}
|
|
11
|
+
end
|
|
12
|
+
procs[:body] = lambda do |title, value|
|
|
13
|
+
%{<div class="#{@name}">
|
|
14
|
+
#{title}#{value}
|
|
27
15
|
|
|
28
16
|
</div>}
|
|
17
|
+
end
|
|
18
|
+
section_element_for procs
|
|
29
19
|
end
|
|
30
20
|
|
|
31
21
|
macro :article do
|
|
@@ -112,79 +102,76 @@ macro :head do
|
|
|
112
102
|
#{author}
|
|
113
103
|
#{copy}
|
|
114
104
|
<meta name="generator" content="Glyph v#{Glyph::VERSION} (http://www.h3rald.com/glyph)" />
|
|
105
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
115
106
|
#{value}
|
|
116
107
|
</head>
|
|
117
108
|
}
|
|
118
109
|
end
|
|
119
110
|
|
|
120
111
|
macro :style do
|
|
112
|
+
within :head
|
|
121
113
|
exact_parameters 1
|
|
122
114
|
file = Glyph.lite? ? Pathname.new(value) : Glyph::PROJECT/"styles/#{value}"
|
|
123
115
|
file = Pathname.new Glyph::HOME/'styles'/value unless file.exist?
|
|
124
116
|
macro_error "Stylesheet '#{value}' not found" unless file.exist?
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
style =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
117
|
+
|
|
118
|
+
@node[:document].style file
|
|
119
|
+
case Glyph['document.styles'].to_s
|
|
120
|
+
when 'embed' then
|
|
121
|
+
style = ""
|
|
122
|
+
case file.extname
|
|
123
|
+
when ".css"
|
|
124
|
+
style = file_load file
|
|
125
|
+
when ".sass"
|
|
126
|
+
begin
|
|
127
|
+
require 'sass'
|
|
128
|
+
style = Sass::Engine.new(file_load(file)).render
|
|
129
|
+
rescue LoadError
|
|
130
|
+
macro_error "Haml is not installed. Please run: gem install haml"
|
|
131
|
+
rescue Exception
|
|
132
|
+
raise
|
|
133
|
+
end
|
|
134
|
+
else
|
|
135
|
+
macro_error "Extension '#{file.extname}' not supported."
|
|
137
136
|
end
|
|
137
|
+
%{<style type="text/css">
|
|
138
|
+
#{style}
|
|
139
|
+
</style>}
|
|
140
|
+
when 'import' then
|
|
141
|
+
%{<style type="text/css">
|
|
142
|
+
@import url("#{Glyph["output.#{Glyph['document.output']}.base"]}styles/#{value.gsub(/\..+$/, '.css')}");
|
|
143
|
+
</style>}
|
|
144
|
+
when 'link' then
|
|
145
|
+
%{<link href="#{Glyph["output.#{Glyph['document.output']}.base"]}styles/#{value.gsub(/\..+$/, '.css')}" rel="stylesheet" type="text/css" />}
|
|
138
146
|
else
|
|
139
|
-
macro_error "
|
|
147
|
+
macro_error "Value '#{Glyph['document.styles']}' not allowed for 'document.styles' setting"
|
|
140
148
|
end
|
|
141
|
-
%{<style type="text/css">
|
|
142
|
-
#{style}
|
|
143
|
-
</style>}
|
|
144
149
|
end
|
|
145
150
|
|
|
146
151
|
macro :toc do
|
|
147
152
|
max_parameters 1
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
%{<a href="##{header[:id]}">#{header[:title]}</a>}
|
|
153
|
+
link_proc = lambda do |head|
|
|
154
|
+
(!Glyph.multiple_output_files? || (head.definition != head.file)) ? %{<a href="#{head.link(@source_file)}">#{head.title}</a>} : head.title
|
|
151
155
|
end
|
|
152
|
-
|
|
153
|
-
descend_section = lambda do |n1, added_headers|
|
|
154
|
-
list = ""
|
|
155
|
-
added_headers ||= []
|
|
156
|
-
n1.descend do |n2, level|
|
|
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]
|
|
162
|
-
next if added_headers.include? header_id
|
|
163
|
-
added_headers << header_id
|
|
164
|
-
# Check if part of frontmatter, bodymatter or backmatter
|
|
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
|
|
170
|
-
child_list = ""
|
|
171
|
-
n2.children.each do |c|
|
|
172
|
-
child_list << descend_section.call(c, added_headers)
|
|
173
|
-
end
|
|
174
|
-
list << "<li><ol>#{child_list}</ol></li>\n" unless child_list.blank?
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
list
|
|
178
|
-
end
|
|
179
|
-
toc_title = attr(:title) || "Table of Contents"
|
|
156
|
+
toc_list_proc = lambda do |descend_proc, bmk, document|
|
|
180
157
|
%{<div class="contents">
|
|
181
|
-
<h2 class="toc-header" id="
|
|
158
|
+
<h2 class="toc-header" id="#{bmk}">#{bmk.title}</h2>
|
|
182
159
|
<ol class="toc">
|
|
183
|
-
#{
|
|
160
|
+
#{descend_proc.call(document.structure, nil)}
|
|
184
161
|
</ol>
|
|
185
162
|
</div>}
|
|
186
163
|
end
|
|
187
|
-
|
|
164
|
+
toc_item_proc = lambda do |classes, header|
|
|
165
|
+
"<li class=\"#{classes.join(" ").strip}\">#{header}</li>"
|
|
166
|
+
end
|
|
167
|
+
toc_sublist_proc = lambda do |contents|
|
|
168
|
+
"<li><ol>#{contents}</ol></li>\n"
|
|
169
|
+
end
|
|
170
|
+
toc_element_for param(0), attr(:title),
|
|
171
|
+
:link => link_proc,
|
|
172
|
+
:toc_list => toc_list_proc,
|
|
173
|
+
:toc_item => toc_item_proc,
|
|
174
|
+
:toc_sublist => toc_sublist_proc
|
|
188
175
|
end
|
|
189
176
|
|
|
190
177
|
# See:
|