glyph 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/Rakefile +19 -40
  2. data/benchmark.rb +1 -2
  3. data/book/config.yml +8 -8
  4. data/book/document.glyph +18 -19
  5. data/book/images/glyph/commands_tasks.png +0 -0
  6. data/book/lib/layouts/bookindex.glyph +113 -111
  7. data/book/lib/layouts/bookpage.glyph +112 -108
  8. data/book/lib/macros/reference.rb +2 -2
  9. data/book/lib/tasks/tasks.rake +1 -1
  10. data/book/text/acknowledgements.glyph +1 -0
  11. data/book/text/changelog.glyph +140 -112
  12. data/book/text/compiling/compiling.glyph +36 -24
  13. data/book/text/compiling/lite_mode.glyph +11 -11
  14. data/book/text/compiling/programmatic_usage.glyph +57 -57
  15. data/book/text/config/document.glyph +7 -1
  16. data/book/text/config/options.glyph +5 -3
  17. data/book/text/config/output.glyph +41 -8
  18. data/book/text/extending/bookmarks_headers.glyph +13 -11
  19. data/book/text/extending/command.glyph +1 -1
  20. data/book/text/extending/commands_tasks.glyph +2 -2
  21. data/book/text/extending/internals.glyph +29 -29
  22. data/book/text/extending/interpreting.glyph +48 -9
  23. data/book/text/extending/macro_def.glyph +80 -32
  24. data/book/text/extending/output_format.glyph +2 -2
  25. data/book/text/extending/placeholders.glyph +27 -15
  26. data/book/text/extending/validators.glyph +1 -1
  27. data/book/text/getting_started/configuration.glyph +1 -1
  28. data/book/text/getting_started/create_project.glyph +4 -5
  29. data/book/text/getting_started/structure.glyph +2 -2
  30. data/book/text/macros/macros_core.glyph +341 -199
  31. data/book/text/macros/macros_filters.glyph +1 -1
  32. data/book/text/macros/macros_inline.glyph +3 -3
  33. data/book/text/macros/macros_structure.glyph +1 -1
  34. data/book/text/ref_commands.glyph +98 -93
  35. data/book/text/snippets.glyph +18 -0
  36. data/book/text/stats/bookmarks.glyph +16 -16
  37. data/book/text/stats/links.glyph +23 -23
  38. data/book/text/stats/macros.glyph +14 -14
  39. data/book/text/stats/snippets.glyph +26 -26
  40. data/book/text/stats/stats.glyph +14 -15
  41. data/book/text/text_editing/attribute_intro.glyph +8 -8
  42. data/book/text/text_editing/code.glyph +16 -16
  43. data/book/text/text_editing/conditionals.glyph +12 -13
  44. data/book/text/text_editing/esc_quot.glyph +3 -3
  45. data/book/text/text_editing/evaluation.glyph +57 -3
  46. data/book/text/text_editing/inclusions.glyph +34 -25
  47. data/book/text/text_editing/macro_composition.glyph +28 -0
  48. data/book/text/text_editing/macro_intro.glyph +4 -4
  49. data/book/text/text_editing/section_aliases.glyph +23 -23
  50. data/book/text/text_editing/sections.glyph +22 -22
  51. data/book/text/text_editing/stylesheets.glyph +33 -33
  52. data/book/text/text_editing/topics.glyph +6 -6
  53. data/book/text/text_editing/xml_fallback.glyph +1 -1
  54. data/book/text/troubleshooting/errors_command.glyph +4 -4
  55. data/book/text/troubleshooting/errors_generic.glyph +16 -10
  56. data/book/text/troubleshooting/errors_macro.glyph +18 -21
  57. data/book/text/troubleshooting/errors_parser.glyph +7 -7
  58. data/config.yml +51 -29
  59. data/document.glyph +18 -18
  60. data/glyph.gemspec +39 -287
  61. data/layouts/web5/topic.glyph +1 -1
  62. data/lib/glyph.rb +42 -10
  63. data/lib/glyph/analyzer.rb +5 -2
  64. data/lib/glyph/bookmark.rb +3 -1
  65. data/lib/glyph/commands.rb +11 -9
  66. data/lib/glyph/commands/add.rb +3 -1
  67. data/lib/glyph/commands/compile.rb +10 -7
  68. data/lib/glyph/commands/config.rb +7 -5
  69. data/lib/glyph/commands/init.rb +2 -0
  70. data/lib/glyph/commands/outline.rb +2 -0
  71. data/lib/glyph/commands/stats.rb +3 -0
  72. data/lib/glyph/commands/todo.rb +2 -0
  73. data/lib/glyph/config.rb +2 -0
  74. data/lib/glyph/document.rb +34 -9
  75. data/lib/glyph/interpreter.rb +2 -0
  76. data/lib/glyph/macro.rb +97 -25
  77. data/lib/glyph/macro_validators.rb +9 -6
  78. data/lib/glyph/node.rb +3 -1
  79. data/lib/glyph/parser.rb +68 -33
  80. data/lib/glyph/reporter.rb +3 -1
  81. data/lib/glyph/syntax_node.rb +23 -28
  82. data/lib/glyph/system_extensions.rb +21 -0
  83. data/lib/glyph/utils.rb +24 -4
  84. data/macros/block.rb +111 -0
  85. data/macros/core.rb +163 -33
  86. data/macros/filters.rb +3 -2
  87. data/macros/inline.rb +97 -0
  88. data/macros/reps/html.rb +180 -0
  89. data/macros/reps/html5.rb +100 -0
  90. data/macros/reps/web.rb +4 -0
  91. data/macros/reps/web5.rb +4 -0
  92. data/macros/structure.rb +229 -0
  93. data/macros/xml.rb +29 -24
  94. data/spec/config.yml +7 -0
  95. data/spec/files/article.glyph +2 -2
  96. data/spec/files/web_doc.glyph +9 -5
  97. data/spec/lib/commands_spec.rb +13 -9
  98. data/spec/lib/config_spec.rb +2 -2
  99. data/spec/lib/document_spec.rb +10 -0
  100. data/spec/lib/glyph_spec.rb +30 -8
  101. data/spec/lib/macro_spec.rb +39 -4
  102. data/spec/lib/macro_validators_spec.rb +3 -4
  103. data/spec/lib/parser_spec.rb +7 -0
  104. data/spec/lib/reporter_spec.rb +1 -0
  105. data/spec/lib/syntax_node_spec.rb +40 -6
  106. data/spec/macros/core_spec.rb +154 -21
  107. data/spec/macros/filters_spec.rb +1 -1
  108. data/spec/macros/html5_spec.rb +4 -5
  109. data/spec/macros/macros_spec.rb +6 -7
  110. data/spec/macros/web5_spec.rb +3 -3
  111. data/spec/macros/web_spec.rb +10 -7
  112. data/spec/macros/xml_spec.rb +11 -2
  113. data/spec/spec_helper.rb +11 -5
  114. data/spec/tasks/generate_spec.rb +40 -5
  115. data/spec/tasks/load_spec.rb +1 -13
  116. data/styles/coderay.css +147 -38
  117. data/styles/default.css +19 -22
  118. data/styles/pagination.css +30 -30
  119. data/tasks/generate.rake +54 -18
  120. data/tasks/load.rake +9 -24
  121. data/tasks/project.rake +0 -2
  122. metadata +208 -207
  123. data/.gitignore +0 -7
  124. data/VERSION +0 -1
  125. data/book/snippets.yml +0 -18
  126. data/lib/glyph/macro_helpers.rb +0 -282
  127. data/macros/html/block.rb +0 -124
  128. data/macros/html/inline.rb +0 -42
  129. data/macros/html/structure.rb +0 -191
  130. data/macros/html5/block.rb +0 -69
  131. data/macros/html5/inline.rb +0 -24
  132. data/macros/html5/structure.rb +0 -140
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
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
- Glyph::SNIPPETS[:a] = "this is a em[test] &[b]"
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
- Glyph::SNIPPETS[:c] = "This is a link to something afterwards: =>[#other]"
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
- Glyph::SNIPPETS[:t1].should == "Test #1"
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 "rewrite:" do
190
+ it "define:" do
187
191
  define_em_macro
188
- interpret("rewrite:[rw_test|em[{{0}}\\.em[{{a}}]]]").process
189
- output_for("rw_test[test @a[em[A!]]]").should == "<em>test<em><em>A!</em></em></em>"
190
- output_for("rw_test[]").should == "<em><em></em></em>"
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 "rewrite should detect mutual definitions" do
194
- define_em_macro
195
- lambda do
196
- interpret("rw:[rw_test2|em[rw_test2[{{0}}]]]").process
197
- end.should raise_error(Glyph::MacroError)
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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+ # encoding: utf-8
3
3
 
4
4
  describe "Filter Macros" do
5
5
 
@@ -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
- <img src="images/ligature.jpg" alt="ligature" />
81
- <figcaption>Ligature</figcaption>
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
@@ -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 alt="-" src="images/ligature.jpg" width="90%" height="90%" />
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="figure">
155
- <img src="images/ligature.jpg" alt="ligature" />
156
- <div class="caption">Ligature</div>
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 alt="-" src="images/ligature.jpg" />
163
+ <img src="images/ligature.jpg" />
165
164
  <div class="caption">Ligature</div>
166
165
  </div>
167
166
  }.gsub(/\n|\t/, '')
@@ -17,7 +17,7 @@ describe "Macro:" do
17
17
  end
18
18
 
19
19
  it "section (topic)" do
20
- interpret("contents[section[@src[a/web1.glyph]@title[Test]]]")
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><a href="/index.html">Contents</a><a href="/a/b/web2.html">&rarr; Topic #2</a></nav>}).blank?.should == false
30
- web2.match(%{<nav><a href="/a/web1.html">Topic #1 &larr;</a><a href="/index.html">Contents</a></nav>}).blank?.should == false
29
+ web1.match(%{<nav> | <a href="/index.html">Contents</a> | <a href="/a/b/web2.html">&rarr; 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
@@ -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"><a href="/index.html">Contents</a><a href="/a/b/web2.html">&rarr; Topic #2</a></div>}).blank?.should == false
37
- web2.match(%{<div class="navigation"><a href="/a/web1.html">Topic #1 &larr;</a><a href="/index.html">Contents</a></div>}).blank?.should == false
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#h_2"}).blank?.should == false
45
- index.match(%{href="/a/b/web2.html#h_6"}).blank?.should == false
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
- index.match(%{href="a/web1.html#h_2"}).blank?.should == true
53
- index.match(%{href="a/b/web2.html#h_6"}).blank?.should == true
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="#h_7"}).blank?.should == false # Header numbers are different...
59
+ index.match(%{href="#h_8"}).blank?.should == false # Header numbers are different...
57
60
  end
58
61
 
59
62
  end
@@ -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, "Unknown macro '*a'")
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::SNIPPETS.clear
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
- stdout_for do
73
- GLI.run cmd
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).match(/error/) == nil
99
+ run_command(cmd, true) == 0
94
100
  end
95
101
 
96
102
  def define_em_macro
@@ -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#h_6">Topic #2<\/a>/)
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