glyph 0.4.2 → 0.5.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/Rakefile +19 -40
- data/benchmark.rb +1 -2
- data/book/config.yml +8 -8
- data/book/document.glyph +18 -19
- data/book/images/glyph/commands_tasks.png +0 -0
- data/book/lib/layouts/bookindex.glyph +113 -111
- data/book/lib/layouts/bookpage.glyph +112 -108
- data/book/lib/macros/reference.rb +2 -2
- data/book/lib/tasks/tasks.rake +1 -1
- data/book/text/acknowledgements.glyph +1 -0
- data/book/text/changelog.glyph +140 -112
- data/book/text/compiling/compiling.glyph +36 -24
- data/book/text/compiling/lite_mode.glyph +11 -11
- data/book/text/compiling/programmatic_usage.glyph +57 -57
- data/book/text/config/document.glyph +7 -1
- data/book/text/config/options.glyph +5 -3
- data/book/text/config/output.glyph +41 -8
- data/book/text/extending/bookmarks_headers.glyph +13 -11
- data/book/text/extending/command.glyph +1 -1
- data/book/text/extending/commands_tasks.glyph +2 -2
- data/book/text/extending/internals.glyph +29 -29
- data/book/text/extending/interpreting.glyph +48 -9
- data/book/text/extending/macro_def.glyph +80 -32
- data/book/text/extending/output_format.glyph +2 -2
- data/book/text/extending/placeholders.glyph +27 -15
- data/book/text/extending/validators.glyph +1 -1
- data/book/text/getting_started/configuration.glyph +1 -1
- data/book/text/getting_started/create_project.glyph +4 -5
- data/book/text/getting_started/structure.glyph +2 -2
- data/book/text/macros/macros_core.glyph +341 -199
- data/book/text/macros/macros_filters.glyph +1 -1
- data/book/text/macros/macros_inline.glyph +3 -3
- data/book/text/macros/macros_structure.glyph +1 -1
- data/book/text/ref_commands.glyph +98 -93
- data/book/text/snippets.glyph +18 -0
- data/book/text/stats/bookmarks.glyph +16 -16
- data/book/text/stats/links.glyph +23 -23
- data/book/text/stats/macros.glyph +14 -14
- data/book/text/stats/snippets.glyph +26 -26
- data/book/text/stats/stats.glyph +14 -15
- data/book/text/text_editing/attribute_intro.glyph +8 -8
- data/book/text/text_editing/code.glyph +16 -16
- data/book/text/text_editing/conditionals.glyph +12 -13
- data/book/text/text_editing/esc_quot.glyph +3 -3
- data/book/text/text_editing/evaluation.glyph +57 -3
- data/book/text/text_editing/inclusions.glyph +34 -25
- data/book/text/text_editing/macro_composition.glyph +28 -0
- data/book/text/text_editing/macro_intro.glyph +4 -4
- data/book/text/text_editing/section_aliases.glyph +23 -23
- data/book/text/text_editing/sections.glyph +22 -22
- data/book/text/text_editing/stylesheets.glyph +33 -33
- data/book/text/text_editing/topics.glyph +6 -6
- data/book/text/text_editing/xml_fallback.glyph +1 -1
- data/book/text/troubleshooting/errors_command.glyph +4 -4
- data/book/text/troubleshooting/errors_generic.glyph +16 -10
- data/book/text/troubleshooting/errors_macro.glyph +18 -21
- data/book/text/troubleshooting/errors_parser.glyph +7 -7
- data/config.yml +51 -29
- data/document.glyph +18 -18
- data/glyph.gemspec +39 -287
- data/layouts/web5/topic.glyph +1 -1
- data/lib/glyph.rb +42 -10
- data/lib/glyph/analyzer.rb +5 -2
- data/lib/glyph/bookmark.rb +3 -1
- data/lib/glyph/commands.rb +11 -9
- data/lib/glyph/commands/add.rb +3 -1
- data/lib/glyph/commands/compile.rb +10 -7
- data/lib/glyph/commands/config.rb +7 -5
- data/lib/glyph/commands/init.rb +2 -0
- data/lib/glyph/commands/outline.rb +2 -0
- data/lib/glyph/commands/stats.rb +3 -0
- data/lib/glyph/commands/todo.rb +2 -0
- data/lib/glyph/config.rb +2 -0
- data/lib/glyph/document.rb +34 -9
- data/lib/glyph/interpreter.rb +2 -0
- data/lib/glyph/macro.rb +97 -25
- data/lib/glyph/macro_validators.rb +9 -6
- data/lib/glyph/node.rb +3 -1
- data/lib/glyph/parser.rb +68 -33
- data/lib/glyph/reporter.rb +3 -1
- data/lib/glyph/syntax_node.rb +23 -28
- data/lib/glyph/system_extensions.rb +21 -0
- data/lib/glyph/utils.rb +24 -4
- data/macros/block.rb +111 -0
- data/macros/core.rb +163 -33
- data/macros/filters.rb +3 -2
- data/macros/inline.rb +97 -0
- data/macros/reps/html.rb +180 -0
- data/macros/reps/html5.rb +100 -0
- data/macros/reps/web.rb +4 -0
- data/macros/reps/web5.rb +4 -0
- data/macros/structure.rb +229 -0
- data/macros/xml.rb +29 -24
- data/spec/config.yml +7 -0
- data/spec/files/article.glyph +2 -2
- data/spec/files/web_doc.glyph +9 -5
- data/spec/lib/commands_spec.rb +13 -9
- data/spec/lib/config_spec.rb +2 -2
- data/spec/lib/document_spec.rb +10 -0
- data/spec/lib/glyph_spec.rb +30 -8
- data/spec/lib/macro_spec.rb +39 -4
- data/spec/lib/macro_validators_spec.rb +3 -4
- data/spec/lib/parser_spec.rb +7 -0
- data/spec/lib/reporter_spec.rb +1 -0
- data/spec/lib/syntax_node_spec.rb +40 -6
- data/spec/macros/core_spec.rb +154 -21
- data/spec/macros/filters_spec.rb +1 -1
- data/spec/macros/html5_spec.rb +4 -5
- data/spec/macros/macros_spec.rb +6 -7
- data/spec/macros/web5_spec.rb +3 -3
- data/spec/macros/web_spec.rb +10 -7
- data/spec/macros/xml_spec.rb +11 -2
- data/spec/spec_helper.rb +11 -5
- data/spec/tasks/generate_spec.rb +40 -5
- data/spec/tasks/load_spec.rb +1 -13
- data/styles/coderay.css +147 -38
- data/styles/default.css +19 -22
- data/styles/pagination.css +30 -30
- data/tasks/generate.rake +54 -18
- data/tasks/load.rake +9 -24
- data/tasks/project.rake +0 -2
- metadata +208 -207
- data/.gitignore +0 -7
- data/VERSION +0 -1
- data/book/snippets.yml +0 -18
- data/lib/glyph/macro_helpers.rb +0 -282
- data/macros/html/block.rb +0 -124
- data/macros/html/inline.rb +0 -42
- data/macros/html/structure.rb +0 -191
- data/macros/html5/block.rb +0 -69
- data/macros/html5/inline.rb +0 -24
- data/macros/html5/structure.rb +0 -140
data/spec/macros/core_spec.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
-
|
|
2
|
+
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
describe "Macro:" do
|
|
5
5
|
|
|
@@ -15,26 +15,22 @@ describe "Macro:" do
|
|
|
15
15
|
|
|
16
16
|
it "snippet" do
|
|
17
17
|
define_em_macro
|
|
18
|
-
interpret "Testing a snippet: &[test]."
|
|
18
|
+
interpret "&:[test|This is a \nTest snippet]Testing a snippet: &[test]."
|
|
19
19
|
@p.document.output.should == "Testing a snippet: This is a \nTest snippet."
|
|
20
20
|
interpret("Testing &[wrong].")
|
|
21
21
|
@p.document.output.should == "Testing [SNIPPET 'wrong' NOT PROCESSED]."
|
|
22
|
-
|
|
23
|
-
Glyph::SNIPPETS[:b] = "and another em[test]"
|
|
24
|
-
text = "TEST: &[a]"
|
|
22
|
+
text = "&:[b|and another em[test]]&:[a|this is a em[test] &[b]]TEST: &[a]"
|
|
25
23
|
interpret text
|
|
26
24
|
@p.document.output.should == "TEST: this is a <em>test</em> and another <em>test</em>"
|
|
27
25
|
# Check snippets with links
|
|
28
|
-
|
|
29
|
-
text = "Test. &[c]. #[other|Test]."
|
|
26
|
+
text = "&:[c|This is a link to something afterwards: =>[#other]]Test. &[c]. #[other|Test]."
|
|
30
27
|
output_for(text).should == %{Test. This is a link to something afterwards: <a href="#other">Test</a>. <a id="other">Test</a>.}
|
|
31
28
|
end
|
|
32
29
|
|
|
33
30
|
it "snippet:" do
|
|
34
31
|
interpret("&[t1] - &:[t1|Test #1] - &[t1]")
|
|
35
32
|
@p.document.output.should == "[SNIPPET 't1' NOT PROCESSED] - - Test #1"
|
|
36
|
-
|
|
37
|
-
Glyph::SNIPPETS.delete :t1
|
|
33
|
+
@p.document.snippet?(:t1).should == "Test #1"
|
|
38
34
|
end
|
|
39
35
|
|
|
40
36
|
it "condition" do
|
|
@@ -56,8 +52,6 @@ describe "Macro:" do
|
|
|
56
52
|
@p.document.output.should == ""
|
|
57
53
|
interpret("?[not[match[$[document.source]|/^docu/]]|em[test]]")
|
|
58
54
|
@p.document.output.should == ""
|
|
59
|
-
# Invalid regexp
|
|
60
|
-
lambda { interpret("?[match[$[document.source]|document]em[test]]").document.output }.should raise_error
|
|
61
55
|
interpret "?[%[lite?]|test]"
|
|
62
56
|
@p.document.output.should == ""
|
|
63
57
|
interpret "?[%[!lite?]|test]"
|
|
@@ -121,7 +115,7 @@ This is a test.
|
|
|
121
115
|
it "include should assume .glyph as the default extension" do
|
|
122
116
|
file_copy Glyph::SPEC_DIR/'files/article.glyph', Glyph::PROJECT/'text/article.glyph'
|
|
123
117
|
output_for("include[article]").gsub(/\n|\t/, '').should == %{<div class="section">
|
|
124
|
-
Test -- Test Snippet
|
|
118
|
+
改善 Test -- Test Snippet
|
|
125
119
|
|
|
126
120
|
</div>}.gsub(/\n|\t/, '')
|
|
127
121
|
end
|
|
@@ -136,6 +130,16 @@ Test -- Test Snippet
|
|
|
136
130
|
output_for("include[test.rb]day[]").should == Time.now.day.to_s
|
|
137
131
|
end
|
|
138
132
|
|
|
133
|
+
it "load" do
|
|
134
|
+
text1 = %{section[@title[...]]}
|
|
135
|
+
text2 = %{Time.now.day}
|
|
136
|
+
file_write Glyph::PROJECT/"test1.glyph", text1
|
|
137
|
+
file_write Glyph::PROJECT/"test2.rb", text2
|
|
138
|
+
output_for("load[test/test1.glyph]").should == "[FILE 'test/test1.glyph' NOT FOUND]"
|
|
139
|
+
output_for("load[test1.glyph]").should == text1
|
|
140
|
+
output_for("load[test2.rb]").should == text2
|
|
141
|
+
end
|
|
142
|
+
|
|
139
143
|
|
|
140
144
|
it "escape" do
|
|
141
145
|
define_em_macro
|
|
@@ -183,18 +187,26 @@ Test -- Test Snippet
|
|
|
183
187
|
Glyph::MACROS[:test].should == Glyph::MACROS[:em]
|
|
184
188
|
end
|
|
185
189
|
|
|
186
|
-
it "
|
|
190
|
+
it "define:" do
|
|
187
191
|
define_em_macro
|
|
188
|
-
interpret("
|
|
189
|
-
output_for("
|
|
190
|
-
output_for("
|
|
192
|
+
interpret("def:[def_test|em[{{0}}\\/em[{{a}}]]]").process
|
|
193
|
+
output_for("def_test[test @a[em[A!]]]").should == "<em>test<em><em>A!</em></em></em>"
|
|
194
|
+
output_for("def_test[]").should == "<em><em></em></em>"
|
|
191
195
|
end
|
|
192
196
|
|
|
193
|
-
it "
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
it "define should support recursion" do
|
|
198
|
+
fact = %{
|
|
199
|
+
def:[fact|
|
|
200
|
+
?[
|
|
201
|
+
eq[{{0}}|0]|1|
|
|
202
|
+
multiply[
|
|
203
|
+
{{0}} | fact[subtract[{{0}}|1]]
|
|
204
|
+
]
|
|
205
|
+
]
|
|
206
|
+
]
|
|
207
|
+
fact[5]
|
|
208
|
+
}
|
|
209
|
+
output_for(fact).strip.should == "120"
|
|
198
210
|
end
|
|
199
211
|
|
|
200
212
|
it "output?" do
|
|
@@ -207,4 +219,125 @@ Test -- Test Snippet
|
|
|
207
219
|
output_for("?[output?[html|web]|YES!|NO...]").should == "NO..."
|
|
208
220
|
end
|
|
209
221
|
|
|
222
|
+
it "let, attribute, attribute:" do
|
|
223
|
+
test = %{
|
|
224
|
+
let[
|
|
225
|
+
@a[1]
|
|
226
|
+
@b[1]
|
|
227
|
+
-- @[a]@[b] --
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
nested_test = %{
|
|
231
|
+
section[
|
|
232
|
+
@title[test]
|
|
233
|
+
let[
|
|
234
|
+
-- @[title]@[unknown] --
|
|
235
|
+
]
|
|
236
|
+
]
|
|
237
|
+
}
|
|
238
|
+
set_test = %{
|
|
239
|
+
section[
|
|
240
|
+
@title[test]
|
|
241
|
+
em[-- @[title]@:[title|changed!]@[title] --]
|
|
242
|
+
let[
|
|
243
|
+
@a[1]
|
|
244
|
+
em[@:[title|changed again!]-- @[title] --]
|
|
245
|
+
]
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
invalid_set = %{@:[test|1]}
|
|
249
|
+
invalid_macro = %{=>@[test]}
|
|
250
|
+
output_for(test).should match("-- 11 --")
|
|
251
|
+
output_for(nested_test).should match("-- test --")
|
|
252
|
+
output_for(set_test).should match("-- testchanged! --")
|
|
253
|
+
output_for(set_test).should match("-- changed again! --")
|
|
254
|
+
lambda { output_for(invalid_set)}.should raise_error(Glyph::MacroError, "Undeclared attribute 'test'")
|
|
255
|
+
lambda { output_for(invalid_macro) }.should raise_error
|
|
256
|
+
# Set same attribute
|
|
257
|
+
text = %{
|
|
258
|
+
let[
|
|
259
|
+
@a[-]
|
|
260
|
+
em[
|
|
261
|
+
@:[a|s/concat[@[a]|--]]
|
|
262
|
+
@[a]
|
|
263
|
+
]
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
output_for(text).strip.should match("---")
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
it "add, multiply, subtract" do
|
|
270
|
+
output_for("add[2|2]").should == "4"
|
|
271
|
+
output_for("add[1|2|3|4]").should == "10"
|
|
272
|
+
output_for("add[1|2|-3]").should == "0"
|
|
273
|
+
output_for("add[a|1|2]").should == "3"
|
|
274
|
+
output_for("add[a|test]").should == "0"
|
|
275
|
+
lambda { output_for("add[1]").should == "1"}.should raise_error
|
|
276
|
+
lambda { output_for("add[]").should == "1"}.should raise_error
|
|
277
|
+
output_for("subtract[2|2]").should == "0"
|
|
278
|
+
output_for("subtract[1|2|3|4]").should == "-8"
|
|
279
|
+
output_for("subtract[1|2|-3]").should == "2"
|
|
280
|
+
output_for("subtract[a|1|2]").should == "-3"
|
|
281
|
+
output_for("subtract[a|test]").should == "0"
|
|
282
|
+
lambda { output_for("subtract[1]").should == "1"}.should raise_error
|
|
283
|
+
lambda { output_for("subtract[]").should == "1"}.should raise_error
|
|
284
|
+
output_for("multiply[2|2]").should == "4"
|
|
285
|
+
output_for("multiply[1|2|3|4]").should == "24"
|
|
286
|
+
output_for("multiply[1|2|-3]").should == "-6"
|
|
287
|
+
output_for("multiply[a|1|2]").should == "0"
|
|
288
|
+
output_for("multiply[a|test]").should == "0"
|
|
289
|
+
lambda { output_for("multiply[1]").should == "1"}.should raise_error
|
|
290
|
+
lambda { output_for("multiply[]").should == "1"}.should raise_error
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it "s" do
|
|
294
|
+
lambda { output_for("s/each[test]") }.should raise_error
|
|
295
|
+
lambda { output_for("s/gsub[]") }.should raise_error
|
|
296
|
+
output_for("s/gsub[string|/ri/|i]").should == "sting"
|
|
297
|
+
output_for("s/match[test|/EST/i]").should == "est"
|
|
298
|
+
output_for("s/upcase[test]").should == "TEST"
|
|
299
|
+
output_for("s/insert[hell|4|o]").should == "hello"
|
|
300
|
+
output_for("s/slice[test]").should == ""
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
it "lt, lte, gt, gte" do
|
|
304
|
+
lambda { output_for("lt[1|2|3]")}.should raise_error
|
|
305
|
+
output_for("lt[2|7]").should == "true"
|
|
306
|
+
output_for("gt[2|7]").should == ""
|
|
307
|
+
output_for("gte[2|2]").should == "true"
|
|
308
|
+
output_for("lte[2|2]").should == "true"
|
|
309
|
+
output_for("gt[aaa|2]").should == "true"
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
it "while" do
|
|
313
|
+
text = %{
|
|
314
|
+
let[
|
|
315
|
+
@count[5]
|
|
316
|
+
@text[-]
|
|
317
|
+
while[gt[@[count]|0]|
|
|
318
|
+
@:[text|s/concat[@[text]|test-]]
|
|
319
|
+
@:[count|subtract[@[count]|1]]
|
|
320
|
+
]
|
|
321
|
+
@[text]
|
|
322
|
+
]
|
|
323
|
+
}
|
|
324
|
+
output_for(text).strip.should == "-test-test-test-test-test-"
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
it "fragment" do
|
|
328
|
+
text = "... ##[id1|test fragment #1] ... ##[id2|test fragment #2]"
|
|
329
|
+
interpret text
|
|
330
|
+
@p.document.fragments.should == {:id1 => "test fragment #1", :id2 => "test fragment #2"}
|
|
331
|
+
@p.document.output.should == "... test fragment #1 ... test fragment #2"
|
|
332
|
+
lambda { output_for "##[id1|test] -- fragment[id1|test]" }.should raise_error
|
|
333
|
+
lambda { output_for "##[id1]" }.should raise_error
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
it "embed" do
|
|
337
|
+
text = "... <=[id2] ##[id1|test fragment #1] ... ##[id2|test fragment #2] <=[id1]"
|
|
338
|
+
output_for(text).should == "... test fragment #2 test fragment #1 ... test fragment #2 test fragment #1"
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
210
343
|
end
|
data/spec/macros/filters_spec.rb
CHANGED
data/spec/macros/html5_spec.rb
CHANGED
|
@@ -76,11 +76,10 @@ describe "Macro:" do
|
|
|
76
76
|
it "figure (html5)" do
|
|
77
77
|
interpret "figure[@alt[ligature]ligature.jpg|Ligature]"
|
|
78
78
|
@p.document.output.gsub(/\t|\n/, '').should == %{
|
|
79
|
-
<figure>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
</figure>
|
|
83
|
-
}.gsub(/\n|\t/, '')
|
|
79
|
+
<figure alt=\"ligature\">
|
|
80
|
+
<img src=\"images/ligature.jpg\" />
|
|
81
|
+
<figcaption>Ligature</figcaption>
|
|
82
|
+
</figure>}.gsub(/\n|\t/, '')
|
|
84
83
|
end
|
|
85
84
|
|
|
86
85
|
it "draftcomment, todo (html5)" do
|
data/spec/macros/macros_spec.rb
CHANGED
|
@@ -138,7 +138,7 @@ describe "Macro:" do
|
|
|
138
138
|
|
|
139
139
|
it "image should link files by absolute or relative path in Lite mode" do
|
|
140
140
|
result = %{
|
|
141
|
-
<img
|
|
141
|
+
<img src="images/ligature.jpg" width="90%" height="90%" />
|
|
142
142
|
}.gsub(/\n|\t/, '')
|
|
143
143
|
Glyph.lite_mode = true
|
|
144
144
|
Dir.chdir Glyph::PROJECT
|
|
@@ -151,17 +151,16 @@ describe "Macro:" do
|
|
|
151
151
|
it "figure" do
|
|
152
152
|
interpret "figure[@alt[ligature]ligature.jpg|Ligature]"
|
|
153
153
|
@p.document.output.gsub(/\t|\n/, '').should == %{
|
|
154
|
-
<div class
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
</div>
|
|
158
|
-
}.gsub(/\n|\t/, '')
|
|
154
|
+
<div class=\"figure\" alt=\"ligature\">
|
|
155
|
+
<img src=\"images/ligature.jpg\" />
|
|
156
|
+
<div class=\"caption\">Ligature</div>
|
|
157
|
+
</div>}.gsub(/\n|\t/, '')
|
|
159
158
|
end
|
|
160
159
|
|
|
161
160
|
it "fig should link files by absolute or relative path in Lite mode" do
|
|
162
161
|
result = %{
|
|
163
162
|
<div class="figure">
|
|
164
|
-
<img
|
|
163
|
+
<img src="images/ligature.jpg" />
|
|
165
164
|
<div class="caption">Ligature</div>
|
|
166
165
|
</div>
|
|
167
166
|
}.gsub(/\n|\t/, '')
|
data/spec/macros/web5_spec.rb
CHANGED
|
@@ -17,7 +17,7 @@ describe "Macro:" do
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "section (topic)" do
|
|
20
|
-
interpret("
|
|
20
|
+
interpret("section[section[@src[a/web1.glyph]@title[Test]]]")
|
|
21
21
|
topic = @p.document.topics[0]
|
|
22
22
|
topic[:contents].match(/<article>/).blank?.should == false
|
|
23
23
|
end
|
|
@@ -26,7 +26,7 @@ describe "Macro:" do
|
|
|
26
26
|
Glyph.run! 'generate:web5'
|
|
27
27
|
web1 = Glyph.file_load(Glyph::PROJECT/'output/web5/a/web1.html')
|
|
28
28
|
web2 = Glyph.file_load(Glyph::PROJECT/'output/web5/a/b/web2.html')
|
|
29
|
-
web1.match(%{<nav
|
|
30
|
-
web2.match(%{<nav><a href="/a/web1.html">Topic #1
|
|
29
|
+
web1.match(%{<nav> | <a href="/index.html">Contents</a> | <a href="/a/b/web2.html">→ Topic #2</a></nav>}).blank?.should == false
|
|
30
|
+
web2.match(%{<nav><a href="/a/web1.html">Topic #1</a> | <a href="/index.html">Contents</a> | </nav>}).blank?.should == false
|
|
31
31
|
end
|
|
32
32
|
end
|
data/spec/macros/web_spec.rb
CHANGED
|
@@ -33,27 +33,30 @@ describe "Macro:" do
|
|
|
33
33
|
Glyph.run! 'generate:web'
|
|
34
34
|
web1 = Glyph.file_load(Glyph::PROJECT/'output/web/a/web1.html')
|
|
35
35
|
web2 = Glyph.file_load(Glyph::PROJECT/'output/web/a/b/web2.html')
|
|
36
|
-
web1.match(%{<div class="navigation"
|
|
37
|
-
web2.match(%{<div class="navigation"><a href="/a/web1.html">Topic #1
|
|
36
|
+
web1.match(%{<div class="navigation"> | <a href="/index.html">Contents</a> | <a href="/a/b/web2.html">Topic #2</a></div>}).blank?.should == false
|
|
37
|
+
web2.match(%{<div class="navigation"><a href="/a/web1.html">Topic #1</a> | <a href="/index.html">Contents</a> | </div>}).blank?.should == false
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "toc should only list topics" do
|
|
41
41
|
Glyph.run! 'generate:web'
|
|
42
42
|
index = Glyph.file_load(Glyph::PROJECT/'output/web/index.html')
|
|
43
43
|
index.match(%{<li class="section"><a href="#h_1">Web Document</a></li>}).blank?.should == true
|
|
44
|
-
index.match(%{href="/a/web1.html#
|
|
45
|
-
index.match(%{href="/a/b/web2.html#
|
|
44
|
+
index.match(%{href="/a/web1.html#h_3"}).blank?.should == false
|
|
45
|
+
index.match(%{href="/a/b/web2.html#h_7"}).blank?.should == false
|
|
46
|
+
web1 = Glyph.file_load(Glyph::PROJECT/'output/web/a/web1.html')
|
|
47
|
+
web1.should match(/<h2 id="t_0">Topic #1<\/h2>/) # Headers are reset in each topic
|
|
46
48
|
delete_project
|
|
47
49
|
reset_quiet
|
|
48
50
|
create_web_project
|
|
49
51
|
Glyph['document.output'] = 'html'
|
|
50
52
|
Glyph.run! 'generate:html'
|
|
51
53
|
index = Glyph.file_load(Glyph::PROJECT/'output/html/test_project.html')
|
|
52
|
-
|
|
53
|
-
index.match(%{href="a/
|
|
54
|
+
index.should match(%{<li class="section"><a href="#h_3">Topic #1</a></li><li><ol><li class="section"><a href="#h_4">Test #1a</a></li>})
|
|
55
|
+
index.match(%{href="a/web1.html#h_3"}).blank?.should == true
|
|
56
|
+
index.match(%{href="a/b/web2.html#h_7"}).blank?.should == true
|
|
54
57
|
index.match(%{<li class="section"><a href="#h_1">Web Document</a></li>}).blank?.should == false
|
|
55
58
|
index.match(%{href="#h_2"}).blank?.should == false
|
|
56
|
-
index.match(%{href="#
|
|
59
|
+
index.match(%{href="#h_8"}).blank?.should == false # Header numbers are different...
|
|
57
60
|
end
|
|
58
61
|
|
|
59
62
|
end
|
data/spec/macros/xml_spec.rb
CHANGED
|
@@ -35,7 +35,7 @@ describe "Glyph Language" do
|
|
|
35
35
|
it "should support XML attributes" do
|
|
36
36
|
language('xml')
|
|
37
37
|
output_for("span[@class[test] @style[color:red;] test...]").should == %{
|
|
38
|
-
<span class="test" style="color:red;">test...</span>
|
|
38
|
+
<span class="test" style="color:red;"> test...</span>
|
|
39
39
|
}.strip
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -48,7 +48,7 @@ describe "Glyph Language" do
|
|
|
48
48
|
it "should notify the user that a macro is not found for invalid elements if xml_fallback is enabled" do
|
|
49
49
|
# Assuming options.xml_fallback = true
|
|
50
50
|
language('glyph')
|
|
51
|
-
lambda { interpret("*a[test]").document }.should raise_error(Glyph::MacroError, "
|
|
51
|
+
lambda { interpret("*a[test]").document }.should raise_error(Glyph::MacroError, "Invalid XML element '*a'")
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
it "should not render blacklisted tags" do
|
|
@@ -74,4 +74,13 @@ describe "Glyph Language" do
|
|
|
74
74
|
output_for(text).gsub(/\s/, '').should == "<test>test</test>"
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
+
it "should work with macro composition" do
|
|
78
|
+
language('glyph')
|
|
79
|
+
output_for("xml/a[@test[...]xyz]").should == "<a test=\"...\">xyz</a>"
|
|
80
|
+
output_for("xml/a[@test[...]xml/b[test]]").should == "<a test=\"...\">\n<b>test</b>\n</a>"
|
|
81
|
+
output_for("xml/a[xml/b[test]xml/c[test]]").should == "<a>\n<b>test</b><c>test</c>\n</a>"
|
|
82
|
+
output_for("xml/a[xml/b[test]xml/c[@test[test_attr]test]]").should == "<a>\n<b>test</b><c test=\"test_attr\">test</c>\n</a>"
|
|
83
|
+
output_for("xml/a[xml/b[@test[true]]]").should == "<a>\n<b test=\"true\" />\n</a>"
|
|
84
|
+
end
|
|
85
|
+
|
|
77
86
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -62,16 +62,22 @@ end
|
|
|
62
62
|
|
|
63
63
|
def delete_project
|
|
64
64
|
delete_project_dir
|
|
65
|
-
Glyph::
|
|
65
|
+
Glyph::REPS.clear
|
|
66
66
|
Glyph::MACROS.clear
|
|
67
67
|
Glyph['document.source'] = 'document.glyph'
|
|
68
68
|
Glyph.document = nil
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
def run_command(cmd)
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
def run_command(cmd, return_code=false)
|
|
72
|
+
result = 0
|
|
73
|
+
out = stdout_for do
|
|
74
|
+
result = GLI.run cmd
|
|
74
75
|
end
|
|
76
|
+
return_code ? result : out
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def run_command_with_status(cmd)
|
|
80
|
+
run_command(cmd, true)
|
|
75
81
|
end
|
|
76
82
|
|
|
77
83
|
def stdout_for(&block)
|
|
@@ -90,7 +96,7 @@ def stdout_for(&block)
|
|
|
90
96
|
end
|
|
91
97
|
|
|
92
98
|
def run_command_successfully(cmd)
|
|
93
|
-
run_command(cmd)
|
|
99
|
+
run_command(cmd, true) == 0
|
|
94
100
|
end
|
|
95
101
|
|
|
96
102
|
def define_em_macro
|
data/spec/tasks/generate_spec.rb
CHANGED
|
@@ -22,9 +22,44 @@ describe "generate" do
|
|
|
22
22
|
(Glyph::PROJECT/'output/html/test_project.html').exist?.should == true
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
it ":html5 should generate a standalone html document" do
|
|
26
|
+
Glyph['document.output'] = 'html5'
|
|
27
|
+
lambda { Glyph.run! 'generate:html5'}.should_not raise_error
|
|
28
|
+
(Glyph::PROJECT/'output/html5/test_project.html').exist?.should == true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it ":pdf_through_html should generate a pdf document through html" do
|
|
32
|
+
Glyph['document.output'] = 'pdf'
|
|
33
|
+
lambda { stdout_for { Glyph.run! 'generate:pdf_through_html'}}.should_not raise_error
|
|
34
|
+
(Glyph::PROJECT/'output/tmp/test_project.html').exist?.should == true
|
|
35
|
+
(Glyph::PROJECT/'output/pdf/test_project.pdf').exist?.should == true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it ":pdf_through_html5 should generate a pdf document through html5" do
|
|
39
|
+
Glyph['document.output'] = 'pdf'
|
|
40
|
+
lambda { stdout_for { Glyph.run! 'generate:pdf_through_html5'}}.should_not raise_error
|
|
41
|
+
(Glyph::PROJECT/'output/tmp/test_project.html').exist?.should == true
|
|
42
|
+
(Glyph::PROJECT/'output/pdf/test_project.pdf').exist?.should == true
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it ":mobi should generate a mobi document" do
|
|
46
|
+
Glyph['document.output'] = 'mobi'
|
|
47
|
+
lambda { stdout_for { Glyph.run! 'generate:mobi'}}.should_not raise_error
|
|
48
|
+
(Glyph::PROJECT/'output/tmp/test_project.html').exist?.should == true
|
|
49
|
+
(Glyph::PROJECT/'output/mobi/test_project.mobi').exist?.should == true
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it ":epub should generate an epub document" do
|
|
53
|
+
Glyph['document.output'] = 'epub'
|
|
54
|
+
#lambda {
|
|
55
|
+
stdout_for { Glyph.run! 'generate:epub'}#}.should_not raise_error
|
|
56
|
+
(Glyph::PROJECT/'output/tmp/test_project.html').exist?.should == true
|
|
57
|
+
(Glyph::PROJECT/'output/epub/test_project.epub').exist?.should == true
|
|
58
|
+
end
|
|
59
|
+
|
|
25
60
|
it "should copy images" do
|
|
26
61
|
dir = (Glyph::PROJECT/'images/test').mkpath
|
|
27
|
-
file_copy Glyph::HOME/'spec/files/ligature.jpg', Glyph::PROJECT/'images/test'
|
|
62
|
+
file_copy Glyph::HOME/'spec/files/ligature.jpg', Glyph::PROJECT/'images/test'
|
|
28
63
|
lambda { Glyph.run! 'generate:html' }.should_not raise_error
|
|
29
64
|
(Glyph::PROJECT/'output/html/images/test/ligature.jpg').exist?.should == true
|
|
30
65
|
end
|
|
@@ -56,10 +91,10 @@ describe "generate" do
|
|
|
56
91
|
lambda { Glyph.run! 'generate:web'}.should raise_error(RuntimeError, "You cannot have a 'styles' directory under your 'text' directory.")
|
|
57
92
|
reset_web.call
|
|
58
93
|
# check that the task can be run without errors
|
|
59
|
-
reset_web.call
|
|
94
|
+
reset_web.call
|
|
60
95
|
Glyph["output.#{Glyph['document.output']}.base"] = "/test/"
|
|
61
|
-
#lambda {
|
|
62
|
-
Glyph.run! 'generate:web'
|
|
96
|
+
#lambda {
|
|
97
|
+
Glyph.run! 'generate:web'
|
|
63
98
|
#}.should_not raise_error
|
|
64
99
|
# check that images are copied
|
|
65
100
|
(Glyph::PROJECT/'output/web/images/ligature.jpg').exist?.should == true
|
|
@@ -69,7 +104,7 @@ describe "generate" do
|
|
|
69
104
|
# check that index.html is created
|
|
70
105
|
index = (Glyph::PROJECT/'output/web/index.html')
|
|
71
106
|
index.exist?.should == true
|
|
72
|
-
file_load(index).should match(/<li class="section"><a href="\/test\/a\/b\/web2.html#
|
|
107
|
+
file_load(index).should match(/<li class="section"><a href="\/test\/a\/b\/web2.html#h_7">Topic #2<\/a>/)
|
|
73
108
|
# check that topics are copied in the proper directories
|
|
74
109
|
web1 = (Glyph::PROJECT/'output/web/a/web1.html')
|
|
75
110
|
web1.exist?.should == true
|