glyph 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/AUTHORS.textile +1 -1
  2. data/CHANGELOG.textile +119 -222
  3. data/LICENSE.textile +1 -1
  4. data/README.textile +42 -23
  5. data/Rakefile +1 -3
  6. data/VERSION +1 -1
  7. data/benchmark.rb +72 -0
  8. data/book/config.yml +4 -4
  9. data/book/document.glyph +90 -57
  10. data/book/images/document_generation.png +0 -0
  11. data/book/lib/macros/reference.rb +75 -22
  12. data/book/output/html/glyph.html +3183 -2121
  13. data/book/output/html/images/document_generation.png +0 -0
  14. data/book/output/pdf/glyph.pdf +7370 -4913
  15. data/book/resources/document_generation.txt +34 -0
  16. data/book/snippets.yml +6 -0
  17. data/book/text/changelog.glyph +45 -34
  18. data/book/text/compiling/compiling.glyph +23 -0
  19. data/book/text/compiling/lite_mode.glyph +23 -0
  20. data/book/text/compiling/programmatic_usage.glyph +77 -0
  21. data/book/text/extending/bookmarks_headers.glyph +21 -0
  22. data/book/text/extending/further_reading.glyph +13 -0
  23. data/book/text/extending/internals.glyph +79 -0
  24. data/book/text/extending/interpreting.glyph +51 -0
  25. data/book/text/extending/macro_def.glyph +64 -0
  26. data/book/text/extending/params_attrs.glyph +70 -0
  27. data/book/text/extending/placeholders.glyph +34 -0
  28. data/book/text/extending/validators.glyph +16 -0
  29. data/book/text/getting_started/configuration.glyph +49 -0
  30. data/book/text/getting_started/create_project.glyph +41 -0
  31. data/book/text/getting_started/structure.glyph +55 -0
  32. data/book/text/introduction.glyph +49 -26
  33. data/book/text/license.glyph +1 -1
  34. data/book/text/macros/macros_block.glyph +99 -0
  35. data/book/text/macros/macros_core.glyph +208 -0
  36. data/book/text/macros/macros_filters.glyph +40 -0
  37. data/book/text/macros/macros_inline.glyph +50 -0
  38. data/book/text/macros/macros_structure.glyph +100 -0
  39. data/book/text/ref_commands.glyph +94 -73
  40. data/book/text/ref_config.glyph +34 -42
  41. data/book/text/ref_macros.glyph +1 -373
  42. data/book/text/text_editing/code.glyph +51 -0
  43. data/book/text/text_editing/conditionals.glyph +49 -0
  44. data/book/text/text_editing/evaluation.glyph +13 -0
  45. data/book/text/text_editing/glyph_files.glyph +7 -0
  46. data/book/text/text_editing/images.glyph +29 -0
  47. data/book/text/text_editing/inclusions.glyph +44 -0
  48. data/book/text/text_editing/links.glyph +53 -0
  49. data/book/text/text_editing/macro_intro.glyph +111 -0
  50. data/book/text/text_editing/raw_html.glyph +112 -0
  51. data/book/text/text_editing/sections.glyph +63 -0
  52. data/book/text/text_editing/stylesheets.glyph +36 -0
  53. data/book/text/troubleshooting/errors_command.glyph +39 -0
  54. data/book/text/troubleshooting/errors_generic.glyph +29 -0
  55. data/book/text/troubleshooting/errors_intro.glyph +3 -0
  56. data/book/text/troubleshooting/errors_macro.glyph +98 -0
  57. data/book/text/troubleshooting/errors_parser.glyph +29 -0
  58. data/config.yml +77 -58
  59. data/document.glyph +25 -25
  60. data/glyph.gemspec +57 -22
  61. data/lib/glyph.rb +54 -13
  62. data/lib/glyph/commands.rb +84 -17
  63. data/lib/glyph/config.rb +3 -3
  64. data/lib/glyph/document.rb +14 -8
  65. data/lib/glyph/interpreter.rb +18 -58
  66. data/lib/glyph/macro.rb +160 -55
  67. data/lib/glyph/macro_validators.rb +104 -12
  68. data/lib/glyph/node.rb +24 -0
  69. data/lib/glyph/parser.rb +278 -0
  70. data/lib/glyph/syntax_node.rb +225 -0
  71. data/macros/core.rb +212 -0
  72. data/macros/filters.rb +66 -15
  73. data/macros/html/block.rb +43 -105
  74. data/macros/html/inline.rb +11 -12
  75. data/macros/html/structure.rb +123 -58
  76. data/macros/xml.rb +33 -0
  77. data/spec/files/container.textile +2 -2
  78. data/spec/files/document.glyph +2 -2
  79. data/spec/files/document_with_toc.glyph +3 -3
  80. data/spec/files/included.textile +1 -1
  81. data/spec/files/ligature.jpg +0 -0
  82. data/spec/files/markdown.markdown +2 -1
  83. data/spec/lib/commands_spec.rb +46 -3
  84. data/spec/lib/document_spec.rb +4 -4
  85. data/spec/lib/glyph_spec.rb +17 -46
  86. data/spec/lib/interpreter_spec.rb +6 -25
  87. data/spec/lib/macro_spec.rb +141 -43
  88. data/spec/lib/macro_validators_spec.rb +27 -5
  89. data/spec/lib/node_spec.rb +26 -1
  90. data/spec/lib/parser_spec.rb +246 -0
  91. data/spec/lib/syntax_node_spec.rb +111 -0
  92. data/spec/macros/core_spec.rb +195 -0
  93. data/spec/macros/filters_spec.rb +38 -4
  94. data/spec/macros/macros_spec.rb +20 -176
  95. data/spec/macros/textile_spec.rb +13 -71
  96. data/spec/macros/xml_spec.rb +77 -0
  97. data/spec/spec_helper.rb +50 -10
  98. data/spec/tasks/load_spec.rb +13 -2
  99. data/styles/default.css +18 -6
  100. data/styles/pagination.css +1 -19
  101. data/tasks/generate.rake +2 -2
  102. data/tasks/load.rake +27 -17
  103. data/tasks/project.rake +1 -1
  104. metadata +75 -62
  105. data/book/script/compile.rb +0 -8
  106. data/book/script/prof +0 -1
  107. data/book/script/prof_results.htm +0 -21079
  108. data/book/text/authoring.glyph +0 -548
  109. data/book/text/extending.glyph +0 -224
  110. data/book/text/getting_started.glyph +0 -158
  111. data/book/text/troubleshooting.glyph +0 -179
  112. data/lib/glyph/glyph_language.rb +0 -538
  113. data/lib/glyph/glyph_language.treetop +0 -27
  114. data/macros/common.rb +0 -160
data/document.glyph CHANGED
@@ -1,29 +1,29 @@
1
- document[
2
- head[style[default.css]]
3
- body[
4
- titlepage[
5
- title[]
6
- author[]
7
- pubdate[]
8
- ]
9
- frontmatter[
10
- toc[]
11
- preface[header[Preface]
12
- @[preface.textile]
13
- ]
1
+ book[
2
+ @frontmatter[
3
+ toc[]
4
+ preface[
5
+ @title[Preface]
6
+ todo[Write the preface]
7
+ include[preface]
8
+ ]
9
+ ]
10
+ @bodymatter[
11
+ chapter[
12
+ @title[Chapter 1]
13
+ todo[Write chapter 1]
14
+ include[chapter_1]
14
15
  ]
15
- bodymatter[
16
- chapter[header[Chapter #1]
17
- @[chapter_1.textile]
18
- ]
19
- chapter[header[Chapter #2]
20
- @[chapter_2.textile]
21
- ]
16
+ chapter[
17
+ @title[Chapter 2]
18
+ todo[Write chapter 2]
19
+ include[chapter_2]
22
20
  ]
23
- backmatter[
24
- appendix[header[Appendix A]
25
- @[appendix_a.textile]
26
- ]
27
- ]
28
21
  ]
22
+ @backmatter[
23
+ appendix[
24
+ @title[Appendix A]
25
+ todo[Write appendix A]
26
+ include[appendix_a]
27
+ ]
28
+ ]
29
29
  ]
data/glyph.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{glyph}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Fabio Cevasco"]
12
- s.date = %q{2010-05-09}
12
+ s.date = %q{2010-06-13}
13
13
  s.default_executable = %q{glyph}
14
14
  s.description = %q{Glyph is a framework for structured document authoring.}
15
15
  s.email = %q{h3rald@h3rald.com}
@@ -25,35 +25,67 @@ Gem::Specification.new do |s|
25
25
  "README.textile",
26
26
  "Rakefile",
27
27
  "VERSION",
28
+ "benchmark.rb",
28
29
  "bin/glyph",
29
30
  "book/config.yml",
30
31
  "book/document.glyph",
32
+ "book/images/document_generation.png",
31
33
  "book/images/glyph.png",
32
34
  "book/images/glyph.svg",
33
35
  "book/lib/macros/reference.rb",
34
36
  "book/output/html/glyph.html",
37
+ "book/output/html/images/document_generation.png",
35
38
  "book/output/html/images/glyph.png",
36
39
  "book/output/html/images/glyph.svg",
37
40
  "book/output/pdf/glyph.pdf",
41
+ "book/resources/document_generation.txt",
38
42
  "book/script/authors",
39
43
  "book/script/changelog",
40
- "book/script/compile.rb",
41
44
  "book/script/license",
42
- "book/script/prof",
43
- "book/script/prof_results.htm",
44
45
  "book/script/readme",
45
46
  "book/snippets.yml",
46
47
  "book/text/acknowledgement.glyph",
47
- "book/text/authoring.glyph",
48
48
  "book/text/changelog.glyph",
49
- "book/text/extending.glyph",
50
- "book/text/getting_started.glyph",
49
+ "book/text/compiling/compiling.glyph",
50
+ "book/text/compiling/lite_mode.glyph",
51
+ "book/text/compiling/programmatic_usage.glyph",
52
+ "book/text/extending/bookmarks_headers.glyph",
53
+ "book/text/extending/further_reading.glyph",
54
+ "book/text/extending/internals.glyph",
55
+ "book/text/extending/interpreting.glyph",
56
+ "book/text/extending/macro_def.glyph",
57
+ "book/text/extending/params_attrs.glyph",
58
+ "book/text/extending/placeholders.glyph",
59
+ "book/text/extending/validators.glyph",
60
+ "book/text/getting_started/configuration.glyph",
61
+ "book/text/getting_started/create_project.glyph",
62
+ "book/text/getting_started/structure.glyph",
51
63
  "book/text/introduction.glyph",
52
64
  "book/text/license.glyph",
65
+ "book/text/macros/macros_block.glyph",
66
+ "book/text/macros/macros_core.glyph",
67
+ "book/text/macros/macros_filters.glyph",
68
+ "book/text/macros/macros_inline.glyph",
69
+ "book/text/macros/macros_structure.glyph",
53
70
  "book/text/ref_commands.glyph",
54
71
  "book/text/ref_config.glyph",
55
72
  "book/text/ref_macros.glyph",
56
- "book/text/troubleshooting.glyph",
73
+ "book/text/text_editing/code.glyph",
74
+ "book/text/text_editing/conditionals.glyph",
75
+ "book/text/text_editing/evaluation.glyph",
76
+ "book/text/text_editing/glyph_files.glyph",
77
+ "book/text/text_editing/images.glyph",
78
+ "book/text/text_editing/inclusions.glyph",
79
+ "book/text/text_editing/links.glyph",
80
+ "book/text/text_editing/macro_intro.glyph",
81
+ "book/text/text_editing/raw_html.glyph",
82
+ "book/text/text_editing/sections.glyph",
83
+ "book/text/text_editing/stylesheets.glyph",
84
+ "book/text/troubleshooting/errors_command.glyph",
85
+ "book/text/troubleshooting/errors_generic.glyph",
86
+ "book/text/troubleshooting/errors_intro.glyph",
87
+ "book/text/troubleshooting/errors_macro.glyph",
88
+ "book/text/troubleshooting/errors_parser.glyph",
57
89
  "config.yml",
58
90
  "document.glyph",
59
91
  "glyph.gemspec",
@@ -61,18 +93,19 @@ Gem::Specification.new do |s|
61
93
  "lib/glyph/commands.rb",
62
94
  "lib/glyph/config.rb",
63
95
  "lib/glyph/document.rb",
64
- "lib/glyph/glyph_language.rb",
65
- "lib/glyph/glyph_language.treetop",
66
96
  "lib/glyph/interpreter.rb",
67
97
  "lib/glyph/macro.rb",
68
98
  "lib/glyph/macro_validators.rb",
69
99
  "lib/glyph/node.rb",
100
+ "lib/glyph/parser.rb",
101
+ "lib/glyph/syntax_node.rb",
70
102
  "lib/glyph/system_extensions.rb",
71
- "macros/common.rb",
103
+ "macros/core.rb",
72
104
  "macros/filters.rb",
73
105
  "macros/html/block.rb",
74
106
  "macros/html/inline.rb",
75
107
  "macros/html/structure.rb",
108
+ "macros/xml.rb",
76
109
  "spec/files/article.glyph",
77
110
  "spec/files/container.textile",
78
111
  "spec/files/document.glyph",
@@ -89,9 +122,13 @@ Gem::Specification.new do |s|
89
122
  "spec/lib/macro_spec.rb",
90
123
  "spec/lib/macro_validators_spec.rb",
91
124
  "spec/lib/node_spec.rb",
125
+ "spec/lib/parser_spec.rb",
126
+ "spec/lib/syntax_node_spec.rb",
127
+ "spec/macros/core_spec.rb",
92
128
  "spec/macros/filters_spec.rb",
93
129
  "spec/macros/macros_spec.rb",
94
130
  "spec/macros/textile_spec.rb",
131
+ "spec/macros/xml_spec.rb",
95
132
  "spec/spec_helper.rb",
96
133
  "spec/tasks/generate_spec.rb",
97
134
  "spec/tasks/load_spec.rb",
@@ -130,8 +167,10 @@ Gem::Specification.new do |s|
130
167
  s.rubygems_version = %q{1.3.6}
131
168
  s.summary = %q{Glyph -- A Ruby-powered Document Authoring Framework}
132
169
  s.test_files = [
133
- "spec/macros/filters_spec.rb",
170
+ "spec/macros/core_spec.rb",
171
+ "spec/macros/filters_spec.rb",
134
172
  "spec/macros/textile_spec.rb",
173
+ "spec/macros/xml_spec.rb",
135
174
  "spec/macros/macros_spec.rb",
136
175
  "spec/lib/interpreter_spec.rb",
137
176
  "spec/lib/commands_spec.rb",
@@ -140,6 +179,8 @@ Gem::Specification.new do |s|
140
179
  "spec/lib/macro_validators_spec.rb",
141
180
  "spec/lib/config_spec.rb",
142
181
  "spec/lib/glyph_spec.rb",
182
+ "spec/lib/parser_spec.rb",
183
+ "spec/lib/syntax_node_spec.rb",
143
184
  "spec/lib/document_spec.rb",
144
185
  "spec/tasks/load_spec.rb",
145
186
  "spec/tasks/generate_spec.rb",
@@ -154,46 +195,40 @@ Gem::Specification.new do |s|
154
195
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
155
196
  s.add_runtime_dependency(%q<gli>, [">= 0.3.1"])
156
197
  s.add_runtime_dependency(%q<extlib>, [">= 0.9.12"])
157
- s.add_runtime_dependency(%q<treetop>, [">= 0.4.3"])
158
198
  s.add_runtime_dependency(%q<rake>, [">= 0.8.7"])
159
199
  s.add_development_dependency(%q<rspec>, [">= 1.1.11"])
160
200
  s.add_development_dependency(%q<yard>, [">= 1.5.4"])
161
201
  s.add_development_dependency(%q<jeweler>, ["= 1.4.0"])
162
202
  s.add_development_dependency(%q<directory_watcher>, [">= 1.3.2"])
163
- s.add_development_dependency(%q<haml>, [">= 2.2.3"])
203
+ s.add_development_dependency(%q<haml>, [">= 3.0.6"])
164
204
  s.add_development_dependency(%q<RedCloth>, [">= 4.2.3"])
165
205
  s.add_development_dependency(%q<bluecloth>, [">= 2.0.7"])
166
206
  s.add_development_dependency(%q<coderay>, [">= 0.9.3"])
167
- s.add_development_dependency(%q<ruby-prof>, [">= 0.8.1"])
168
207
  else
169
208
  s.add_dependency(%q<gli>, [">= 0.3.1"])
170
209
  s.add_dependency(%q<extlib>, [">= 0.9.12"])
171
- s.add_dependency(%q<treetop>, [">= 0.4.3"])
172
210
  s.add_dependency(%q<rake>, [">= 0.8.7"])
173
211
  s.add_dependency(%q<rspec>, [">= 1.1.11"])
174
212
  s.add_dependency(%q<yard>, [">= 1.5.4"])
175
213
  s.add_dependency(%q<jeweler>, ["= 1.4.0"])
176
214
  s.add_dependency(%q<directory_watcher>, [">= 1.3.2"])
177
- s.add_dependency(%q<haml>, [">= 2.2.3"])
215
+ s.add_dependency(%q<haml>, [">= 3.0.6"])
178
216
  s.add_dependency(%q<RedCloth>, [">= 4.2.3"])
179
217
  s.add_dependency(%q<bluecloth>, [">= 2.0.7"])
180
218
  s.add_dependency(%q<coderay>, [">= 0.9.3"])
181
- s.add_dependency(%q<ruby-prof>, [">= 0.8.1"])
182
219
  end
183
220
  else
184
221
  s.add_dependency(%q<gli>, [">= 0.3.1"])
185
222
  s.add_dependency(%q<extlib>, [">= 0.9.12"])
186
- s.add_dependency(%q<treetop>, [">= 0.4.3"])
187
223
  s.add_dependency(%q<rake>, [">= 0.8.7"])
188
224
  s.add_dependency(%q<rspec>, [">= 1.1.11"])
189
225
  s.add_dependency(%q<yard>, [">= 1.5.4"])
190
226
  s.add_dependency(%q<jeweler>, ["= 1.4.0"])
191
227
  s.add_dependency(%q<directory_watcher>, [">= 1.3.2"])
192
- s.add_dependency(%q<haml>, [">= 2.2.3"])
228
+ s.add_dependency(%q<haml>, [">= 3.0.6"])
193
229
  s.add_dependency(%q<RedCloth>, [">= 4.2.3"])
194
230
  s.add_dependency(%q<bluecloth>, [">= 2.0.7"])
195
231
  s.add_dependency(%q<coderay>, [">= 0.9.3"])
196
- s.add_dependency(%q<ruby-prof>, [">= 0.8.1"])
197
232
  end
198
233
  end
199
234
 
data/lib/glyph.rb CHANGED
@@ -7,7 +7,6 @@ require 'pathname'
7
7
  require 'yaml'
8
8
  require 'gli'
9
9
  require 'extlib'
10
- require 'treetop'
11
10
  require 'rake'
12
11
 
13
12
  # Glyph is a Rapid Document Authoring Framework able to produce structured documents effortlessly.
@@ -29,14 +28,32 @@ module Glyph
29
28
  require LIB/'config'
30
29
  require LIB/'node'
31
30
  require LIB/'document'
32
- require LIB/'glyph_language'
33
31
  require LIB/'macro_validators'
34
32
  require LIB/'macro'
33
+ require LIB/'syntax_node'
34
+ require LIB/'parser'
35
35
  require LIB/'interpreter'
36
36
 
37
37
  class Error < RuntimeError; end
38
38
  class SyntaxError < Error; end
39
- class MacroError < Error; end
39
+ class MacroError < Error
40
+ attr_reader :macro
41
+
42
+ # Initializes a new Glyph::MacroError
43
+ # @param [String] message the error message
44
+ # @param [Glyph::Macro] macro the macro that caused the error
45
+ def initialize(message, macro)
46
+ @macro = macro
47
+ super(message)
48
+ end
49
+
50
+ # Displays the error message, source, path and node value (if debugging)
51
+ def display
52
+ Glyph.warning exception.message
53
+ Glyph.msg " source: #{@macro.source}\n path: #{@macro.path}"
54
+ Glyph.msg "#{"-"*54}\n#{@macro.node.to_s.gsub(/\t/, ' ')}\n#{"-"*54}" if Glyph.debug?
55
+ end
56
+ end
40
57
  class MutualInclusionError < MacroError; end
41
58
 
42
59
  # The current version of Glyph
@@ -50,8 +67,13 @@ module Glyph
50
67
 
51
68
  begin
52
69
  unless const_defined? :MODE then
53
- # Glyph's modes: debug/lite/test
54
- MODE = {:debug => false, :lite => false, :test => false, :library => false}
70
+ MODE = {
71
+ :debug => false,
72
+ :lite => false,
73
+ :test => false,
74
+ :library => false,
75
+ :safe => false
76
+ }
55
77
  end
56
78
  rescue
57
79
  end
@@ -60,7 +82,7 @@ module Glyph
60
82
  @@document = nil
61
83
 
62
84
  (class << self; self; end).instance_eval do
63
- ["test", "lite", "debug", "library"].each do |mode|
85
+ ["test", "lite", "debug", "library", "safe"].each do |mode|
64
86
  define_method((mode+"?").to_sym) do
65
87
  MODE[mode.to_sym]
66
88
  end
@@ -176,6 +198,12 @@ module Glyph
176
198
  MACROS[name.to_sym] = block
177
199
  end
178
200
 
201
+ def self.rewrite(name, &block)
202
+ MACROS[name.to_sym] = lambda do
203
+ rewrite &block
204
+ end
205
+ end
206
+
179
207
  # Defines an alias for an existing macro
180
208
  # @param [Hash] text the single-key hash defining the alias
181
209
  # @example
@@ -198,7 +226,7 @@ module Glyph
198
226
  Dir.chdir Pathname.new(src).parent.to_s
199
227
  begin
200
228
  require 'glyph/commands'
201
- self[:quiet] = true
229
+ self['system.quiet'] = true
202
230
  self.library_mode = true
203
231
  GLI.run ["compile", src.to_s, out].compact
204
232
  rescue Exception => e
@@ -207,7 +235,7 @@ module Glyph
207
235
  Dir.chdir pwd
208
236
  self.library_mode = false
209
237
  self.lite_mode = false
210
- self[:quiet] = false
238
+ self['system.quiet'] = false
211
239
  end
212
240
  end
213
241
 
@@ -224,7 +252,7 @@ module Glyph
224
252
  self.enable_all
225
253
  result = ""
226
254
  begin
227
- self[:quiet] = true
255
+ self['system.quiet'] = true
228
256
  self.library_mode = true
229
257
  self.run 'load:all'
230
258
  result = Interpreter.new(text).document.output
@@ -233,27 +261,40 @@ module Glyph
233
261
  ensure
234
262
  self.lite_mode = false
235
263
  self.library_mode = false
236
- self[:quiet] = false
264
+ self['system.quiet'] = false
237
265
  end
238
266
  result
239
267
  end
240
268
 
269
+
241
270
  # Prints a message
242
271
  # @param [String] message the message to print
272
+ def self.msg(message)
273
+ puts message unless Glyph['system.quiet']
274
+ end
275
+
276
+ # Prints an informational message
277
+ # @param [String] message the message to print
243
278
  def self.info(message)
244
- puts "#{message}" unless Glyph[:quiet]
279
+ puts "-- #{message}" unless Glyph['system.quiet']
245
280
  end
246
281
 
247
282
  # Prints a warning
248
283
  # @param [String] message the message to print
249
284
  def self.warning(message)
250
- puts "--> warning: #{message}" unless Glyph[:quiet]
285
+ puts "-> warning: #{message}" unless Glyph['system.quiet']
251
286
  end
252
287
 
253
288
  # Prints an error
254
289
  # @param [String] message the message to print
255
290
  def self.error(message)
256
- puts "==> error: #{message}" unless Glyph[:quiet]
291
+ puts "=> error: #{message}" unless Glyph['system.quiet']
292
+ end
293
+
294
+ # Prints a message if running in debug mode
295
+ # @param [String] message the message to print
296
+ def self.debug(message)
297
+ puts message if Glyph.debug?
257
298
  end
258
299
 
259
300
  end
@@ -29,13 +29,13 @@ command :compile do |c|
29
29
  c.desc "Specify the format of the output file (default: html)"
30
30
  c.flag [:f, :format]
31
31
  c.desc "Auto-regenerate output on file changes"
32
- c.switch :auto
32
+ c.switch [:a, :auto]
33
33
  c.action do |global_options, options, args|
34
34
  raise ArgumentError, "Too many arguments" if args.length > 2
35
35
  Glyph.lite_mode = true unless args.blank?
36
36
  Glyph.run! 'load:config'
37
37
  original_config = Glyph::CONFIG.dup
38
- output_targets = Glyph::CONFIG.get('document.output_targets')
38
+ output_targets = Glyph['system.output_targets']
39
39
  target = nil
40
40
  Glyph['document.output'] = options[:f] if options[:f]
41
41
  target = Glyph['document.output']
@@ -74,7 +74,7 @@ command :compile do |c|
74
74
  end
75
75
 
76
76
  # Auto-regeneration
77
- if options[:auto] && !Glyph.lite? then
77
+ if options[:a] && !Glyph.lite? then
78
78
  Glyph.lite_mode = false
79
79
  begin
80
80
  require 'directory_watcher'
@@ -113,11 +113,26 @@ end
113
113
  GLI.desc 'Display all project TODO items'
114
114
  command :todo do |c|
115
115
  c.action do |global_options, options, args|
116
+ Glyph['system.quiet'] = true
116
117
  Glyph.run "generate:document"
118
+ Glyph['system.quiet'] = false
117
119
  unless Glyph.document.todos.blank?
118
- Glyph.info "*** TODOs: ***"
119
- Glyph.document.todos.each do |t|
120
- Glyph.info t
120
+ puts "====================================="
121
+ puts "#{Glyph['document.title']} - TODOs"
122
+ puts "====================================="
123
+ # Group items
124
+ if Glyph.document.todos.respond_to? :group_by then
125
+ Glyph.document.todos.group_by{|e| e[:source]}.each_pair do |k, v|
126
+ puts
127
+ puts "=== #{k} "
128
+ v.each do |i|
129
+ puts " * #{i[:text]}"
130
+ end
131
+ end
132
+ else
133
+ Glyph.document.todos.each do |t|
134
+ Glyph.info t
135
+ end
121
136
  end
122
137
  else
123
138
  Glyph.info "Nothing left to do."
@@ -125,6 +140,52 @@ command :todo do |c|
125
140
  end
126
141
  end
127
142
 
143
+ GLI.desc 'Display the document outline'
144
+ command :outline do |c|
145
+ c.desc "Limit to level N"
146
+ c.flag :l, :level
147
+ c.desc "Show file names"
148
+ c.switch :f, :files
149
+ c.desc "Show titles"
150
+ c.switch :t, :titles
151
+ c.desc "Show IDs"
152
+ c.switch :i, :ids
153
+ c.action do |global_options, options, args|
154
+ levels = options[:l]
155
+ ids = options[:i]
156
+ files = options[:f]
157
+ titles = options[:t]
158
+ titles = true if !ids && !levels && !files || levels && !ids
159
+ Glyph['system.quiet'] = true
160
+ Glyph.run "generate:document"
161
+ Glyph['system.quiet'] = false
162
+ puts "====================================="
163
+ puts "#{Glyph['document.title']} - Outline"
164
+ puts "====================================="
165
+ Glyph.document.structure.descend do |n, level|
166
+ if n.is_a?(Glyph::MacroNode) then
167
+ case
168
+ when n[:name].in?(Glyph['system.structure.headers']) then
169
+ header = Glyph.document.header?(n[:header])
170
+ next if !header || levels && header[:level]-1 > levels.to_i
171
+ last_level = header[:level]
172
+ h_id = ids ? "[##{header[:id]}]" : ""
173
+ h_title = titles ? "#{header[:title]} " : ""
174
+ text = (" "*(header[:level]-1))+"- "+h_title+h_id
175
+ puts text unless text.blank?
176
+ when n[:name] == :include then
177
+ if files && n.find_parent{|p| p[:name] == :document && p.is_a?(Glyph::MacroNode)} then
178
+ # When using the book or article macros, includes appear twice:
179
+ # * in the macro parameters
180
+ # * as children of the document macro
181
+ puts "=== #{n.param(0)}"
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+
128
189
  GLI.desc 'Get/set configuration settings'
129
190
  arg_name "setting [new_value]"
130
191
  command :config do |c|
@@ -145,15 +206,19 @@ command :config do |c|
145
206
  raise RuntimeError, "Unknown setting '#{args[0]}'" if setting.blank?
146
207
  Glyph.info setting
147
208
  when 2 then
148
- # Remove all overrides
149
- Glyph.config_reset
150
- # Reload current project config
151
- config.read
152
- config.set args[0], args[1]
153
- # Write changes to file
154
- config.write
155
- # Refresh configuration
156
- Glyph.config_refresh
209
+ if args[0].match /^system\..+/ then
210
+ Glyph.warning "Cannot reset '#@value' setting (system use only)."
211
+ else
212
+ # Remove all overrides
213
+ Glyph.config_reset
214
+ # Reload current project config
215
+ config.read
216
+ config.set args[0], args[1]
217
+ # Write changes to file
218
+ config.write
219
+ # Refresh configuration
220
+ Glyph.config_refresh
221
+ end
157
222
  else
158
223
  raise ArgumentError, "Too many arguments."
159
224
  end
@@ -180,12 +245,14 @@ post do |global,command,options,args|
180
245
  end
181
246
 
182
247
  on_error do |exception|
248
+ raise if Glyph.library?
183
249
  if exception.is_a? Glyph::MacroError then
184
- Glyph.warning exception.message
250
+ exception.display
185
251
  false
186
252
  else
187
253
  if Glyph.debug? then
188
- puts "Exception: #{exception.message}"
254
+ Glyph.warning exception.message
255
+ puts "\n"+"-"*20+"[ Backtrace: ]"+"-"*20
189
256
  puts "Backtrace:"
190
257
  exception.backtrace.each do |b|
191
258
  puts b