glyph 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/AUTHORS.textile +8 -7
- data/CHANGELOG.textile +89 -8
- data/LICENSE.textile +1 -2
- data/README.textile +89 -61
- data/Rakefile +12 -10
- data/VERSION +1 -1
- data/benchmark.rb +1 -1
- data/book/config.yml +18 -4
- data/book/document.glyph +269 -45
- data/book/images/glyph/commands_tasks.png +0 -0
- data/book/images/{document_generation.png → glyph/document_generation.png} +0 -0
- data/book/images/glyph/glyph.eps +123 -0
- data/book/images/glyph/glyph.png +0 -0
- data/book/images/glyph/glyph.svg +29 -0
- data/book/lib/commands/commands.rb +11 -0
- data/book/lib/layouts/bookindex.glyph +127 -0
- data/book/lib/layouts/bookpage.glyph +129 -0
- data/book/lib/layouts/project.glyph +26 -0
- data/book/lib/macros/reference.rb +27 -7
- data/book/lib/tasks/tasks.rake +52 -0
- data/book/snippets.yml +1 -1
- data/book/text/{acknowledgement.glyph → acknowledgements.glyph} +4 -2
- data/book/text/changelog.glyph +29 -3
- data/book/text/compiling/compiling.glyph +44 -20
- data/book/text/compiling/lite_mode.glyph +0 -4
- data/book/text/compiling/programmatic_usage.glyph +1 -5
- data/book/text/config/document.glyph +35 -0
- data/book/text/config/filters.glyph +28 -0
- data/book/text/config/options.glyph +25 -0
- data/book/text/config/output.glyph +83 -0
- data/book/text/extending/bookmarks_headers.glyph +0 -5
- data/book/text/extending/command.glyph +56 -0
- data/book/text/extending/commands_tasks.glyph +39 -0
- data/book/text/extending/further_reading.glyph +0 -3
- data/book/text/extending/internals.glyph +3 -5
- data/book/text/extending/interpreting.glyph +0 -4
- data/book/text/extending/layouts.glyph +68 -0
- data/book/text/extending/macro_def.glyph +0 -5
- data/book/text/extending/output_format.glyph +78 -0
- data/book/text/extending/params_attrs.glyph +0 -3
- data/book/text/extending/placeholders.glyph +0 -4
- data/book/text/extending/task.glyph +46 -0
- data/book/text/extending/validators.glyph +5 -6
- data/book/text/getting_started/configuration.glyph +1 -5
- data/book/text/getting_started/create_project.glyph +1 -5
- data/book/text/getting_started/structure.glyph +0 -4
- data/book/text/introduction.glyph +100 -75
- data/book/text/license.glyph +1 -2
- data/book/text/macros/macros_block.glyph +8 -4
- data/book/text/macros/macros_core.glyph +0 -3
- data/book/text/macros/macros_filters.glyph +2 -7
- data/book/text/macros/macros_inline.glyph +0 -4
- data/book/text/macros/macros_structure.glyph +0 -4
- data/book/text/ref_commands.glyph +29 -7
- data/book/text/stats/bookmarks.glyph +49 -0
- data/book/text/stats/links.glyph +90 -0
- data/book/text/stats/macros.glyph +73 -0
- data/book/text/stats/snippets.glyph +50 -0
- data/book/text/stats/stats.glyph +79 -0
- data/book/text/text_editing/attribute_intro.glyph +22 -0
- data/book/text/text_editing/code.glyph +0 -5
- data/book/text/text_editing/conditionals.glyph +0 -4
- data/book/text/text_editing/esc_quot.glyph +64 -0
- data/book/text/text_editing/evaluation.glyph +0 -3
- data/book/text/text_editing/glyph_files.glyph +0 -3
- data/book/text/text_editing/images.glyph +0 -5
- data/book/text/text_editing/inclusions.glyph +0 -4
- data/book/text/text_editing/links.glyph +2 -7
- data/book/text/text_editing/macro_intro.glyph +1 -98
- data/book/text/text_editing/raw_html.glyph +0 -87
- data/book/text/text_editing/section_aliases.glyph +28 -0
- data/book/text/text_editing/sections.glyph +1 -32
- data/book/text/text_editing/stylesheets.glyph +3 -5
- data/book/text/text_editing/topics.glyph +33 -0
- data/book/text/text_editing/xml_fallback.glyph +73 -0
- data/book/text/troubleshooting/errors_command.glyph +0 -3
- data/book/text/troubleshooting/errors_generic.glyph +21 -6
- data/book/text/troubleshooting/errors_macro.glyph +11 -8
- data/book/text/troubleshooting/errors_parser.glyph +0 -3
- data/config.yml +60 -25
- data/glyph.gemspec +90 -36
- data/layouts/web/index.glyph +16 -0
- data/layouts/web/topic.glyph +15 -0
- data/layouts/web5/index.glyph +16 -0
- data/layouts/web5/topic.glyph +17 -0
- data/lib/glyph.rb +36 -49
- data/lib/glyph/analyzer.rb +253 -0
- data/lib/glyph/bookmark.rb +92 -0
- data/lib/glyph/commands.rb +9 -221
- data/lib/glyph/commands/add.rb +8 -0
- data/lib/glyph/commands/compile.rb +93 -0
- data/lib/glyph/commands/config.rb +38 -0
- data/lib/glyph/commands/init.rb +6 -0
- data/lib/glyph/commands/outline.rb +45 -0
- data/lib/glyph/commands/stats.rb +48 -0
- data/lib/glyph/commands/todo.rb +29 -0
- data/lib/glyph/config.rb +2 -0
- data/lib/glyph/document.rb +61 -30
- data/lib/glyph/interpreter.rb +2 -2
- data/lib/glyph/macro.rb +14 -5
- data/lib/glyph/macro_helpers.rb +280 -0
- data/lib/glyph/macro_validators.rb +37 -2
- data/lib/glyph/reporter.rb +182 -0
- data/lib/glyph/syntax_node.rb +37 -10
- data/lib/glyph/system_extensions.rb +8 -45
- data/lib/glyph/utils.rb +148 -0
- data/macros/core.rb +10 -15
- data/macros/filters.rb +4 -5
- data/macros/html/block.rb +46 -30
- data/macros/html/inline.rb +9 -35
- data/macros/html/structure.rb +59 -72
- data/macros/html5/block.rb +69 -0
- data/macros/html5/inline.rb +24 -0
- data/macros/html5/structure.rb +139 -0
- data/macros/xml.rb +1 -1
- data/spec/files/custom_command.rb +6 -0
- data/spec/files/custom_tasks.rake +6 -0
- data/spec/files/document_for_stats.glyph +12 -0
- data/spec/files/references.glyph +4 -0
- data/spec/files/web1.glyph +11 -0
- data/spec/files/web2.glyph +10 -0
- data/spec/files/web_doc.glyph +23 -0
- data/spec/lib/analyzer_spec.rb +137 -0
- data/spec/lib/bookmark_spec.rb +64 -0
- data/spec/lib/commands_spec.rb +30 -5
- data/spec/lib/document_spec.rb +49 -9
- data/spec/lib/glyph_spec.rb +21 -1
- data/spec/lib/macro_spec.rb +6 -6
- data/spec/lib/macro_validators_spec.rb +24 -0
- data/spec/lib/reporter_spec.rb +132 -0
- data/spec/macros/core_spec.rb +2 -3
- data/spec/macros/filters_spec.rb +2 -2
- data/spec/macros/html5_spec.rb +101 -0
- data/spec/macros/macros_spec.rb +16 -6
- data/spec/macros/web5_spec.rb +32 -0
- data/spec/macros/web_spec.rb +59 -0
- data/spec/macros/xml_spec.rb +1 -1
- data/spec/spec_helper.rb +24 -4
- data/spec/tasks/generate_spec.rb +54 -0
- data/spec/tasks/load_spec.rb +29 -3
- data/spec/tasks/project_spec.rb +21 -3
- data/styles/default.css +40 -4
- data/styles/pagination.css +59 -41
- data/tasks/generate.rake +110 -31
- data/tasks/load.rake +39 -7
- data/tasks/project.rake +9 -7
- metadata +115 -34
- data/book/images/glyph.png +0 -0
- data/book/images/glyph.svg +0 -351
- data/book/output/html/glyph.html +0 -4482
- data/book/output/html/images/document_generation.png +0 -0
- data/book/output/html/images/glyph.png +0 -0
- data/book/output/html/images/glyph.svg +0 -351
- data/book/output/pdf/glyph.pdf +4 -10254
- data/book/script/authors +0 -1
- data/book/script/changelog +0 -1
- data/book/script/license +0 -1
- data/book/script/readme +0 -1
- data/book/text/ref_config.glyph +0 -100
- data/book/text/ref_macros.glyph +0 -6
- data/book/text/troubleshooting/errors_intro.glyph +0 -3
data/spec/tasks/project_spec.rb
CHANGED
@@ -11,11 +11,11 @@ describe "project:create" do
|
|
11
11
|
delete_project_dir
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
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 "
|
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 "
|
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
|
-
.
|
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 {
|
data/styles/pagination.css
CHANGED
@@ -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
|
-
|
91
|
+
/* TOC Margins */
|
92
|
+
|
93
|
+
.toc ol li[class]::before {
|
90
94
|
margin-left: 1em;
|
91
|
-
content: counter(toc1) "." counter(toc2) " ";
|
92
95
|
}
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
53
|
+
info "Processing..."
|
15
54
|
interpreter.process
|
16
|
-
|
55
|
+
info "Post-processing..."
|
17
56
|
interpreter.postprocess
|
18
57
|
Glyph.document = interpreter.document
|
19
58
|
end
|
20
59
|
|
21
|
-
desc "Create a standalone
|
22
|
-
task :html => :
|
23
|
-
|
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
|
29
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
141
|
+
error "An error occurred while generating #{file}"
|
69
142
|
end
|
70
|
-
|
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
|
-
|
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
|
|