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
@@ -11,11 +11,11 @@ describe "project:create" do
11
11
  delete_project_dir
12
12
  end
13
13
 
14
- it "[create] should not create a new project if no valid directory is supplied" do
14
+ it "should not create a new project if no valid directory is supplied" do
15
15
  lambda { Glyph.run! 'project:create', 'test_dir' }.should raise_error
16
16
  end
17
17
 
18
- it "[create] should create a new project if an existing empty directory is supplied" do
18
+ it "should create a new project if an existing empty directory is supplied" do
19
19
  lambda { Glyph.run! 'project:create', Glyph::PROJECT }.should_not raise_error
20
20
  (Glyph::PROJECT/'lib').exist?.should == true
21
21
  (Glyph::PROJECT/'document.glyph').exist?.should == true
@@ -26,7 +26,25 @@ describe "project:create" do
26
26
  (Glyph::PROJECT/'output').exist?.should == true
27
27
  end
28
28
 
29
- it "[add] should add new files to project" do
29
+ it "should create a project in a directory containing just Gemfiles or hidden files" do
30
+ file_write Glyph::PROJECT/".test", "..."
31
+ file_write Glyph::PROJECT/"Gemfile", "..."
32
+ lambda { Glyph.run! 'project:create', Glyph::PROJECT }.should_not raise_error
33
+ end
34
+ end
35
+
36
+ describe "project:add" do
37
+
38
+ before do
39
+ create_project_dir
40
+ end
41
+
42
+ after do
43
+ delete_project_dir
44
+ end
45
+
46
+
47
+ it "should add new files to project" do
30
48
  create_project
31
49
  lambda { Glyph.run 'project:add', 'test.textile'}.should_not raise_error
32
50
  (Glyph::PROJECT/'text/test.textile').exist?.should == true
data/styles/default.css CHANGED
@@ -35,7 +35,7 @@ body {
35
35
  margin: auto;
36
36
  text-align: center;
37
37
  }
38
- .title, h1 {
38
+ .titlepage h1, .halftitlepage h1 {
39
39
  font-size: 2.5em;
40
40
  font-weight: bold;
41
41
  line-height: 1.5em;
@@ -174,22 +174,27 @@ body {
174
174
  color: #000;
175
175
  font-size: 1em;
176
176
  }
177
- h2 {
177
+ h2, section section h1, h1.toc-header {
178
178
  display: block;
179
179
  font-size: 2em;
180
180
  font-weight: bold;
181
181
  margin: 3em 0 1em 0;
182
182
  }
183
- h3 {
183
+ h3, section section section h1 {
184
184
  font-size: 1.6em;
185
185
  font-weight: bold;
186
186
  margin: 3em 0 1em 0;
187
187
  }
188
- h4 {
188
+ h4, section section section section h1 {
189
189
  font-size: 1.3em;
190
190
  font-weight: bold;
191
191
  margin: 3em 0 1em 0;
192
192
  }
193
+ h5, section section section section section h1 {
194
+ font-size: 1.2em;
195
+ font-weight: bold;
196
+ margin: 3em 0 1em 0;
197
+ }
193
198
  em {
194
199
  font-style: italic;
195
200
  }
@@ -213,6 +218,33 @@ span.line-numbers{
213
218
  padding: 3px;
214
219
  }
215
220
 
221
+ nav, .navigation {
222
+ display: block;
223
+ margin: 1em auto;
224
+ text-align: center;
225
+ border: 1px solid #E6E6E6;
226
+ }
227
+
228
+ nav.contents {
229
+ margin: auto;
230
+ text-align: left;
231
+ border: none;
232
+ }
233
+
234
+ nav a, .navigation a {
235
+ margin: 1em;
236
+ }
237
+
238
+ nav.contents a {
239
+ margin: 0;
240
+ }
241
+
242
+ mark {
243
+ font-weight:bolder;
244
+ font-style: italic;
245
+ background: none;
246
+ }
247
+
216
248
  pre>code {
217
249
  font-size: 1em;
218
250
  }
@@ -225,6 +257,10 @@ td>div.code, td>code {
225
257
  padding: 0.2em;
226
258
  }
227
259
 
260
+ .topic{
261
+ margin: 2em auto;
262
+ }
263
+
228
264
  /* FONTS */
229
265
 
230
266
  body {
@@ -44,6 +44,8 @@ ol.toc {
44
44
  string-set: book-title content();
45
45
  }
46
46
 
47
+ /* TOC Counters */
48
+
47
49
  .toc>li[class~=chapter] {
48
50
  counter-increment: toc1;
49
51
  counter-reset: toc2;
@@ -86,41 +88,56 @@ ol.toc {
86
88
  margin: 1em 0;
87
89
  }
88
90
 
89
- .toc ol li[class~=bodymatter]::before {
91
+ /* TOC Margins */
92
+
93
+ .toc ol li[class]::before {
90
94
  margin-left: 1em;
91
- content: counter(toc1) "." counter(toc2) " ";
92
95
  }
93
- .toc ol li[class~=appendix]::before {
94
- margin-left: 1em;
95
- content: counter(appendix1, upper-latin) "." counter(toc2) " ";
96
+
97
+ .toc ol ol li[class]::before {
98
+ margin-left: 2em;
96
99
  }
97
100
 
101
+ .toc ol ol ol li[class]::before {
102
+ margin-left: 3em;
103
+ }
104
+
105
+ .toc ol ol ol ol li[class]::before {
106
+ margin-left: 4em;
107
+ }
108
+
109
+ /* TOC Numbers */
110
+
111
+ .toc ol li[class~=frontmatter]::before {
112
+ content: " ";
113
+ }
114
+
115
+ .toc ol li[class~=bodymatter]::before {
116
+ content: counter(toc1) "." counter(toc2) " ";
117
+ }
118
+ .toc ol li[class~=appendix]::before {
119
+ content: counter(appendix1, upper-latin) "." counter(toc2) " ";
120
+ }
98
121
 
99
122
  .toc ol ol li[class~=bodymatter]::before {
100
- margin-left: 1em;
101
- content: counter(toc1) "." counter(toc2) "." counter(toc3) " ";
123
+ content: counter(toc1) "." counter(toc2) "." counter(toc3) " ";
102
124
  }
103
125
  .toc ol ol li[class~=appendix]::before {
104
- margin-left: 1em;
105
- content: counter(appendix1, upper-latin) "." counter(toc2) "." counter(toc3) " ";
126
+ content: counter(appendix1, upper-latin) "." counter(toc2) "." counter(toc3) " ";
106
127
  }
107
128
 
108
129
  .toc ol ol ol li[class~=bodymatter]::before {
109
- margin-left: 1em;
110
- content: counter(toc1) "." counter(toc2) "." counter(toc3) "." counter(toc4) " ";
130
+ content: counter(toc1) "." counter(toc2) "." counter(toc3) "." counter(toc4) " ";
111
131
  }
112
132
  .toc ol ol ol li[class~=appendix]::before {
113
- margin-left: 1em;
114
- content: counter(appendix1, upper-latin) "." counter(toc2) "." counter(toc3) "." counter(toc4) " ";
133
+ content: counter(appendix1, upper-latin) "." counter(toc2) "." counter(toc3) "." counter(toc4) " ";
115
134
  }
116
135
 
117
136
  .toc ol ol ol ol li[class~=bodymatter]::before {
118
- margin-left: 1em;
119
- content: counter(toc1) "." counter(toc2) "." counter(toc3) "." counter(toc4) "." counter(toc5) " ";
137
+ content: counter(toc1) "." counter(toc2) "." counter(toc3) "." counter(toc4) "." counter(toc5) " ";
120
138
  }
121
139
  .toc ol ol ol ol li[class~=appendix]::before {
122
- margin-left: 1em;
123
- content: counter(appendix1, upper-latin) "." counter(toc2) "." counter(toc3) "." counter(toc4) "." counter(toc5) " ";
140
+ content: counter(appendix1, upper-latin) "." counter(toc2) "." counter(toc3) "." counter(toc4) "." counter(toc5) " ";
124
141
  }
125
142
 
126
143
  div.frontmatter{
@@ -131,40 +148,41 @@ div.backmatter{
131
148
  page: backmatter;
132
149
  }
133
150
 
134
- .bodymatter h2::before {
135
- content: "Chapter " counter(h2, upper-roman) " – ";
151
+ .bodymatter h2::before, .bodymatter h1:before {
152
+ content: "Chapter " counter(h2, upper-roman) ": ";
136
153
  counter-reset: footnote;
137
154
  }
138
155
 
139
- .backmatter h2::before {
140
- content: "Appendix " counter(a2, upper-latin) " – ";
156
+ .backmatter h2::before, .bodymatter section h1:before {
157
+ content: "Appendix " counter(a2, upper-latin) ": ";
141
158
  }
142
159
 
143
- .bodymatter h3::before {
144
- content: counter(h2) "." counter(h3) " ";
160
+ .bodymatter h3::before,.bodymatter section h1:before {
161
+ content: counter(h2) "." counter(h3) " ";
145
162
  }
146
163
 
147
- .backmatter h3::before {
148
- content: counter(a2, upper-latin) "." counter(h3) " ";
164
+ .backmatter h3::before, .bodymatter section section h1:before {
165
+ content: counter(a2, upper-latin) "." counter(h3) " ";
149
166
  }
150
167
 
151
- .bodymatter h4::before {
152
- content: counter(h2) "." counter(h3) "." counter(h4) " ";
168
+ .bodymatter h4::before, .bodymatter section section h1:before {
169
+ content: counter(h2) "." counter(h3) "." counter(h4) " ";
153
170
  }
154
171
 
155
- .backmatter h4::before {
156
- content: counter(a2, upper-latin) "." counter(h3) "." counter(h4) " ";
172
+ .backmatter h4::before, .bodymatter section section section h2:before {
173
+ content: counter(a2, upper-latin) "." counter(h3) "." counter(h4) " ";
157
174
  }
158
175
 
159
- .bodymatter h5::before {
160
- content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) " ";
176
+ .bodymatter h5::before, .bodymatter section section section section h2:before {
177
+ content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) " ";
161
178
  }
162
179
 
163
- .backmatter h5::before {
164
- content: counter(a2, upper-latin) "." counter(h3) "." counter(h4) "." counter(h5) " ";
180
+ .backmatter h5::before, .bodymatter section section section section h2:before {
181
+ content: counter(a2, upper-latin) "." counter(h3) "." counter(h4) "." counter(h5) " ";
165
182
  }
166
183
 
167
- h2 {
184
+ h2, section h1 {
185
+ padding-top: 2em;
168
186
  string-set: chapter-title content();
169
187
  page-break-before: always;
170
188
  }
@@ -173,32 +191,32 @@ h2 {
173
191
  page-break-before: avoid;
174
192
  }
175
193
 
176
- .bodymatter h2{
194
+ .bodymatter h2, .bodymatter h1{
177
195
  counter-increment: h2;
178
196
  counter-reset: h3;
179
197
  }
180
198
 
181
- .backmatter h2{
199
+ .backmatter h2, .backmatter h1{
182
200
  counter-increment: a2;
183
201
  counter-reset: h3;
184
202
  }
185
203
 
186
- .bodymatter h3, .backmatter h3 {
204
+ .bodymatter h3, .backmatter h3, .bodymatter section h1, .backmatter section h1 {
187
205
  counter-increment: h3;
188
206
  counter-reset: h4;
189
207
  }
190
208
 
191
- .bodymatter h4, .backmatter h4 {
209
+ .bodymatter h4, .backmatter h4, .bodymatter section section h1, .backmatter section section h1 {
192
210
  counter-increment: h4;
193
211
  counter-reset: h5;
194
212
  }
195
213
 
196
- .bodymatter h5, .backmatter h5 {
214
+ .bodymatter h5, .backmatter h5, .bodymatter section section section h1, .backmatter section section section h1 {
197
215
  counter-increment: h5;
198
216
  }
199
217
 
200
- h2, h3, h4, h5 { page-break-after: avoid }
201
- table, .box, .note, .important, .tip, .caution, .code { page-break-inside: avoid }
218
+ h1, h2, h3, h4, h5 { page-break-after: avoid }
219
+ .box, .note, .important, .tip, .caution, .code { page-break-inside: avoid }
202
220
 
203
221
  /* Footnotes */
204
222
 
data/tasks/generate.rake CHANGED
@@ -2,52 +2,121 @@
2
2
 
3
3
  namespace :generate do
4
4
 
5
- desc "Process source"
5
+ include Glyph::Utils
6
+
7
+ desc "Copy image files"
8
+ task :images => [:document] do
9
+ unless Glyph.lite? then
10
+ info "Copying images..."
11
+ with_files_from('images') do |src, dest|
12
+ file_copy src, dest
13
+ end
14
+ end
15
+ end
16
+
17
+ desc "Copy style files"
18
+ task :styles => [:document] do
19
+ if Glyph['document.styles'].in?(['link', 'import']) && !Glyph.lite? then
20
+ info "Copying stylesheets..."
21
+ output = (Glyph['document.output'] == 'pdf') ? 'html' : Glyph['document.output']
22
+ out_dir = Glyph::PROJECT/"output/#{output}/styles"
23
+ Glyph.document.styles.each do |f|
24
+ styles_dir = f.parent.to_s.include?(Glyph::HOME/'styles') ? Glyph::HOME/'styles' : Glyph::PROJECT/'styles'
25
+ subdir = f.parent.relative_path_from(styles_dir).to_s.gsub(/^\./, '')
26
+ dir = out_dir/subdir
27
+ dir.mkpath
28
+ case
29
+ when f.extname == ".css" then
30
+ file_copy f, dir/f.basename
31
+ when f.extname == ".sass" then
32
+ style = Sass::Engine.new(file_load(f.to_s)).render
33
+ out_file = dir/f.basename.to_s.gsub(/\.sass$/, '.css')
34
+ file_write out_file, style
35
+ else
36
+ raise RuntimeError, "Unsupported stylesheet: '#{f.basename}'"
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ desc "Process source files and create a Glyph document"
6
43
  task :document => ["load:all"] do
7
44
  if Glyph.lite? then
8
45
  text = file_load Pathname.new(Glyph['document.source'])
9
46
  else
10
47
  text = file_load Glyph::PROJECT/Glyph['document.source']
11
48
  end
12
- interpreter = Glyph::Interpreter.new text, :source => {:name => "#{Glyph['document.source']}"}, :info => true
49
+ require 'net/http' if Glyph['options.url_validation']
50
+ name = Glyph['document.source']
51
+ interpreter = Glyph::Interpreter.new text, :source => {:name => name, :file => name, :topic => nil}, :info => true
13
52
  interpreter.parse
14
- Glyph.info "Processing..."
53
+ info "Processing..."
15
54
  interpreter.process
16
- Glyph.info "Post-processing..."
55
+ info "Post-processing..."
17
56
  interpreter.postprocess
18
57
  Glyph.document = interpreter.document
19
58
  end
20
59
 
21
- desc "Create a standalone html file"
22
- task :html => :document do
23
- Glyph.info "Generating HTML file..."
60
+ desc "Create a standalone HTML file"
61
+ task :html => [:images, :styles] do
62
+ info "Generating HTML file..."
24
63
  if Glyph.lite? then
25
64
  out = Pathname.new Glyph['document.output_dir']
26
65
  file = (Glyph['document.output'] == 'pdf') ? Glyph['document.filename']+".html" : Glyph['document.output_file']
27
66
  else
28
- out = Glyph::PROJECT/"output/html"
29
- file = "#{Glyph['document.filename']}.html"
67
+ out = (Glyph['document.output'] == 'pdf') ? 'html' : Glyph['document.output']
68
+ out = Glyph::PROJECT/"output/#{out}"
69
+ extension = (Glyph['document.output'] == 'pdf') ? Glyph["output.html.extension"] : Glyph["output.#{Glyph['document.output']}.extension"]
70
+ file = "#{Glyph['document.filename']}#{extension}"
30
71
  end
31
- extension = '.html'
32
72
  out.mkpath
33
73
  file_write out/file, Glyph.document.output
34
- Glyph.info "'#{file}' generated successfully."
35
- unless Glyph.lite? then
36
- images = Glyph::PROJECT/'output/html/images'
37
- images.mkpath
38
- (Glyph::PROJECT/'images').find do |i|
39
- if i.file? then
40
- dest = "#{Glyph::PROJECT/'output/html/images'}/#{i.relative_path_from(Glyph::PROJECT/'images')}"
41
- Pathname.new(dest).parent.mkpath
42
- file_copy i.to_s, dest
43
- end
44
- end
74
+ info "'#{file}' generated successfully."
75
+ end
76
+
77
+ desc "Create a standalone HTML 5 file"
78
+ task :html5 => [:html] do; end
79
+
80
+ desc "Create multiple HTML files"
81
+ task :web => [:images, :styles] do
82
+ info "Generating HTML files..."
83
+ if Glyph.lite? then
84
+ out = Pathname.new Glyph['document.output_dir']
85
+ else
86
+ out = Glyph::PROJECT/"output/#{Glyph['document.output']}"
87
+ end
88
+ raise RuntimeError, "You cannot have an 'images' directory under your 'text' directory." if (Glyph::PROJECT/"text/images").exist?
89
+ raise RuntimeError, "You cannot have a 'styles' directory under your 'text' directory." if (Glyph::PROJECT/"text/styles").exist?
90
+ out.mkpath
91
+ index_layout = Glyph["output.#{Glyph['document.output']}.layouts.index"] || :index
92
+ # Generate index topic
93
+ context = {}
94
+ context[:document] = Glyph::Document.new(Glyph::DocumentNode.new).inherit_from(Glyph.document)
95
+ context[:source] = {:name => "layout:#{index_layout}", :file => "layouts/#{index_layout}.glyph"}
96
+ # Do not display errors (already displayed when document is finalized).
97
+ q = Glyph['system.quiet']
98
+ Glyph['system.quiet'] = true
99
+ index_topic = Glyph::Interpreter.new("layout:#{index_layout}[]", context).document.output
100
+ Glyph['system.quiet'] = q
101
+ file_write out/"index.html", index_topic
102
+ # Generate all topics
103
+ Glyph.document.topics.each do |topic|
104
+ extension = "#{Glyph["output.#{Glyph['document.output']}.extension"]}"
105
+ file = topic[:src].gsub(/\..+$/, extension)
106
+ file += extension unless file.match /#{Regexp.escape(extension)}$/
107
+ info "Generating topic '#{file}'"
108
+ (out/file).parent.mkpath
109
+ file_write out/file, topic[:contents]
45
110
  end
111
+ info "Web output generated successfully."
46
112
  end
47
113
 
114
+ desc "Create multiple HTML 5 files"
115
+ task :web5 => [:web] do; end
116
+
48
117
  desc "Create a pdf file"
49
118
  task :pdf => :html do
50
- Glyph.info "Generating PDF file..."
119
+ info "Generating PDF file..."
51
120
  if Glyph.lite? then
52
121
  out = Pathname.new Glyph['document.output_dir']
53
122
  src = out/"#{Glyph['document.filename']}.html"
@@ -58,18 +127,28 @@ namespace :generate do
58
127
  file = "#{Glyph['document.filename']}.pdf"
59
128
  end
60
129
  out.mkpath
61
- case Glyph['tools.pdf_generator']
62
- when 'prince' then
63
- ENV['PATH'] += ";#{ENV['ProgramFiles']}\\Prince\\Engine\\bin" if RUBY_PLATFORM.match /mswin/
64
- res = system "prince #{src} -o #{out/"#{file}"}"
65
- if res then
66
- Glyph.info "'#{file}' generated successfully."
130
+ generate_pdf = lambda do |path, cmd|
131
+ ENV['PATH'] += path if RUBY_PLATFORM.match /mswin/
132
+ IO.popen(cmd+" 2>&1") do |pipe|
133
+ pipe.sync = true
134
+ while str = pipe.gets do
135
+ puts str
136
+ end
137
+ end
138
+ if (out/file).exist? then
139
+ info "'#{file}' generated successfully."
67
140
  else
68
- Glyph.error "An error occurred while generating #{file}"
141
+ error "An error occurred while generating #{file}"
69
142
  end
70
- # TODO: support other PDF renderers
143
+ end
144
+ case Glyph['output.pdf.generator']
145
+ when 'prince' then
146
+ generate_pdf.call ";#{ENV['ProgramFiles']}\\Prince\\Engine\\bin", %{prince #{src} -o #{out/"#{file}"}}
147
+ when 'wkhtmltopdf' then
148
+ generate_pdf.call ";#{ENV['ProgramFiles']}\\wkhtmltopdf", %{wkhtmltopdf #{src} #{out/"#{file}"}}
71
149
  else
72
- Glyph.error "Glyph cannot generate PDF. Please specify a valid tools.pdf_generator setting."
150
+ # TODO: support other PDF renderers
151
+ error "Glyph cannot generate PDF. Please specify a valid output.pdf.generator setting."
73
152
  end
74
153
  end
75
154