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.
Files changed (162) hide show
  1. data/.gitignore +7 -0
  2. data/AUTHORS.textile +8 -7
  3. data/CHANGELOG.textile +89 -8
  4. data/LICENSE.textile +1 -2
  5. data/README.textile +89 -61
  6. data/Rakefile +12 -10
  7. data/VERSION +1 -1
  8. data/benchmark.rb +1 -1
  9. data/book/config.yml +18 -4
  10. data/book/document.glyph +269 -45
  11. data/book/images/glyph/commands_tasks.png +0 -0
  12. data/book/images/{document_generation.png → glyph/document_generation.png} +0 -0
  13. data/book/images/glyph/glyph.eps +123 -0
  14. data/book/images/glyph/glyph.png +0 -0
  15. data/book/images/glyph/glyph.svg +29 -0
  16. data/book/lib/commands/commands.rb +11 -0
  17. data/book/lib/layouts/bookindex.glyph +127 -0
  18. data/book/lib/layouts/bookpage.glyph +129 -0
  19. data/book/lib/layouts/project.glyph +26 -0
  20. data/book/lib/macros/reference.rb +27 -7
  21. data/book/lib/tasks/tasks.rake +52 -0
  22. data/book/snippets.yml +1 -1
  23. data/book/text/{acknowledgement.glyph → acknowledgements.glyph} +4 -2
  24. data/book/text/changelog.glyph +29 -3
  25. data/book/text/compiling/compiling.glyph +44 -20
  26. data/book/text/compiling/lite_mode.glyph +0 -4
  27. data/book/text/compiling/programmatic_usage.glyph +1 -5
  28. data/book/text/config/document.glyph +35 -0
  29. data/book/text/config/filters.glyph +28 -0
  30. data/book/text/config/options.glyph +25 -0
  31. data/book/text/config/output.glyph +83 -0
  32. data/book/text/extending/bookmarks_headers.glyph +0 -5
  33. data/book/text/extending/command.glyph +56 -0
  34. data/book/text/extending/commands_tasks.glyph +39 -0
  35. data/book/text/extending/further_reading.glyph +0 -3
  36. data/book/text/extending/internals.glyph +3 -5
  37. data/book/text/extending/interpreting.glyph +0 -4
  38. data/book/text/extending/layouts.glyph +68 -0
  39. data/book/text/extending/macro_def.glyph +0 -5
  40. data/book/text/extending/output_format.glyph +78 -0
  41. data/book/text/extending/params_attrs.glyph +0 -3
  42. data/book/text/extending/placeholders.glyph +0 -4
  43. data/book/text/extending/task.glyph +46 -0
  44. data/book/text/extending/validators.glyph +5 -6
  45. data/book/text/getting_started/configuration.glyph +1 -5
  46. data/book/text/getting_started/create_project.glyph +1 -5
  47. data/book/text/getting_started/structure.glyph +0 -4
  48. data/book/text/introduction.glyph +100 -75
  49. data/book/text/license.glyph +1 -2
  50. data/book/text/macros/macros_block.glyph +8 -4
  51. data/book/text/macros/macros_core.glyph +0 -3
  52. data/book/text/macros/macros_filters.glyph +2 -7
  53. data/book/text/macros/macros_inline.glyph +0 -4
  54. data/book/text/macros/macros_structure.glyph +0 -4
  55. data/book/text/ref_commands.glyph +29 -7
  56. data/book/text/stats/bookmarks.glyph +49 -0
  57. data/book/text/stats/links.glyph +90 -0
  58. data/book/text/stats/macros.glyph +73 -0
  59. data/book/text/stats/snippets.glyph +50 -0
  60. data/book/text/stats/stats.glyph +79 -0
  61. data/book/text/text_editing/attribute_intro.glyph +22 -0
  62. data/book/text/text_editing/code.glyph +0 -5
  63. data/book/text/text_editing/conditionals.glyph +0 -4
  64. data/book/text/text_editing/esc_quot.glyph +64 -0
  65. data/book/text/text_editing/evaluation.glyph +0 -3
  66. data/book/text/text_editing/glyph_files.glyph +0 -3
  67. data/book/text/text_editing/images.glyph +0 -5
  68. data/book/text/text_editing/inclusions.glyph +0 -4
  69. data/book/text/text_editing/links.glyph +2 -7
  70. data/book/text/text_editing/macro_intro.glyph +1 -98
  71. data/book/text/text_editing/raw_html.glyph +0 -87
  72. data/book/text/text_editing/section_aliases.glyph +28 -0
  73. data/book/text/text_editing/sections.glyph +1 -32
  74. data/book/text/text_editing/stylesheets.glyph +3 -5
  75. data/book/text/text_editing/topics.glyph +33 -0
  76. data/book/text/text_editing/xml_fallback.glyph +73 -0
  77. data/book/text/troubleshooting/errors_command.glyph +0 -3
  78. data/book/text/troubleshooting/errors_generic.glyph +21 -6
  79. data/book/text/troubleshooting/errors_macro.glyph +11 -8
  80. data/book/text/troubleshooting/errors_parser.glyph +0 -3
  81. data/config.yml +60 -25
  82. data/glyph.gemspec +90 -36
  83. data/layouts/web/index.glyph +16 -0
  84. data/layouts/web/topic.glyph +15 -0
  85. data/layouts/web5/index.glyph +16 -0
  86. data/layouts/web5/topic.glyph +17 -0
  87. data/lib/glyph.rb +36 -49
  88. data/lib/glyph/analyzer.rb +253 -0
  89. data/lib/glyph/bookmark.rb +92 -0
  90. data/lib/glyph/commands.rb +9 -221
  91. data/lib/glyph/commands/add.rb +8 -0
  92. data/lib/glyph/commands/compile.rb +93 -0
  93. data/lib/glyph/commands/config.rb +38 -0
  94. data/lib/glyph/commands/init.rb +6 -0
  95. data/lib/glyph/commands/outline.rb +45 -0
  96. data/lib/glyph/commands/stats.rb +48 -0
  97. data/lib/glyph/commands/todo.rb +29 -0
  98. data/lib/glyph/config.rb +2 -0
  99. data/lib/glyph/document.rb +61 -30
  100. data/lib/glyph/interpreter.rb +2 -2
  101. data/lib/glyph/macro.rb +14 -5
  102. data/lib/glyph/macro_helpers.rb +280 -0
  103. data/lib/glyph/macro_validators.rb +37 -2
  104. data/lib/glyph/reporter.rb +182 -0
  105. data/lib/glyph/syntax_node.rb +37 -10
  106. data/lib/glyph/system_extensions.rb +8 -45
  107. data/lib/glyph/utils.rb +148 -0
  108. data/macros/core.rb +10 -15
  109. data/macros/filters.rb +4 -5
  110. data/macros/html/block.rb +46 -30
  111. data/macros/html/inline.rb +9 -35
  112. data/macros/html/structure.rb +59 -72
  113. data/macros/html5/block.rb +69 -0
  114. data/macros/html5/inline.rb +24 -0
  115. data/macros/html5/structure.rb +139 -0
  116. data/macros/xml.rb +1 -1
  117. data/spec/files/custom_command.rb +6 -0
  118. data/spec/files/custom_tasks.rake +6 -0
  119. data/spec/files/document_for_stats.glyph +12 -0
  120. data/spec/files/references.glyph +4 -0
  121. data/spec/files/web1.glyph +11 -0
  122. data/spec/files/web2.glyph +10 -0
  123. data/spec/files/web_doc.glyph +23 -0
  124. data/spec/lib/analyzer_spec.rb +137 -0
  125. data/spec/lib/bookmark_spec.rb +64 -0
  126. data/spec/lib/commands_spec.rb +30 -5
  127. data/spec/lib/document_spec.rb +49 -9
  128. data/spec/lib/glyph_spec.rb +21 -1
  129. data/spec/lib/macro_spec.rb +6 -6
  130. data/spec/lib/macro_validators_spec.rb +24 -0
  131. data/spec/lib/reporter_spec.rb +132 -0
  132. data/spec/macros/core_spec.rb +2 -3
  133. data/spec/macros/filters_spec.rb +2 -2
  134. data/spec/macros/html5_spec.rb +101 -0
  135. data/spec/macros/macros_spec.rb +16 -6
  136. data/spec/macros/web5_spec.rb +32 -0
  137. data/spec/macros/web_spec.rb +59 -0
  138. data/spec/macros/xml_spec.rb +1 -1
  139. data/spec/spec_helper.rb +24 -4
  140. data/spec/tasks/generate_spec.rb +54 -0
  141. data/spec/tasks/load_spec.rb +29 -3
  142. data/spec/tasks/project_spec.rb +21 -3
  143. data/styles/default.css +40 -4
  144. data/styles/pagination.css +59 -41
  145. data/tasks/generate.rake +110 -31
  146. data/tasks/load.rake +39 -7
  147. data/tasks/project.rake +9 -7
  148. metadata +115 -34
  149. data/book/images/glyph.png +0 -0
  150. data/book/images/glyph.svg +0 -351
  151. data/book/output/html/glyph.html +0 -4482
  152. data/book/output/html/images/document_generation.png +0 -0
  153. data/book/output/html/images/glyph.png +0 -0
  154. data/book/output/html/images/glyph.svg +0 -351
  155. data/book/output/pdf/glyph.pdf +4 -10254
  156. data/book/script/authors +0 -1
  157. data/book/script/changelog +0 -1
  158. data/book/script/license +0 -1
  159. data/book/script/readme +0 -1
  160. data/book/text/ref_config.glyph +0 -100
  161. data/book/text/ref_macros.glyph +0 -6
  162. data/book/text/troubleshooting/errors_intro.glyph +0 -3
@@ -17,10 +17,10 @@ describe "Filter Macros" do
17
17
  text = "textile[This is a _TEST_(TM).]"
18
18
  interpret text
19
19
  @p.document.output.should == "<p>This is a <em><span class=\"caps\">TEST</span></em>&#8482;.</p>"
20
- Glyph['filters.target'] = :latex
20
+ Glyph["output.#{Glyph['document.output']}.filter_target"] = :latex
21
21
  interpret text
22
22
  @p.document.output.should == "This is a \\emph{TEST}\\texttrademark{}.\n\n"
23
- Glyph['filters.target'] = :html
23
+ Glyph["output.#{Glyph['document.output']}.filter_target"] = :html
24
24
  Glyph['filters.redcloth.restrictions'] = [:no_span_caps]
25
25
  interpret text
26
26
  @p.document.output.should == "<p>This is a <em>TEST</em>&#8482;.</p>"
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
+
4
+ describe "Macro:" do
5
+
6
+ before do
7
+ reset_quiet
8
+ create_project
9
+ Glyph['document.output'] = 'html5'
10
+ Glyph.run! 'load:all'
11
+ end
12
+
13
+ after do
14
+ Glyph.lite_mode = false
15
+ reset_quiet
16
+ delete_project
17
+ end
18
+
19
+ it "section, chapter, header (html5)" do
20
+ text = "chapter[@title[Chapter X] ... section[@title[Section Y]@id[sec-y] ... section[@title[Another section] ...]]]"
21
+ interpret text
22
+ doc = @p.document
23
+ doc.output.gsub(/\n|\t/, '').should == %{<section class="chapter">
24
+ <header><h1 id="h_1">Chapter X</h1></header>...
25
+ <section class="section">
26
+ <header><h1 id="sec-y">Section Y</h1></header>...
27
+ <section class="section">
28
+ <header><h1 id="h_3">Another section</h1></header>...
29
+ </section>
30
+ </section>
31
+ </section>
32
+ }.gsub(/\n|\t/, '')
33
+ doc.bookmark?(:"sec-y").should == Glyph::Bookmark.new({:id => :"sec-y", :title => "Section Y", :file => nil})
34
+ end
35
+
36
+ it "document, head, style (html5)" do
37
+ interpret "document[head[style[test.sass]]]"
38
+ @p.document.output.gsub(/\n|\t/, '').should == %{
39
+ <!DOCTYPE html>
40
+ <html lang="en">
41
+ <head>
42
+ <title>#{Glyph::CONFIG.get("document.title")}</title>
43
+ <meta name="author" content="#{Glyph["document.author"]}" />
44
+ <meta name="copyright" content="#{Glyph["document.author"]}" />
45
+ <meta name="generator" content="Glyph v#{Glyph::VERSION} (http://www.h3rald.com/glyph)" />
46
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
47
+ <style type=\"text/css\">#main { background-color: blue; }</style>
48
+ </head>
49
+ </html>
50
+ }.gsub(/\n|\t/, '')
51
+ end
52
+
53
+ it "toc (html5)" do
54
+ file_copy Glyph::PROJECT/'../files/document_with_toc.glyph', Glyph::PROJECT/'document.glyph'
55
+ interpret file_load(Glyph::PROJECT/'document.glyph')
56
+ doc = @p.document
57
+ doc.output.gsub!(/\n|\t/, '')
58
+ doc.output.slice(/(.+?<\/nav>)/, 1).should == %{
59
+ <nav class="contents">
60
+ <h1 class="toc-header" id="toc">Table of Contents</h1>
61
+ <ol class="toc">
62
+ <li class="section"><a href="#h_1">Container section</a></li>
63
+ <li class="section"><a href="#md">Markdown</a></li>
64
+ </ol>
65
+ </nav>
66
+ }.gsub(/\n|\t/, '')
67
+ end
68
+
69
+ it "fmi (html5)" do
70
+ interpret "fmi[this topic|#test] #[test|Test]"
71
+ @p.document.output.should == %{<span class="fmi">
72
+ for more information on <mark>this topic</mark>,
73
+ see <a href="#test">Test</a></span> <a id="test">Test</a>}.gsub(/\n|\t/, '')
74
+ end
75
+
76
+ it "figure (html5)" do
77
+ interpret "figure[@alt[ligature]ligature.jpg|Ligature]"
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/, '')
84
+ end
85
+
86
+ it "draftcomment, todo (html5)" do
87
+ text1 = "dc[comment!]"
88
+ text2 = "![todo!]"
89
+ interpret text1
90
+ @p.document.output.should == ""
91
+ interpret text2
92
+ @p.document.output.should == ""
93
+ Glyph['document.draft'] = true
94
+ interpret text1
95
+ @p.document.output.should == %{<aside class="comment"><span class="comment-pre"><strong>Comment:</strong> </span>comment!</aside>}
96
+ interpret text2
97
+ @p.document.output.should == %{<aside class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>todo!</aside>}
98
+ @p.document.todos.length.should == 1
99
+ Glyph['document.draft'] = false
100
+ end
101
+ end
@@ -18,8 +18,8 @@ describe "Macro:" do
18
18
  interpret "this is a #[test|test]."
19
19
  doc = @p.document
20
20
  doc.output.should == "this is a <a id=\"test\">test</a>."
21
- doc.bookmarks.has_key?(:test).should == true
22
- lambda { interpret "this is a #[test|test]. #[test|This won't work!]"; @p.document }.should raise_error(Glyph::MacroError)
21
+ doc.bookmarks[:test].should == Glyph::Bookmark.new({:file => nil, :title => 'test', :id => :test})
22
+ lambda { interpret "this is a #[test|test]. #[test|This won't work!]"; @p.document }.should raise_error
23
23
  end
24
24
 
25
25
  it "section, chapter, header" do
@@ -36,7 +36,7 @@ describe "Macro:" do
36
36
  </div>
37
37
  </div>
38
38
  }.gsub(/\n|\t/, '')
39
- doc.bookmark?(:"sec-y").should == {:id => :"sec-y", :title => "Section Y"}
39
+ doc.bookmark?(:"sec-y").should == Glyph::Bookmark.new({:id => :"sec-y", :title => "Section Y", :file => nil})
40
40
  end
41
41
 
42
42
  it "document, head, style" do
@@ -50,6 +50,7 @@ describe "Macro:" do
50
50
  <meta name="author" content="#{Glyph["document.author"]}" />
51
51
  <meta name="copyright" content="#{Glyph["document.author"]}" />
52
52
  <meta name="generator" content="Glyph v#{Glyph::VERSION} (http://www.h3rald.com/glyph)" />
53
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
53
54
  <style type=\"text/css\">#main { background-color: blue; }</style>
54
55
  </head>
55
56
  </html>
@@ -66,6 +67,7 @@ describe "Macro:" do
66
67
  <meta name="author" content="#{Glyph["document.author"]}" />
67
68
  <meta name="copyright" content="#{Glyph["document.author"]}" />
68
69
  <meta name="generator" content="Glyph v#{Glyph::VERSION} (http://www.h3rald.com/glyph)" />
70
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
69
71
  <style type=\"text/css\">#main { background-color: blue; }</style>
70
72
  </head>
71
73
  </html>
@@ -78,6 +80,14 @@ describe "Macro:" do
78
80
  @p.document.output.gsub(/\n|\t/, '').should == result
79
81
  end
80
82
 
83
+ it "style should import and link stylesheets" do
84
+ Glyph['document.styles'] = 'import'
85
+ output_for("head[style[default.css]]").match(/@import url\("styles\/default\.css"\)/).blank?.should == false
86
+ Glyph['document.styles'] = 'link'
87
+ output_for("head[style[default.css]]").match(%{<link href="styles/default.css" rel="stylesheet" type="text/css" />}).blank?.should == false
88
+ Glyph['document.styles'] = 'embed'
89
+ end
90
+
81
91
  it "toc" do
82
92
  file_copy Glyph::PROJECT/'../files/document_with_toc.glyph', Glyph::PROJECT/'document.glyph'
83
93
  interpret file_load(Glyph::PROJECT/'document.glyph')
@@ -85,10 +95,10 @@ describe "Macro:" do
85
95
  doc.output.gsub!(/\n|\t/, '')
86
96
  doc.output.slice(/(.+?<\/div>)/, 1).should == %{
87
97
  <div class="contents">
88
- <h2 class="toc-header" id="h_toc">Table of Contents</h2>
98
+ <h2 class="toc-header" id="toc">Table of Contents</h2>
89
99
  <ol class="toc">
90
- <li class=" section"><a href="#h_1">Container section</a></li>
91
- <li class=" section"><a href="#md">Markdown</a></li>
100
+ <li class="section"><a href="#h_1">Container section</a></li>
101
+ <li class="section"><a href="#md">Markdown</a></li>
92
102
  </ol>
93
103
  </div>
94
104
  }.gsub(/\n|\t/, '')
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
+
4
+ describe "Macro:" do
5
+
6
+ before do
7
+ create_web_project
8
+ Glyph['document.output'] = 'web5'
9
+ Glyph['document.extension'] = '.html'
10
+ Glyph.run! 'load:all'
11
+ end
12
+
13
+ after do
14
+ Glyph.lite_mode = false
15
+ reset_quiet
16
+ delete_project
17
+ end
18
+
19
+ it "section (topic)" do
20
+ interpret("contents[section[@src[a/web1.glyph]@title[Test]]]")
21
+ topic = @p.document.topics[0]
22
+ topic[:contents].match(/<article>/).blank?.should == false
23
+ end
24
+
25
+ it "navigation" do
26
+ Glyph.run! 'generate:web5'
27
+ web1 = Glyph.file_load(Glyph::PROJECT/'output/web5/a/web1.html')
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
31
+ end
32
+ end
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
+
4
+ describe "Macro:" do
5
+
6
+ before do
7
+ create_web_project
8
+ Glyph['document.output'] = 'web'
9
+ Glyph.run! 'load:all'
10
+ end
11
+
12
+ after do
13
+ Glyph.lite_mode = false
14
+ reset_quiet
15
+ delete_project
16
+ end
17
+
18
+ it "section (topic)" do
19
+ lambda { output_for("section[@src[test]]") }.should raise_error(Glyph::MacroError, "Macro 'section' requires a 'title' attribute")
20
+ interpret("section[@src[a/web1.glyph]@title[Test]]")
21
+ topic = @p.document.topics[0]
22
+ topic.blank?.should == false
23
+ topic[:id].should == :t_0
24
+ topic[:title].should == "Test"
25
+ topic[:src].should == "a/web1.glyph"
26
+ topic[:contents].match(/id="w1_3"/).blank?.should == false
27
+ Glyph['document.output'] = 'html'
28
+ Glyph.run! 'load:macros'
29
+ output_for("contents[section[@src[a/web1.glyph]@title[Test]]]").match(/id="w1_3"/).blank?.should == false
30
+ end
31
+
32
+ it "navigation" do
33
+ Glyph.run! 'generate:web'
34
+ web1 = Glyph.file_load(Glyph::PROJECT/'output/web/a/web1.html')
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
38
+ end
39
+
40
+ it "toc should only list topics" do
41
+ Glyph.run! 'generate:web'
42
+ index = Glyph.file_load(Glyph::PROJECT/'output/web/index.html')
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
46
+ delete_project
47
+ reset_quiet
48
+ create_web_project
49
+ Glyph['document.output'] = 'html'
50
+ Glyph.run! 'generate:html'
51
+ 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.match(%{<li class="section"><a href="#h_1">Web Document</a></li>}).blank?.should == false
55
+ index.match(%{href="#h_2"}).blank?.should == false
56
+ index.match(%{href="#h_7"}).blank?.should == false # Header numbers are different...
57
+ end
58
+
59
+ end
@@ -46,7 +46,7 @@ describe "Glyph Language" do
46
46
  end
47
47
 
48
48
  it "should notify the user that a macro is not found for invalid elements if xml_fallback is enabled" do
49
- # Assuming language.options.xml_fallback = true
49
+ # Assuming options.xml_fallback = true
50
50
  language('glyph')
51
51
  lambda { interpret("*a[test]").document }.should raise_error(Glyph::MacroError, "Unknown macro '*a'")
52
52
  end
data/spec/spec_helper.rb CHANGED
@@ -39,6 +39,19 @@ def create_project
39
39
  file_copy Glyph::SPEC_DIR/'files/ligature.jpg', Glyph::PROJECT/'images/ligature.jpg'
40
40
  end
41
41
 
42
+ def create_web_project
43
+ reset_quiet
44
+ create_project_dir
45
+ return if Glyph.lite?
46
+ Glyph.run! 'project:create', Glyph::PROJECT.to_s
47
+ file_copy Glyph::SPEC_DIR/'files/web_doc.glyph', Glyph::PROJECT/'document.glyph'
48
+ (Glyph::PROJECT/'text/a/b').mkpath
49
+ file_copy Glyph::SPEC_DIR/'files/web1.glyph', Glyph::PROJECT/'text/a/web1.glyph'
50
+ file_copy Glyph::SPEC_DIR/'files/web2.glyph', Glyph::PROJECT/'text/a/b/web2.glyph'
51
+ file_copy Glyph::SPEC_DIR/'files/test.sass', Glyph::PROJECT/'styles/test.sass'
52
+ file_copy Glyph::SPEC_DIR/'files/ligature.jpg', Glyph::PROJECT/'images/ligature.jpg'
53
+ end
54
+
42
55
  def delete_project_dir
43
56
  return unless Glyph::PROJECT.exist?
44
57
  Glyph::PROJECT.children.each do |f|
@@ -56,13 +69,20 @@ def delete_project
56
69
  end
57
70
 
58
71
  def run_command(cmd)
72
+ stdout_for do
73
+ GLI.run cmd
74
+ end
75
+ end
76
+
77
+ def stdout_for(&block)
59
78
  out = StringIO.new
79
+ err = StringIO.new
60
80
  old_stdout = $stdout
61
81
  old_stderr = $stderr
62
82
  $stdout = out
63
- $stderr = out
83
+ $stderr = err
64
84
  Glyph['system.quiet'] = false
65
- GLI.run cmd
85
+ block.call
66
86
  Glyph['system.quiet'] = true
67
87
  $stdout = old_stdout
68
88
  $stderr = old_stderr
@@ -88,7 +108,7 @@ end
88
108
  def language(set)
89
109
  reset_quiet
90
110
  Glyph.run 'load:config'
91
- Glyph['language.set'] = set
111
+ Glyph['options.macro_set'] = set
92
112
  Glyph.run 'load:macros'
93
113
  end
94
114
 
@@ -105,7 +125,7 @@ def create_tree(text)
105
125
  end
106
126
 
107
127
  def create_doc(tree)
108
- Glyph::Document.new tree, {}
128
+ Glyph::Document.new tree
109
129
  end
110
130
 
111
131
  def filter(text)
@@ -8,6 +8,7 @@ describe "generate" do
8
8
  end
9
9
 
10
10
  after do
11
+ reset_quiet
11
12
  delete_project
12
13
  end
13
14
 
@@ -28,4 +29,57 @@ describe "generate" do
28
29
  (Glyph::PROJECT/'output/html/images/test/ligature.jpg').exist?.should == true
29
30
  end
30
31
 
32
+ it "should copy styles if necessary" do
33
+ Glyph['document.styles'] = 'import'
34
+ require 'sass'
35
+ file_write Glyph::PROJECT/'document.glyph', "head[style[default.css]\nstyle[test.sass]]"
36
+ lambda { Glyph.run! 'generate:html' }.should_not raise_error
37
+ (Glyph::PROJECT/'output/html/styles/default.css').exist?.should == true
38
+ (Glyph::PROJECT/'output/html/styles/test.css').exist?.should == true
39
+ end
40
+
41
+ it ":web should generate multiple html documents" do
42
+ reset_web = lambda do
43
+ delete_project
44
+ reset_quiet
45
+ create_web_project
46
+ Glyph['document.output'] = 'web'
47
+ Glyph['document.styles'] = 'link'
48
+ Glyph.run! 'load:all'
49
+ end
50
+ # check that the user didn't create a styles or images directory under /text
51
+ reset_web.call
52
+ (Glyph::PROJECT/'text/images').mkdir
53
+ lambda { Glyph.run! 'generate:web'}.should raise_error(RuntimeError, "You cannot have an 'images' directory under your 'text' directory.")
54
+ reset_web.call
55
+ (Glyph::PROJECT/'text/styles').mkdir
56
+ lambda { Glyph.run! 'generate:web'}.should raise_error(RuntimeError, "You cannot have a 'styles' directory under your 'text' directory.")
57
+ reset_web.call
58
+ # check that the task can be run without errors
59
+ reset_web.call
60
+ Glyph["output.#{Glyph['document.output']}.base"] = "/test/"
61
+ #lambda {
62
+ Glyph.run! 'generate:web'
63
+ #}.should_not raise_error
64
+ # check that images are copied
65
+ (Glyph::PROJECT/'output/web/images/ligature.jpg').exist?.should == true
66
+ # check that stylesheets are copied
67
+ (Glyph::PROJECT/'output/web/styles/default.css').exist?.should == true
68
+ (Glyph::PROJECT/'output/web/styles/test.css').exist?.should == true
69
+ # check that index.html is created
70
+ index = (Glyph::PROJECT/'output/web/index.html')
71
+ 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>/)
73
+ # check that topics are copied in the proper directories
74
+ web1 = (Glyph::PROJECT/'output/web/a/web1.html')
75
+ web1.exist?.should == true
76
+ web2 = (Glyph::PROJECT/'output/web/a/b/web2.html')
77
+ web2.exist?.should == true
78
+ # Check that placeholders are replaced correctly and that links are valid
79
+ file_load(web2).match(/<a href="\/test\/a\/web1\.html#w1_3">Test #1b<\/a>/).blank?.should == false
80
+ file_load(web1).match(/<a href="\/test\/a\/b\/web2\.html#w2_1">Test #2a<\/a>/).blank?.should == false
81
+ file_load(web1).match(/<a href="#w1_3">Test #1b<\/a>/).blank?.should == false
82
+ end
83
+
84
+
31
85
  end
@@ -37,8 +37,8 @@ describe "load" do
37
37
 
38
38
  it "[macros] should be able to load only core macros" do
39
39
  language 'core'
40
- output_for("$:[language.set|glyph]").blank?.should == true
41
- Glyph['language.set'].should == 'glyph'
40
+ output_for("$:[options.macro_set|glyph]").blank?.should == true
41
+ Glyph['options.macro_set'].should == 'glyph'
42
42
  end
43
43
 
44
44
  it "[macros] should be able to load only filter macros" do
@@ -47,7 +47,7 @@ describe "load" do
47
47
  end
48
48
 
49
49
  it "[config] should load configuration files and apply overrides" do
50
- Glyph.config_refresh
50
+ Glyph.config_refresh
51
51
  lambda { Glyph.run! 'load:config'}.should_not raise_error
52
52
  Glyph['system.quiet'] = true
53
53
  Glyph::PROJECT_CONFIG.blank?.should == false
@@ -55,4 +55,30 @@ describe "load" do
55
55
  Glyph['system.structure.headers'].class.to_s.should == "Array"
56
56
  end
57
57
 
58
+ it "[macros] should load HTML macros as well when generating web output" do
59
+ Glyph['document.output'] = 'web'
60
+ Glyph.run! 'load:macros'
61
+ Glyph::MACROS[:section].blank?.should == false
62
+ end
63
+
64
+ it "[layouts] should load layouts" do
65
+ Glyph['document.output'] = 'web'
66
+ Glyph.run! 'load:macros'
67
+ Glyph::MACROS[:"layout:topic"].blank?.should == false
68
+ end
69
+
70
+ it "[tasks] should load tasks" do
71
+ reset_quiet
72
+ file_copy Glyph::PROJECT/"../files/custom_tasks.rake", Glyph::PROJECT/"lib/tasks/custom_tasks.rake"
73
+ Glyph.run 'load:all'
74
+ stdout_for { Glyph.run 'custom:hello'}.should == "Hello, World!\n"
75
+ end
76
+
77
+ it "[commands] should load tasks" do
78
+ reset_quiet
79
+ file_copy Glyph::PROJECT/"../files/custom_command.rb", Glyph::PROJECT/"lib/commands/custom_command.rb"
80
+ Glyph.run 'load:all'
81
+ run_command(['hello']).should == "Hello, World!\n"
82
+ end
83
+
58
84
  end