glyph 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -16,18 +16,6 @@ describe "load" do
16
16
  delete_project
17
17
  lambda { Glyph.run! 'load:all' }.should raise_error
18
18
  end
19
-
20
- it "[snippets] should load snippet definitions" do
21
- lambda { Glyph.run! 'load:snippets'}.should_not raise_error
22
- Glyph::SNIPPETS[:test].blank?.should == false
23
- end
24
-
25
- it "[snippets] should not load snippets.xml in Lite mode" do
26
- Glyph.lite_mode = true
27
- lambda { Glyph.run! 'load:snippets'}.should_not raise_error
28
- Glyph::SNIPPETS[:test].blank?.should == true
29
- Glyph.lite_mode = false
30
- end
31
19
 
32
20
  it "[macros] should load macro definitions" do
33
21
  lambda { Glyph.run! 'load:macros'}.should_not raise_error
@@ -64,7 +52,7 @@ describe "load" do
64
52
  it "[layouts] should load layouts" do
65
53
  Glyph['document.output'] = 'web'
66
54
  Glyph.run! 'load:macros'
67
- Glyph::MACROS[:"layout:topic"].blank?.should == false
55
+ Glyph::MACROS[:"layout/topic"].blank?.should == false
68
56
  end
69
57
 
70
58
  it "[tasks] should load tasks" do
data/styles/coderay.css CHANGED
@@ -1,38 +1,147 @@
1
- .CodeRay pre {
2
- line-height: 1.2em;
3
- margin: 0px;
4
- color: #FFF; }
5
- .CodeRay .no {
6
- font-weight: bold;
7
- color: #595959; }
8
- .CodeRay .an {
9
- color: #E7BE69; }
10
- .CodeRay .c {
11
- color: #BC9358;
12
- font-style: italic; }
13
- .CodeRay .ch {
14
- color: #509E4F; }
15
- .CodeRay .cl, .CodeRay .co {
16
- color: #FFF; }
17
- .CodeRay .fl {
18
- color: #A4C260; }
19
- .CodeRay .fu {
20
- color: #FFC56D; }
21
- .CodeRay .gv {
22
- color: #D0CFFE; }
23
- .CodeRay .i {
24
- color: #A4C260; }
25
- .CodeRay .iv {
26
- color: #D0CFFE; }
27
- .CodeRay .pp {
28
- color: #E7BE69; }
29
- .CodeRay .r {
30
- color: #CB7832; }
31
- .CodeRay .rx, .CodeRay .s {
32
- color: #A4C260; }
33
- .CodeRay .sy {
34
- color: #6C9CBD; }
35
- .CodeRay .ta {
36
- color: #E7BE69; }
37
- .CodeRay .pc {
38
- color: #6C9CBD; }
1
+ /*
2
+ * Based on: https://github.com/pie4dan/CodeRay-GitHub-Theme/blob/master/coderay.css
3
+ */
4
+ .CodeRay {
5
+ background-color: #FFF;
6
+ border: 1px solid #CCC;
7
+ line-height: 1.3em;
8
+ font-size: 12px;
9
+ font-family: Monospace;
10
+ color: #000;
11
+ padding: 1em 0px 1em 1em;
12
+ }
13
+ .CodeRay pre, .CodeRay code {
14
+ padding: 0;
15
+ margin: 0;
16
+ }
17
+
18
+ div.CodeRay {
19
+ padding: 0;
20
+ }
21
+
22
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px }
23
+
24
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
25
+ table.CodeRay td {
26
+ padding: 1em 0.5em;
27
+ vertical-align: top;
28
+ }
29
+
30
+ .CodeRay .line_numbers, .CodeRay .no {
31
+ border: 1px solid #ECECEC;
32
+ margin: 0 inherit;
33
+ background-color: #ECECEC;
34
+ color: #AAA;
35
+ text-align: right;
36
+ }
37
+ .CodeRay .line_numbers tt { font-weight: bold }
38
+ .CodeRay .line_numbers .highlighted { color: red }
39
+ .CodeRay .line { display: block; float: left; width: 100%; }
40
+ .CodeRay .no { padding: 0px 4px }
41
+ .CodeRay .code { width: 100% }
42
+
43
+ ol.CodeRay { font-size: 10pt }
44
+ ol.CodeRay li { white-space: pre }
45
+
46
+ .CodeRay .code pre { overflow: auto }
47
+
48
+ .CodeRay .debug { color:white ! important; background:blue ! important; }
49
+
50
+ .CodeRay .af { color:#00C }
51
+ .CodeRay .an { color:#007 }
52
+ .CodeRay .at { color:#f08 }
53
+ .CodeRay .av { color:#700 }
54
+ .CodeRay .aw { color:#C00 }
55
+ .CodeRay .bi { color:#509; font-weight:bold }
56
+ .CodeRay .c { color:#998; font-style: italic;}
57
+
58
+ .CodeRay .ch { color:#04D }
59
+ .CodeRay .ch .k { color:#04D }
60
+ .CodeRay .ch .dl { color:#039 }
61
+
62
+ .CodeRay .cl { color:#458; font-weight:bold }
63
+ .CodeRay .cm { color:#A08; font-weight:bold }
64
+ .CodeRay .co { color:teal; }
65
+ .CodeRay .cr { color:#0A0 }
66
+ .CodeRay .cv { color:#369 }
67
+ .CodeRay .de { color:#B0B; }
68
+ .CodeRay .df { color:#099; font-weight:bold }
69
+ .CodeRay .di { color:#088; font-weight:bold }
70
+ .CodeRay .dl { color:black }
71
+ .CodeRay .do { color:#970 }
72
+ .CodeRay .dt { color:#34b }
73
+ .CodeRay .ds { color:#D42; font-weight:bold }
74
+ .CodeRay .e { color:#666; font-weight:bold }
75
+ .CodeRay .en { color:#800; font-weight:bold }
76
+ .CodeRay .er { color:#F00; background-color:#FAA }
77
+ .CodeRay .ex { color:#C00; font-weight:bold }
78
+ .CodeRay .fl { color:#099; }
79
+ .CodeRay .fu { color:#900; font-weight:bold }
80
+ .CodeRay .gv { color:teal; font-weight:bold }
81
+ .CodeRay .hx { color:#058; font-weight:bold }
82
+ .CodeRay .i { color:#099; }
83
+ .CodeRay .ic { color:#B44; font-weight:bold }
84
+
85
+ .CodeRay .il { color: black }
86
+ .CodeRay .il .il { background: #ccc }
87
+ .CodeRay .il .il .il { background: #bbb }
88
+ .CodeRay .il .idl { color: #D14; }
89
+ .CodeRay .idl { color: #D14; }
90
+
91
+ .CodeRay .im { color:#f00; }
92
+ .CodeRay .in { color:#B2B; font-weight:bold }
93
+ .CodeRay .iv { color:teal }
94
+ .CodeRay .la { color:#970; font-weight:bold }
95
+ .CodeRay .lv { color:#963 }
96
+ .CodeRay .oc { color:#40E; font-weight:bold }
97
+ .CodeRay .of { color:#000; font-weight:bold }
98
+ .CodeRay .op { }
99
+ .CodeRay .pc { font-weight:bold }
100
+ .CodeRay .pd { color:#369; font-weight:bold }
101
+ .CodeRay .pp { color:#579; }
102
+ .CodeRay .ps { color:#00C; font-weight:bold }
103
+ .CodeRay .pt { color:#074; font-weight:bold }
104
+ .CodeRay .r, .kw { color:#000; font-weight:bold }
105
+
106
+ .CodeRay .ke { color: #808; }
107
+ .CodeRay .ke .dl { color: #606; }
108
+ .CodeRay .ke .ch { color: #80f; }
109
+ .CodeRay .vl { color: #088; }
110
+
111
+ .CodeRay .rx { background-color:#fff0ff }
112
+ .CodeRay .rx .k { color:#808 }
113
+ .CodeRay .rx .dl { color:#404 }
114
+ .CodeRay .rx .mod { color:#C2C }
115
+ .CodeRay .rx .fu { color:#404; font-weight: bold }
116
+
117
+ .CodeRay .s { color: #D20; }
118
+ .CodeRay .s .s { }
119
+ .CodeRay .s .s .s { background-color:#ffd0d0 }
120
+ .CodeRay .s .k { color: #D14; }
121
+ .CodeRay .s .ch { color: #D14; }
122
+ .CodeRay .s .dl { color: #D14; }
123
+
124
+ .CodeRay .sh { color:#D14 }
125
+ .CodeRay .sh .k { }
126
+ .CodeRay .sh .dl { color:#D14 }
127
+
128
+ .CodeRay .sy { color:#990073 }
129
+ .CodeRay .sy .k { color:#A60 }
130
+ .CodeRay .sy .dl { color:#630 }
131
+
132
+ .CodeRay .ta { color:#070 }
133
+ .CodeRay .tf { color:#070; font-weight:bold }
134
+ .CodeRay .ts { color:#D70; font-weight:bold }
135
+ .CodeRay .ty { color:#339; font-weight:bold }
136
+ .CodeRay .v { color:#036 }
137
+ .CodeRay .xt { color:#444 }
138
+
139
+ .CodeRay .ins { background: #afa; }
140
+ .CodeRay .del { background: #faa; }
141
+ .CodeRay .chg { color: #aaf; background: #007; }
142
+ .CodeRay .head { color: #f8f; background: #505 }
143
+
144
+ .CodeRay .ins .ins { color: #080; font-weight:bold }
145
+ .CodeRay .del .del { color: #800; font-weight:bold }
146
+ .CodeRay .chg .chg { color: #66f; }
147
+ .CodeRay .head .head { color: #f4f; }
data/styles/default.css CHANGED
@@ -38,20 +38,21 @@ body {
38
38
  text-align: center; }
39
39
  .titlepage h1 {
40
40
  font-size: 2.5em;
41
+ line-height: 1.2em;
41
42
  font-weight: bold;
42
- line-height: 1.5em;
43
43
  margin-bottom: 0.2em; }
44
44
 
45
45
  .halftitlepage h1 {
46
46
  font-size: 2.5em;
47
47
  font-weight: bold;
48
- line-height: 1.5em;
49
48
  margin-bottom: 0.2em; }
50
49
  .halftitlepage h2 {
51
50
  font-size: 1.1em;
52
51
  font-style: italic;
53
52
  font-weight: bold;
54
- line-height: 1.2em;
53
+ padding-top: 0;
54
+ margin-top: 0;
55
+ line-height: 2.5em;
55
56
  margin-bottom: 0.5em;
56
57
  prince-bookmark-level: none; }
57
58
 
@@ -59,7 +60,9 @@ body {
59
60
  font-size: 1.1em;
60
61
  font-style: italic;
61
62
  font-weight: bold;
62
- line-height: 1.2em;
63
+ padding-top: 0;
64
+ margin-top: 0;
65
+ line-height: 2.5em;
63
66
  margin-bottom: 0.5em;
64
67
  prince-bookmark-level: none; }
65
68
 
@@ -126,11 +129,16 @@ sup {
126
129
  margin: auto;
127
130
  text-align: center; }
128
131
 
132
+ code {
133
+ font-size: 0.8em;
134
+ }
135
+
129
136
  .note, .important, .tip, .caution, .box {
130
- border: 1px solid #e6e6e6;
137
+ border: 1px solid #CCC;
131
138
  display: block;
132
139
  margin: 0.5em auto;
133
- padding: 0 0.5em;
140
+ padding: 1em;
141
+ padding-top: 0em;
134
142
  width: 600px;
135
143
  background: #EEE;
136
144
  color: #1F1F1F; }
@@ -146,7 +154,10 @@ sup {
146
154
  .box-title {
147
155
  display: block;
148
156
  text-align: center;
149
- font-weight: bold; }
157
+ font-weight: bold;
158
+ font-size: 120%;
159
+ margin: 0.5em;
160
+ }
150
161
 
151
162
  .comment {
152
163
  display: block;
@@ -201,20 +212,6 @@ a {
201
212
  a:hover {
202
213
  color: #005b91; }
203
214
 
204
- .code > pre {
205
- -webkit-border-radius: 5px;
206
- -moz-border-radius: 5px;
207
- border-radius: 5px;
208
- background-color: #222;
209
- font-family: 'Courier New', 'Terminal', monospace;
210
- color: #E6E0DB;
211
- padding: 20px;
212
- overflow: auto hidden;
213
- margin: 20px 0 20px 0; }
214
-
215
- code, .CodeRay {
216
- font-size: 0.8em; }
217
-
218
215
  span.line-numbers {
219
216
  margin: 0;
220
217
  padding: 3px; }
@@ -251,7 +248,7 @@ td p, td ul, td ol {
251
248
 
252
249
  /* FONTS */
253
250
  body {
254
- font-family: "Gentium Book Basic", "Book Antiqua", "Times New Roman", "Serif"; }
251
+ font-family: 'Crimson Text', 'Palatino', 'Bookman', 'Georgia', 'Times'; }
255
252
 
256
253
  code, pre {
257
254
  font-family: "Droid Sans Mono", "Consolas", "Monaco", "Courier", "Monospace"; }
@@ -93,6 +93,36 @@ ol.toc {
93
93
  .toc ol ol ol ol li[class~=appendix]::before {
94
94
  content: counter(appendix1, upper-latin) "." counter(toc2) "." counter(toc3) "." counter(toc4) "." counter(toc5) " "; }
95
95
 
96
+ h2, section h1 {
97
+ padding-top: 2em;
98
+ string-set: chapter-title content();
99
+ page-break-before: always; }
100
+
101
+ .halftitlepage h2, .titlepage h2 {
102
+ page-break-before: avoid; }
103
+
104
+ .bodymatter .chapter h2, .bodymatter .chapter h1 {
105
+ counter-increment: h2;
106
+ counter-reset: h3; }
107
+
108
+ .backmatter h2, .backmatter h1 {
109
+ counter-increment: a2;
110
+ counter-reset: h3; }
111
+
112
+ .bodymatter h3, .backmatter h3, .bodymatter section h1, .backmatter section h1 {
113
+ counter-increment: h3;
114
+ counter-reset: h4; }
115
+
116
+ .bodymatter h4, .backmatter h4, .bodymatter section section h1, .backmatter section section h1 {
117
+ counter-increment: h4;
118
+ counter-reset: h5; }
119
+
120
+ .bodymatter h5, .backmatter h5, .bodymatter section section section h1, .backmatter section section section h1 {
121
+ counter-increment: h5; }
122
+
123
+ h1, h2, h3, h4, h5 {
124
+ page-break-after: avoid; }
125
+
96
126
  div.frontmatter {
97
127
  page: frontmatter; }
98
128
  div.backmatter {
@@ -129,36 +159,6 @@ div.backmatter {
129
159
  .backmatter h5::before, .bodymatter section section section section h2:before {
130
160
  content: counter(a2, upper-latin) "." counter(h3) "." counter(h4) "." counter(h5) " "; }
131
161
 
132
- h2, section h1 {
133
- padding-top: 2em;
134
- string-set: chapter-title content();
135
- page-break-before: always; }
136
-
137
- .halftitlepage h2, .titlepage h2 {
138
- page-break-before: avoid; }
139
-
140
- .bodymatter h2, .bodymatter h1 {
141
- counter-increment: h2;
142
- counter-reset: h3; }
143
-
144
- .backmatter h2, .backmatter h1 {
145
- counter-increment: a2;
146
- counter-reset: h3; }
147
-
148
- .bodymatter h3, .backmatter h3, .bodymatter section h1, .backmatter section h1 {
149
- counter-increment: h3;
150
- counter-reset: h4; }
151
-
152
- .bodymatter h4, .backmatter h4, .bodymatter section section h1, .backmatter section section h1 {
153
- counter-increment: h4;
154
- counter-reset: h5; }
155
-
156
- .bodymatter h5, .backmatter h5, .bodymatter section section section h1, .backmatter section section section h1 {
157
- counter-increment: h5; }
158
-
159
- h1, h2, h3, h4, h5 {
160
- page-break-after: avoid; }
161
-
162
162
  .box, .note, .important, .tip, .caution, .code {
163
163
  page-break-inside: avoid; }
164
164
 
data/tasks/generate.rake CHANGED
@@ -18,7 +18,7 @@ namespace :generate do
18
18
  task :styles => [:document] do
19
19
  if Glyph['document.styles'].in?(['link', 'import']) && !Glyph.lite? then
20
20
  info "Copying stylesheets..."
21
- output = (Glyph['document.output'] == 'pdf') ? 'html' : Glyph['document.output']
21
+ output = complex_output? ? 'tmp' : Glyph['document.output']
22
22
  out_dir = Glyph::PROJECT/"output/#{output}/styles"
23
23
  Glyph.document.styles.each do |f|
24
24
  styles_dir = f.parent.to_s.include?(Glyph::HOME/'styles') ? Glyph::HOME/'styles' : Glyph::PROJECT/'styles'
@@ -27,7 +27,7 @@ namespace :generate do
27
27
  dir.mkpath
28
28
  case
29
29
  when f.extname == ".css" then
30
- file_copy f, dir/f.basename
30
+ file_copy f, dir/f.basename
31
31
  when f.extname == ".sass" then
32
32
  style = Sass::Engine.new(file_load(f.to_s)).render
33
33
  out_file = dir/f.basename.to_s.gsub(/\.sass$/, '.css')
@@ -62,11 +62,11 @@ namespace :generate do
62
62
  info "Generating HTML file..."
63
63
  if Glyph.lite? then
64
64
  out = Pathname.new Glyph['document.output_dir']
65
- file = (Glyph['document.output'] == 'pdf') ? Glyph['document.filename']+".html" : Glyph['document.output_file']
65
+ file = complex_output? ? Glyph['document.filename']+".html" : Glyph['document.output_file']
66
66
  else
67
- out = (Glyph['document.output'] == 'pdf') ? 'html' : Glyph['document.output']
67
+ out = complex_output? ? 'tmp' : Glyph['document.output']
68
68
  out = Glyph::PROJECT/"output/#{out}"
69
- extension = (Glyph['document.output'] == 'pdf') ? Glyph["output.html.extension"] : Glyph["output.#{Glyph['document.output']}.extension"]
69
+ extension = complex_output? ? Glyph["output.html.extension"] : Glyph["output.#{Glyph['document.output']}.extension"]
70
70
  file = "#{Glyph['document.filename']}#{extension}"
71
71
  end
72
72
  out.mkpath
@@ -77,6 +77,41 @@ namespace :generate do
77
77
  desc "Create a standalone HTML 5 file"
78
78
  task :html5 => [:html] do; end
79
79
 
80
+ task :calibre => [:html] do
81
+ out = Glyph['document.output']
82
+ output_cfg = "output.#{out}"
83
+ # TODO: support other e-book renderers
84
+ unless Glyph["#{output_cfg}.generator"] == "calibre" then
85
+ error "Glyph cannot generate e-book. At present, output.#{out}.generator can only be set to 'calibre'"
86
+ end
87
+ Glyph.info "Generating #{Glyph['document.output'].upcase} e-book..."
88
+ options = Glyph[output_cfg][:calibre].dup
89
+ options[:isbn] = Glyph['document.isbn'] unless Glyph["document.isbn"].blank?
90
+ options[:cover] = "#{Glyph::PROJECT}/images/#{Glyph['document.cover']}" unless Glyph["document.cover"].blank?
91
+ options[:title] = Glyph["document.title"]
92
+ options[:authors] = Glyph["document.author"]
93
+ html_file = "#{Glyph::PROJECT}/output/tmp/#{Glyph['document.filename']}.html"
94
+ out_dir = "#{Glyph::PROJECT}/output/#{out}"
95
+ out_file = "#{Glyph['document.filename']}.#{out}"
96
+ out_path = Pathname.new "#{out_dir}/#{out_file}"
97
+ Pathname.new(out_dir).mkpath
98
+ calibre_cmd = "ebook-convert #{html_file} #{out_path} #{options.to_options}"
99
+ run_external_command calibre_cmd
100
+ # Remove stylesheets and images (copied by default to output directory)
101
+ (Pathname.new(out_dir)/"images").rmtree rescue nil
102
+ (Pathname.new(out_dir)/"styles").rmtree rescue nil
103
+ if out_path.exist? then
104
+ info "'#{out_file}' generated successfully."
105
+ else
106
+ error "An error occurred while generating #{out_file}"
107
+ end
108
+ end
109
+
110
+ [:mobi, :epub].each do |out|
111
+ desc "Create an e-book file in #{out} format"
112
+ task out => [:calibre] do; end
113
+ end
114
+
80
115
  desc "Create multiple HTML files"
81
116
  task :web => [:images, :styles] do
82
117
  info "Generating HTML files..."
@@ -90,13 +125,13 @@ namespace :generate do
90
125
  out.mkpath
91
126
  index_layout = Glyph["output.#{Glyph['document.output']}.layouts.index"] || :index
92
127
  # Generate index topic
93
- context = {}
128
+ context = {}
94
129
  context[:document] = Glyph::Document.new(Glyph::DocumentNode.new).inherit_from(Glyph.document, :topics => false)
95
- context[:source] = {:name => "layout:#{index_layout}", :file => "layouts/#{index_layout}.glyph"}
130
+ context[:source] = {:name => "layout/#{index_layout}", :file => "layouts/#{index_layout}.glyph"}
96
131
  # Do not display errors (already displayed when document is finalized).
97
132
  q = Glyph['system.quiet']
98
133
  Glyph['system.quiet'] = true
99
- index_topic = Glyph::Interpreter.new("layout:#{index_layout}[]", context).document.output
134
+ index_topic = Glyph::Interpreter.new("layout/#{index_layout}[]", context).document.output
100
135
  Glyph['system.quiet'] = q
101
136
  file_write out/"index.html", index_topic
102
137
  # Generate all topics
@@ -114,8 +149,8 @@ namespace :generate do
114
149
  desc "Create multiple HTML 5 files"
115
150
  task :web5 => [:web] do; end
116
151
 
117
- desc "Create a pdf file"
118
- task :pdf => :html do
152
+ desc "Create a pdf file (do not call directly)"
153
+ task :pdf do
119
154
  info "Generating PDF file..."
120
155
  if Glyph.lite? then
121
156
  out = Pathname.new Glyph['document.output_dir']
@@ -123,18 +158,13 @@ namespace :generate do
123
158
  file = Glyph['document.output_file']
124
159
  else
125
160
  out = Glyph::PROJECT/"output/pdf"
126
- src = Glyph::PROJECT/"output/html/#{Glyph['document.filename']}.html"
161
+ src = Glyph::PROJECT/"output/tmp/#{Glyph['document.filename']}.html"
127
162
  file = "#{Glyph['document.filename']}.pdf"
128
163
  end
129
164
  out.mkpath
130
165
  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
166
+ ENV['PATH'] += path if RUBY_PLATFORM.match /mswin/
167
+ run_external_command cmd
138
168
  if (out/file).exist? then
139
169
  info "'#{file}' generated successfully."
140
170
  else
@@ -152,4 +182,10 @@ namespace :generate do
152
182
  end
153
183
  end
154
184
 
185
+ desc "Create a pdf file through html"
186
+ task :pdf_through_html => [:html, :pdf] do; end
187
+
188
+ desc "Create a pdf file through html5"
189
+ task :pdf_through_html5 => [:html5, :pdf] do; end
190
+
155
191
  end