glyph 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -4,7 +4,7 @@ document[
4
4
  ]
5
5
  body[
6
6
  @class[topic]
7
- =article[
7
+ xml/article[
8
8
  section[
9
9
  @title[{{title}}]
10
10
  @id[{{id}}]
data/lib/glyph.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # Copyright (c) 2009-2010 Fabio Cevasco
2
2
  # website: http://www.h3rald.com/glyph
3
3
  # license: MIT
4
+ # encoding: utf-8
4
5
 
5
6
  require 'rubygems'
6
7
  require 'pathname'
@@ -31,7 +32,6 @@ module Glyph
31
32
  require LIB/'bookmark'
32
33
  require LIB/'document'
33
34
  require LIB/'macro_validators'
34
- require LIB/'macro_helpers'
35
35
  require LIB/'macro'
36
36
  require LIB/'syntax_node'
37
37
  require LIB/'parser'
@@ -40,8 +40,13 @@ module Glyph
40
40
  require LIB/'reporter'
41
41
  extend Glyph::Utils
42
42
 
43
+ # A generic Glyph error.
43
44
  class Error < RuntimeError; end
45
+
46
+ # A syntax error.
44
47
  class SyntaxError < Error; end
48
+
49
+ # A macro error.
45
50
  class MacroError < Error
46
51
  include Glyph::Utils
47
52
  attr_reader :macro
@@ -62,17 +67,19 @@ module Glyph
62
67
  msg "#{"-"*54}\n#{@macro.node.to_s.gsub(/\t/, ' ')}\n#{"-"*54}" if Glyph.debug?
63
68
  end
64
69
  end
70
+
71
+ # An infinite recursion error
65
72
  class MutualInclusionError < MacroError; end
66
73
 
67
74
  # The current version of Glyph
68
- VERSION = file_load(HOME/'VERSION').strip
69
-
70
- # All the currently-loaded snippets
71
- SNIPPETS = {}
75
+ VERSION = "0.5.0"
72
76
 
73
77
  # All the currently-loaded macros
74
78
  MACROS = {}
75
79
 
80
+ # All the currently-loaded macro representations
81
+ REPS = {}
82
+
76
83
  # All macro aliases
77
84
  ALIASES = {:by_alias => {}, :by_def => {}}
78
85
 
@@ -110,10 +117,13 @@ module Glyph
110
117
  CONFIG = Glyph::Config.new :resettable => true, :mutable => false
111
118
 
112
119
  home_dir = Pathname.new(RUBY_PLATFORM.match(/win32|mingw/) ? ENV['HOMEPATH'] : ENV['HOME'])
120
+ # System configuration
113
121
  SYSTEM_CONFIG =
114
122
  Glyph::Config.new(:file => HOME/'config.yml')
123
+ # Global configuration
115
124
  GLOBAL_CONFIG =
116
125
  Glyph.test? ? Glyph::Config.new(:file => SPEC_DIR/'.glyphrc') : Glyph::Config.new(:file => home_dir/'.glyphrc')
126
+ # Project configuration
117
127
  PROJECT_CONFIG =
118
128
  Glyph::Config.new(:file => PROJECT/'config.yml', :resettable => true) rescue Glyph::Config.new(:resettable => true, :mutable => true)
119
129
 
@@ -168,7 +178,7 @@ module Glyph
168
178
  self.enable_all
169
179
  self.config_reset
170
180
  MACROS.clear
171
- SNIPPETS.clear
181
+ REPS.clear
172
182
  end
173
183
 
174
184
  # Reenables all Glyph Rake tasks
@@ -203,11 +213,34 @@ module Glyph
203
213
  MACROS[name.to_sym] = block
204
214
  end
205
215
 
206
- #@since 0.4.0
207
- # Creates a new macro by rewriting.
216
+ # Defines a new macro representation
217
+ # @since 0.5.0
218
+ # @param [Symbol, String] name the name of the macro
219
+ def self.rep(name, &block)
220
+ REPS[name.to_sym] = block
221
+ # Mirror aliases as well
222
+ ALIASES[:by_def][name.to_sym].to_a.each { |a| REPS[a] = block }
223
+ end
224
+
225
+ # Loads macro representations for a given output
226
+ # @since 0.5.0
227
+ # @param [Symbol, String] output a valid output format
228
+ def self.reps_for(output)
229
+ Glyph.instance_eval file_load(Glyph::HOME/"macros/reps/#{output}.rb") rescue nil
230
+ end
231
+
232
+ # Loads project macro representations for a given output
233
+ # @since 0.5.0
234
+ # @param [Symbol, String] output a valid output format
235
+ def self.project_reps_for(output)
236
+ Glyph.instance_eval file_load(Glyph::PROJECT/"lib/macros/reps/#{output}.rb") rescue nil
237
+ end
238
+
239
+ #@since 0.5.0
240
+ # Defines a new macro in Glyph code.
208
241
  # @param [Symbol, String] name the name of the macro
209
242
  # @param [String] text the Glyph code used to define the macro
210
- def self.rewrite(name, text)
243
+ def self.define(name, text)
211
244
  macro name do
212
245
  body = text.dup
213
246
  # Parameters
@@ -283,7 +316,6 @@ module Glyph
283
316
  result
284
317
  end
285
318
 
286
-
287
319
  end
288
320
 
289
321
  Glyph.setup
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Glyph
2
4
 
3
5
  # @since 0.4.0
@@ -186,7 +188,8 @@ module Glyph
186
188
  def stats_snippets
187
189
  c = @stats[:snippets] = {}
188
190
  snippets = {}
189
- c[:definitions] = Glyph::SNIPPETS.keys.sort
191
+ c[:definitions] = @doc.snippets.keys.sort
192
+ c[:values] = @doc.snippets
190
193
  c[:used] = []
191
194
  c[:unused] = []
192
195
  c[:total] = 0
@@ -204,7 +207,7 @@ module Glyph
204
207
  def stats_snippet(name)
205
208
  name = name.to_sym
206
209
  snippets = {}
207
- raise ArgumentError, "Snippet '#{name}' does not exist" unless Glyph::SNIPPETS[name]
210
+ raise ArgumentError, "Snippet '#{name}' does not exist" unless @doc.snippet? name
208
211
  with_macros(:snippet) do |n|
209
212
  code = n.parameters[0].to_s.to_sym
210
213
  if code == name then
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Glyph
2
4
 
3
5
  # @since 0.4.0
@@ -31,7 +33,7 @@ module Glyph
31
33
 
32
34
  # Returns true if the two bookmarks have the same ID and file
33
35
  # @param [Glyph::Bookmark] b the bookmark to compare
34
- # @raises [RuntimeError] if the parameter supplied is not a bookmark
36
+ # @raise [RuntimeError] if the parameter supplied is not a bookmark
35
37
  def ==(b)
36
38
  raise RuntimeError, "#{b.inspect} is not a bookmark" unless b.is_a? Glyph::Bookmark
37
39
  self.code == b.code && self.file == b.file
@@ -1,9 +1,13 @@
1
- include GLI
1
+ # encoding: utf-8
2
2
 
3
+ include GLI
3
4
 
4
5
  GLI.desc "Enable debugging"
5
6
  switch [:d, :debug]
6
7
 
8
+ GLI.desc "Prints the version of the program"
9
+ switch [:v, :version]
10
+
7
11
  require Glyph::LIB/'commands/init'
8
12
  require Glyph::LIB/'commands/add'
9
13
  require Glyph::LIB/'commands/compile'
@@ -17,17 +21,16 @@ Glyph.run 'load:commands'
17
21
 
18
22
  pre do |global,command,options,args|
19
23
  # Pre logic here
20
- # Return true to proceed; false to abourt and not call the
24
+ # Return true to proceed; false to abort and not call the
21
25
  # chosen command
22
26
  if global[:d] then
23
27
  Glyph.debug_mode = true
24
28
  end
25
- if !command || command.name == :help then
26
- puts "====================================="
29
+ if global[:v] || !command || command.name == :help then
27
30
  puts "Glyph v#{Glyph::VERSION}"
28
- puts "====================================="
31
+ puts
29
32
  end
30
- true
33
+ global[:v] ? false : true
31
34
  end
32
35
 
33
36
  post do |global,command,options,args|
@@ -38,10 +41,9 @@ on_error do |exception|
38
41
  raise if Glyph.library?
39
42
  if exception.is_a? Glyph::MacroError then
40
43
  exception.display
41
- false
42
44
  else
45
+ Glyph.warning exception.message
43
46
  if Glyph.debug? then
44
- Glyph.warning exception.message
45
47
  puts "\n"+"-"*20+"[ Backtrace: ]"+"-"*20
46
48
  puts "Backtrace:"
47
49
  exception.backtrace.each do |b|
@@ -49,6 +51,6 @@ on_error do |exception|
49
51
  end
50
52
  Glyph.debug_mode = false
51
53
  end
52
- true
53
54
  end
55
+ false
54
56
  end
@@ -1,8 +1,10 @@
1
+ # encoding: utf-8
2
+
1
3
  GLI.desc 'Add a new text file to the project'
2
4
  arg_name "file_name"
3
5
  command :add do |c|
4
6
  c.action do |global_options,options,args|
5
- raise ArgumentError, "Please specify a file name." if args.blank?
7
+ exit_now! "Please specify a file name.", -20 if args.blank?
6
8
  Glyph.run 'project:add', args[0]
7
9
  end
8
10
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  GLI.desc 'Compile the project'
2
4
  arg_name "[source_file] [destination_file]"
3
5
  command :compile do |c|
@@ -8,7 +10,7 @@ command :compile do |c|
8
10
  c.desc "Auto-regenerate output on file changes"
9
11
  c.switch [:a, :auto]
10
12
  c.action do |global_options, options, args|
11
- raise ArgumentError, "Too many arguments" if args.length > 2
13
+ exit_now! "Too many arguments", -12 if args.length > 2
12
14
  Glyph.lite_mode = true unless args.blank?
13
15
  Glyph.run! 'load:config'
14
16
  original_config = Glyph::CONFIG.dup
@@ -18,14 +20,15 @@ command :compile do |c|
18
20
  target = Glyph['document.output']
19
21
  target = nil if target.blank?
20
22
  target ||= Glyph["output.#{Glyph['document.output']}.filter_target"]
23
+ through = Glyph["output.#{target}.through"]
21
24
  Glyph['document.source'] = options[:s] if options[:s]
22
25
  if Glyph.multiple_output_files? then
23
26
  Glyph["output.#{Glyph['document.output']}.base"] = Glyph::PROJECT/"output/#{Glyph['document.output']}/".to_s if Glyph["output.#{Glyph['document.output']}.base"].blank?
24
27
  else
25
28
  Glyph["output.#{Glyph['document.output']}.base"] = ""
26
29
  end
27
- raise ArgumentError, "Output target not specified" unless target
28
- raise ArgumentError, "Unknown output target '#{target}'" unless output_targets.include? target.to_sym
30
+ exit_now! "Output target not specified", -30 unless target
31
+ exit_now! "Unknown output target '#{target}'", -31 unless output_targets.include? target.to_sym
29
32
 
30
33
  # Lite mode
31
34
  if Glyph.lite? then
@@ -35,15 +38,15 @@ command :compile do |c|
35
38
  src_extension = Regexp.escape(source_file.extname)
36
39
  dst_extension = "."+Glyph['document.output']
37
40
  destination_file ||= Pathname.new(source_file.to_s.gsub(/#{src_extension}$/, dst_extension))
38
- raise ArgumentError, "Source file '#{source_file}' does not exist" unless source_file.exist?
39
- raise ArgumentError, "Source and destination file are the same" if source_file.to_s == destination_file.to_s
41
+ exit_now! "Source file '#{source_file}' does not exist", -32 unless source_file.exist?
42
+ exit_now! "Source and destination file are the same", -33 if source_file.to_s == destination_file.to_s
40
43
  Glyph['document.filename'] = filename
41
44
  Glyph['document.source'] = source_file.to_s
42
45
  Glyph['document.output_dir'] = destination_file.parent.to_s # System use only
43
46
  Glyph['document.output_file'] = destination_file.basename.to_s # System use only
44
47
  end
45
48
  begin
46
- Glyph.run "generate:#{target}"
49
+ Glyph.run "generate:#{target}#{through ? "_through_#{through}" : ""}"
47
50
  rescue Exception => e
48
51
  message = e.message
49
52
  if Glyph.debug? then
@@ -61,7 +64,7 @@ command :compile do |c|
61
64
  begin
62
65
  require 'directory_watcher'
63
66
  rescue LoadError
64
- raise RuntimeError, "DirectoryWatcher is not available. Install it with: gem install directory_watcher"
67
+ exit_now! "DirectoryWatcher is not available. Install it with: gem install directory_watcher", -34
65
68
  end
66
69
  Glyph.info 'Auto-regeneration enabled'
67
70
  Glyph.info 'Use ^C to interrupt'
@@ -1,7 +1,9 @@
1
+ # encoding: utf-8
2
+
1
3
  GLI.desc 'Get/set configuration settings'
2
4
  arg_name "setting [new_value]"
3
5
  command :config do |c|
4
- c.desc "Save to global configuration"
6
+ c.desc "Read from/Save to global configuration"
5
7
  c.switch [:g, :global]
6
8
  c.action do |global_options,options,args|
7
9
  Glyph.run 'load:config'
@@ -12,14 +14,14 @@ command :config do |c|
12
14
  end
13
15
  case args.length
14
16
  when 0 then
15
- raise ArgumentError, "Too few arguments."
17
+ exit_now! "Too few arguments.", -10
16
18
  when 1 then # read current config
17
19
  setting = Glyph[args[0]]
18
- raise RuntimeError, "Unknown setting '#{args[0]}'" if setting.blank?
20
+ exit_now! "Unknown setting '#{args[0]}'", -11 if setting == nil
19
21
  Glyph.info setting.inspect
20
22
  when 2 then
21
23
  if args[0].match /^system\..+/ then
22
- Glyph.warning "Cannot reset '#@value' setting (system use only)."
24
+ exit_now! "Cannot reset '#@value' setting (system use only).", -11
23
25
  else
24
26
  # Remove all overrides
25
27
  Glyph.config_reset
@@ -32,7 +34,7 @@ command :config do |c|
32
34
  Glyph.config_refresh
33
35
  end
34
36
  else
35
- raise ArgumentError, "Too many arguments."
37
+ exit_now! "Too many arguments.", -12
36
38
  end
37
39
  end
38
40
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  GLI.desc 'Create a new Glyph project'
2
4
  command :init do |c|
3
5
  c.action do |global_options,options,args|
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  GLI.desc 'Display the document outline'
2
4
  command :outline do |c|
3
5
  c.desc "Limit to level N"
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  GLI.desc 'Display statistics'
2
4
  command :stats do |c|
3
5
  c.desc "Display stats about macros"
@@ -32,6 +34,7 @@ command :stats do |c|
32
34
  no_flags = true
33
35
  [:macro, :bookmark, :link, :snippet].each do |f|
34
36
  if options[f] then
37
+ analyzer.stats_for :snippets if f == :snippet
35
38
  analyzer.stats_for f, options[f]
36
39
  no_flags = false
37
40
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  GLI.desc 'Display all project TODO items'
2
4
  command :todo do |c|
3
5
  c.action do |global_options, options, args|
data/lib/glyph/config.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Glyph
2
4
 
3
5
  # The Glyph::Config class is used (you don't say!) to store configuration data. Essentially it wraps a Hash of Hashes
@@ -9,9 +9,11 @@ module Glyph
9
9
  # as well as replacing placeholders.
10
10
  class Document
11
11
 
12
- ESCAPES = /\\([\\\]\[\|.=])/
12
+ # A Regexp containing the characters to escape
13
+ ESCAPES = /\\([\\\]\[\|\/=])/
13
14
 
14
- attr_reader :bookmarks, :placeholders, :headers, :styles, :context, :errors, :todos, :topics, :links, :toc
15
+ attr_reader :bookmarks, :placeholders, :headers, :styles, :context
16
+ attr_reader :errors, :todos, :topics, :links, :toc, :fragments, :snippets
15
17
 
16
18
  # Creates a new document
17
19
  # @param [GlyphSyntaxNode] tree the syntax tree to be evaluate
@@ -24,6 +26,8 @@ module Glyph
24
26
  @placeholders = {}
25
27
  @bookmarks = {}
26
28
  @headers = {}
29
+ @snippets = {}
30
+ @fragments = {}
27
31
  @styles = []
28
32
  @errors = []
29
33
  @todos = []
@@ -49,12 +53,14 @@ module Glyph
49
53
  def inherit_from(document, data={})
50
54
  @bookmarks = document.bookmarks unless data[:bookmarks] == false
51
55
  @headers = document.headers unless data[:headers] == false
56
+ @snippets = document.snippets unless data[:snippets] == false
52
57
  @todos = document.todos unless data[:todos] == false
53
58
  @styles = document.styles unless data[:styles] == false
54
59
  @topics = document.topics unless data[:topics] == false
55
60
  @placeholders = document.placeholders unless data[:placeholders] == false
56
61
  @toc = document.toc unless data[:toc] == false
57
- @links = document.links unless data[:links] == true
62
+ @links = document.links unless data[:links] == false
63
+ @fragments = document.fragments unless data[:fragments] == false
58
64
  self
59
65
  end
60
66
 
@@ -75,7 +81,8 @@ module Glyph
75
81
  end
76
82
 
77
83
  # Stores a new bookmark
78
- # @param [Hash] hash the bookmark hash: {:id => "BookmarkID", :title => "Bookmark Title", :file => "dir/preface.glyph"}
84
+ # @param [Hash] hash the bookmark hash
85
+ # @example {:id => "BookmarkID", :title => "Bookmark Title", :file => "dir/preface.glyph"}
79
86
  # @return [Glyph::Bookmark] the stored bookmark
80
87
  # @raise [RuntimeError] if the bookmark is already defined.
81
88
  def bookmark(hash)
@@ -86,7 +93,8 @@ module Glyph
86
93
  end
87
94
 
88
95
  # Stores a new header
89
- # @param [Hash] hash the header hash: {:id => "Bookmark_ID", :title => "Bookmark Title", :level => 3}
96
+ # @param [Hash] hash the header hash
97
+ # @example {:id => "Bookmark_ID", :title => "Bookmark Title", :level => 3}
90
98
  # @return [Glyph::Header] the stored header
91
99
  # @raise [RuntimeError] if the bookmark is already defined.
92
100
  def header(hash)
@@ -104,10 +112,27 @@ module Glyph
104
112
  @headers[key.to_sym]
105
113
  end
106
114
 
115
+ # Stores a new snippet
116
+ # @param [Symbol, String] key the snippet identifier
117
+ # @param [string] value the snippet contents
118
+ # @return [String] the stored snippet
119
+ # @since 0.5.0
120
+ def snippet(key, value)
121
+ @snippets[key.to_sym] = value
122
+ end
123
+
124
+ # Returns a stored snippet or nil
125
+ # @param [String, Symbol] key the snippet identifier
126
+ # @return [String, nil] the snippet contents or nil if no snippet is found
127
+ # @since 0.5.0
128
+ def snippet?(key)
129
+ @snippets[key.to_sym]
130
+ end
131
+
107
132
  # @since 0.4.0
108
133
  # Stores a stylesheet
109
134
  # @param [String] file the stylesheet file
110
- # @raises [RuntimeError] if the stylesheet is already specified for the document (unless the output has more than one file)
135
+ # @raise [RuntimeError] if the stylesheet is already specified for the document (unless the output has more than one file)
111
136
  def style(file)
112
137
  f = Pathname.new file
113
138
  if @styles.include?(f) && !Glyph.multiple_output_files? then
@@ -152,10 +177,10 @@ module Glyph
152
177
  end
153
178
  end
154
179
  # Substitute escape sequences
155
- @output.gsub!(ESCAPES) { |match| ($1 == '.') ? '' : $1 }
156
- toc[:contents].gsub!(ESCAPES) { |match| ($1 == '.') ? '' : $1 } rescue nil
180
+ @output.gsub!(ESCAPES) { |match| ($1 == '/') ? '' : $1 }
181
+ toc[:contents].gsub!(ESCAPES) { |match| ($1 == '/') ? '' : $1 } rescue nil
157
182
  @topics.each do |t|
158
- t[:contents].gsub!(ESCAPES) { |match| ($1 == '.') ? '' : $1 }
183
+ t[:contents].gsub!(ESCAPES) { |match| ($1 == '/') ? '' : $1 }
159
184
  end
160
185
  @state = :finalized
161
186
  end