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
data/macros/xml.rb CHANGED
@@ -1,33 +1,38 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
- macro "|xml|" do
4
- begin
5
- valid_xml_element
4
+ macro :xml do
5
+ dispatch do |node|
6
+ name = node[:name]
7
+ valid_xml_element name
6
8
  max_parameters 1
7
- rescue Exception => e
8
- if @node[:fallback] then
9
- macro_error "Unknown macro '#{@node[:element]}'"
9
+ if Glyph["options.xml_blacklist"] && name.to_s.in?(Glyph['options.xml_blacklist']) then
10
+ ""
10
11
  else
11
- raise
12
- end
13
- end
14
- name = @node[:element]
15
- if Glyph["options.xml_blacklist"] && name.to_s.in?(Glyph['options.xml_blacklist']) then
16
- ""
17
- else
18
- attributes # evaluate attributes
19
- xml_attributes = @node.children.select{|node| node.is_a?(Glyph::AttributeNode)}.
20
- map do |e|
21
- if valid_xml_attribute(e[:name]) then
22
- %|#{e[:name]}="#{e[:value]}"|
23
- else
24
- nil
25
- end
12
+ attributes # evaluate attributes
13
+ xml_attributes = node.children.select{|n| n.is_a?(Glyph::AttributeNode)}.map do |e|
14
+ if valid_xml_attribute(e[:name]) then
15
+ attr_v = e[:value].blank? ? e.evaluate(node, :attrs => true) : e[:value]
16
+ %|#{e[:name]}="#{attr_v}"|
17
+ else
18
+ nil
19
+ end
26
20
  end.compact.join(" ")
27
21
  xml_attributes = " "+xml_attributes unless xml_attributes.blank?
28
- end_first_tag = param(0) ? ">" : ""
29
- end_tag = param(0) ? "</#{name}>" : " />"
30
- contents = (@node.param(0)&0) && (@node.param(0)&0)[:element] ? "\n#{param(0)}\n" : param(0)
22
+ end_first_tag = node.param(0) ? ">" : ""
23
+ end_tag = node.param(0) ? "</#{name}>" : " />"
24
+ if node.param(0) then
25
+ param_0 = node.param(0)[:value].blank? ? node.param(0).evaluate(node, :params => true) : node.param(0)[:value]
26
+ if (node.param(0)&0) && (node.param(0)&0)[:name] then
27
+ contents = "\n#{param_0}\n"
28
+ else
29
+ contents = param_0
30
+ end
31
+ else
32
+ # no parameters
33
+ contents = ""
34
+ end
31
35
  %{<#{name}#{xml_attributes}#{end_first_tag}#{contents}#{end_tag}}
36
+ end
32
37
  end
33
38
  end
data/spec/config.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ :a: 1
3
+ :b:
4
+ :b1: 1111
5
+ :b2: 2222
6
+ :b3:
7
+ :b12: 2222
@@ -1,5 +1,5 @@
1
1
  $:[document.author|Test]
2
2
  &:[test|Test Snippet]
3
- section[
4
- $[document.author] -- &[test]
3
+ §[
4
+ 改善 $[document.author] -- &[test]
5
5
  ]
@@ -5,14 +5,18 @@ document[
5
5
  ]
6
6
  body[
7
7
  toc[]
8
- contents[
8
+ section[
9
9
  section[
10
10
  @title[Web Document]
11
11
  ...
12
- section[
13
- @src[a/web1.glyph]
14
- @title[Topic #1]
15
- ]
12
+ section[
13
+ @title[Another section]
14
+ Some text...
15
+ section[
16
+ @src[a/web1.glyph]
17
+ @title[Topic #1]
18
+ ]
19
+ ]
16
20
  section[
17
21
  @src[a/b/web2.glyph]
18
22
  @title[Topic #2]
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
2
4
  require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
5
  require 'glyph/commands'
4
6
 
@@ -12,6 +14,11 @@ describe "glyph" do
12
14
  reset_quiet
13
15
  delete_project
14
16
  end
17
+
18
+ it "[-v] should pront the program name and version and quit" do
19
+ run_command(["-v"]).should == "Glyph v#{Glyph::VERSION}\n\n"
20
+ run_command(["-v", "compile"]).should == "Glyph v#{Glyph::VERSION}\n\n"
21
+ end
15
22
 
16
23
  it "[init] should create a project in the current directory" do
17
24
  delete_project
@@ -22,8 +29,8 @@ describe "glyph" do
22
29
 
23
30
  it "[config] should read configuration settings" do
24
31
  create_project
25
- run_command_successfully(["config", "-g"]).should == false
26
- run_command(["config", "document.html.filter_target"]).match(/html/m).should_not == nil
32
+ run_command_with_status(["config", "-g"]).should == -10
33
+ run_command(["config", "document.output"]).match(/html/m).should_not == nil
27
34
  end
28
35
 
29
36
  it "[config] should write configuration settings" do
@@ -41,7 +48,6 @@ describe "glyph" do
41
48
  Glyph::PROJECT_CONFIG.get('another.test').should_not == "something else"
42
49
  Glyph::GLOBAL_CONFIG.read
43
50
  Glyph::GLOBAL_CONFIG.get('another.test').should == "something else"
44
- run_command_successfully(["config", "-g", "yet.another.test", "something else", "extra argument"]).should == false
45
51
  (Glyph::SPEC_DIR/'.glyphrc').unlink
46
52
  end
47
53
 
@@ -143,16 +149,17 @@ describe "glyph" do
143
149
  Pathname.new('article.html').exist?.should == true
144
150
  file_load('article.html').gsub(/\t|\n/, '').should == %{
145
151
  <div class="section">
146
- Test -- Test Snippet
152
+ 改善 Test -- Test Snippet
147
153
  </div>
148
154
  }.gsub(/\t|\n/, '')
149
- Glyph.enable 'generate:html'
150
155
  (Glyph::PROJECT/'article.html').unlink
151
156
  Glyph['document.output'] = 'pdf'
152
157
  src = Glyph::PROJECT/'article.html'
153
158
  out = Glyph::PROJECT/'article.pdf'
154
159
  generate_pdf = lambda do |gen|
160
+ Glyph.enable 'generate:html'
155
161
  Glyph.enable 'generate:pdf'
162
+ Glyph.enable 'generate:pdf_through_html'
156
163
  Glyph['output.pdf.generator'] = gen
157
164
  run_command_successfully(["compile", "article.glyph"]).should == true
158
165
  src.exist?.should == true
@@ -184,8 +191,7 @@ describe "glyph" do
184
191
  out = file_load Glyph::PROJECT/'output/html/test_project.html'
185
192
  out.should == %{<div class="section">
186
193
  <h2 id="h_1">Test</h2>
187
- <span class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>Correct errors in file 'errors.glyph'</span>
188
- <span class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>Correct errors in file 'syntax_error.glyph'</span>
194
+
189
195
 
190
196
  </div>}
191
197
  res.match("error: #{err}").should == nil
@@ -233,10 +239,8 @@ test_project - Outline
233
239
  out = run_command(["stats", "-ms"])
234
240
  total_macros = (Glyph::MACROS.keys - Glyph::ALIASES[:by_alias].keys).uniq.length
235
241
  out.should match "-- Total Macro Definitions: #{total_macros}"
236
- out.should match "-- Unused Snippets: test"
237
242
  out = run_command(["stats"])
238
243
  out.should match "-- Total Macro Definitions: #{total_macros}"
239
- out.should_not match "-- Unused Snippets: test"
240
244
  out.should match "-- Total Unreferenced Bookmarks: 3"
241
245
  out = run_command(["stats", "-lb", "--bookmark=md"])
242
246
  out.should match "-- Unreferenced Bookmarks: h_1, h_2, md"
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+ # encoding: utf-8
3
3
 
4
4
  describe Glyph::Config do
5
5
 
@@ -14,7 +14,7 @@ describe Glyph::Config do
14
14
  end
15
15
 
16
16
  after(:all) do
17
- @config_path.delete
17
+ @config_path.delete rescue nil
18
18
  end
19
19
 
20
20
  it "should load a YAML configuration file" do
@@ -149,5 +149,15 @@ describe Glyph::Document do
149
149
  reset_quiet
150
150
  end
151
151
 
152
+ it "should store fragments" do
153
+ delete_project
154
+ create_project
155
+ Glyph.run! "load:all"
156
+ doc = create_doc create_tree("testing ##[frag1|fragments!] -- ##[frag2|another fragment]")
157
+ doc.analyze
158
+ doc.fragments.should == {:frag1 => "fragments!", :frag2 => "another fragment"}
159
+ reset_quiet
160
+ end
161
+
152
162
  end
153
163
 
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
2
 
4
3
  describe Glyph do
5
4
 
@@ -50,15 +49,18 @@ describe Glyph do
50
49
  it "should provide a compile method to compile files in lite mode" do
51
50
  reset_quiet
52
51
  file_copy Glyph::PROJECT/'../files/article.glyph', Glyph::PROJECT/'article.glyph'
53
- lambda { Glyph.compile Glyph::PROJECT/'article.glyph' }.should_not raise_error
52
+ #lambda {
53
+ Glyph.debug_mode = true
54
+ Glyph.compile Glyph::PROJECT/'article.glyph'
55
+ #}.should_not raise_error
54
56
  (Glyph::PROJECT/'article.html').exist?.should == true
55
57
  end
56
58
 
57
- it "should provide a reset method to remove config overrides, reenable tasks, clear macros and snippets." do
59
+ it "should provide a reset method to remove config overrides, reenable tasks, clear macros and reps" do
58
60
  Glyph['test_setting'] = true
59
61
  Glyph.reset
60
- Glyph::SNIPPETS.length.should == 0
61
62
  Glyph::MACROS.length.should == 0
63
+ Glyph::REPS.length.should == 0
62
64
  Glyph['test_setting'].should == nil
63
65
  end
64
66
 
@@ -69,14 +71,14 @@ describe Glyph do
69
71
  lambda { output_for("include[test.glyph]")}.should raise_error Glyph::MacroError
70
72
  lambda {output_for("config:[test|true]")}.should raise_error Glyph::MacroError
71
73
  lambda { output_for("ruby[Time.now]")}.should raise_error Glyph::MacroError
72
- lambda { output_for("rw:[a|section[{{0}}]]")}.should raise_error Glyph::MacroError
74
+ lambda { output_for("def:[a|section[{{0}}]]")}.should raise_error Glyph::MacroError
73
75
  Glyph.safe_mode = false
74
76
  end
75
77
 
76
- it "should rewrite macros using Glyph syntax" do
78
+ it "should define macros using Glyph syntax" do
77
79
  define_em_macro
78
- Glyph.rewrite :test_rw_macro, %{em[{{0}} -- {{a}}]}
79
- output_for("test_rw_macro[@a[!]?]").should == "<em>? -- !</em>"
80
+ Glyph.define :test_def_macro, %{em[{{0}} -- {{a}}]}
81
+ output_for("test_def_macro[@a[!]?]").should == "<em>? -- !</em>"
80
82
  end
81
83
 
82
84
  it "should store alias information" do
@@ -93,4 +95,24 @@ describe Glyph do
93
95
  Glyph.macro_alias?(:"#").should == true
94
96
  end
95
97
 
98
+ it "should store macro representations" do
99
+ delete_project_dir
100
+ create_project_dir
101
+ Glyph.macro :test_rep do
102
+ end
103
+ Glyph.macro_alias :test_rep_alias => :test_rep
104
+ Glyph.rep :test_rep do |data|
105
+ "TEST - #{data[:a]}"
106
+ end
107
+ Glyph::REPS[:test_rep].call(:a => 1).should == "TEST - 1"
108
+ Glyph::REPS[:test_rep_alias].call(:a => 1).should == "TEST - 1"
109
+ end
110
+
111
+ it "should load reps for a given output" do
112
+ Glyph.reps_for(:html)
113
+ Glyph::REPS[:section].should_not be_blank
114
+ Glyph::REPS[:link].should_not be_blank
115
+ Glyph::REPS[:"=>"].should_not be_blank
116
+ end
117
+
96
118
  end
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
2
 
4
3
  describe Glyph::Macro do
5
4
 
@@ -220,13 +219,49 @@ describe Glyph::Macro do
220
219
  Glyph.macro :test_int do
221
220
  interpret "- #{value} -"
222
221
  end
223
- text1 = "em[test\\\\\\.\\[...\\\\\\.\\]]" # test\\\.\[\\\.\]
224
- text2 = "em[=test\\\\\\.[...\\\\\\.]=]" # test\\\.[\\\.]
225
- text3 = "test_int[em[=test\\\\\\.[...\\\\\\.]=]]"
222
+ text1 = "em[test\\\\\\/\\[...\\\\\\/\\]]" # test\\\/\[\\\/\]
223
+ text2 = "em[=test\\\\\\/[...\\\\\\/]=]" # test\\\/[\\\/]
224
+ text3 = "test_int[em[=test\\\\\\/[...\\\\\\/]=]]"
226
225
  out = "<em>test\\[...\\]</em>"
227
226
  output_for(text1).should == out
228
227
  output_for(text2).should == out
229
228
  output_for(text3).should == "- #{out} -"
230
229
  end
231
230
 
231
+ it "should render representations" do
232
+ Glyph.macro :em_with_rep do
233
+ @data[:value] = value
234
+ render
235
+ end
236
+ Glyph.rep :em_with_rep do |data|
237
+ %{<em>!#{data[:value]}!</em>}
238
+ end
239
+ output_for("em_with_rep[testing...]").should == "<em>!testing...!</em>"
240
+ Glyph::Macro.new({}).render(:em_with_rep, :value => "test").should == "<em>!test!</em>"
241
+ end
242
+
243
+ it "should perform dispatching" do
244
+ Glyph.macro :dispatcher do
245
+ dispatch do |node|
246
+ "dispatched: #{node[:name]}" if node[:name] == :em
247
+ end
248
+ end
249
+ Glyph.macro :another_macro do
250
+ "...#{value}"
251
+ end
252
+ define_em_macro
253
+ output_for("dispatcher[em[test]]").should == "dispatched: em"
254
+ output_for("dispatcher[em[@attr[test]]]").should == "dispatched: em"
255
+ output_for("dispatcher[...|em[@attr[test]]]").should == "..." # Dispatcher macros should only take one parameter
256
+ output_for("dispatcher[another_macro[test]]").should == "...test"
257
+ output_for("dispatcher[another_macro[another_macro[test]]]").should == "......test"
258
+ end
259
+
260
+ it "should apply text with placeholders to macro data" do
261
+ Glyph.macro :data do
262
+ apply "{{1}} {{a}} {{0}}"
263
+ end
264
+ output_for("data[@a[is]a test|This]").should == "This is a test"
265
+ end
266
+
232
267
  end
@@ -36,8 +36,7 @@ describe Glyph::Macro::Validators do
36
36
  end
37
37
 
38
38
  it "should check for mutual inclusion" do
39
- Glyph::SNIPPETS[:inc] = "Test &[inc]"
40
- lambda {interpret("&[inc] test").document}.should raise_error(Glyph::MutualInclusionError)
39
+ interpret("&:[inc|Test &[inc]]&[inc] test").document.output.should == "Test [SNIPPET 'inc' NOT PROCESSED] test"
41
40
  end
42
41
 
43
42
  it "should validate XML elements" do
@@ -48,13 +47,13 @@ describe Glyph::Macro::Validators do
48
47
 
49
48
  it "should validate XML attributes" do
50
49
  language 'xml'
51
- output_for("test[test @.test[test]]").should == "<test>test</test>"
50
+ output_for("test[test @.test[test]]").should == "<test>test </test>"
52
51
  end
53
52
 
54
53
  it "should validate required attributes" do
55
54
  Glyph['document.output'] = 'web'
56
55
  Glyph.run! 'load:macros'
57
- lambda { output_for("contents[section[@src[test]]]") }.should raise_error(Glyph::MacroError, "Macro 'section' requires a 'title' attribute")
56
+ lambda { output_for("section[section[@src[test]]]") }.should raise_error(Glyph::MacroError, "Macro 'section' requires a 'title' attribute")
58
57
  end
59
58
 
60
59
  it "should validate if a macro is within another one" do
@@ -243,4 +243,11 @@ Contents]
243
243
  parse_text(text).should == tree
244
244
  end
245
245
 
246
+ it "should allow macro composition" do
247
+ parse_text("test[...|a/b/c[...]]").should == parse_text("test[...|a[b[c[...]]]]")
248
+ parse_text(" /test[...]").should == parse_text(" test[...]")
249
+ parse_text(" test/[...]").should == parse_text(" test[...]")
250
+ parse_text("a/b/c[=test[...]=]").should == parse_text("a[b[c[=test[...]=]]]")
251
+ end
252
+
246
253
  end
@@ -84,6 +84,7 @@ describe Glyph::Reporter do
84
84
  end
85
85
 
86
86
  it "should display stats for a single snippet" do
87
+ stats :snippets
87
88
  stats :snippet, :test
88
89
  out = stdout_for { rep.display }
89
90
  out.should match "-- Total Used Instances: 2"
@@ -83,12 +83,6 @@ describe Glyph::MacroNode do
83
83
  @n.expand({}).should == "--test:test--"
84
84
  end
85
85
 
86
- it "should resolve to an XML element" do
87
- reset_quiet
88
- @n.expand({}) rescue nil # |xml| macro not defined
89
- @n[:element].should == "test"
90
- end
91
-
92
86
  it "should retrieve parameter nodes easily" do
93
87
  @n.parameter(0).should == @p
94
88
  @n.parameters.should == [@p]
@@ -106,6 +100,46 @@ describe Glyph::MacroNode do
106
100
  @p.parent[:escape] = true
107
101
  @p.to_s.should == "test"
108
102
  @p.contents.should == ".[=test=]"
103
+ ###
104
+ n = macro_node(:test)
105
+ a = a_node(:a)
106
+ a[:escape] = true
107
+ a << text_node("alias[test\\|test1]")
108
+ n << a
109
+ a.to_s.should == "@a[=alias[test\\|test1]=]"
110
+ a.contents.should == ".[=alias[test\\|test1]=]"
111
+ end
112
+
113
+ it "should perform macro dispatching" do
114
+ dispatch_proc = lambda do |node|
115
+ "dispatched: #{node[:name]}"
116
+ end
117
+ Glyph.macro :test_macro do
118
+ "--test macro--"
119
+ end
120
+ # Parent dispatcher via parameter
121
+ d = macro_node :dispatcher
122
+ d[:dispatch] = dispatch_proc
123
+ p = p_node 0
124
+ m = macro_node :test_macro
125
+ p << m
126
+ d << p
127
+ m.expand({}).should == "dispatched: test_macro"
128
+ # Parent dispatcher via attribute
129
+ d = macro_node :dispatcher
130
+ d[:dispatch] = dispatch_proc
131
+ a = a_node :attr1
132
+ m = macro_node :test_macro
133
+ a << m
134
+ d << a
135
+ m.expand({}).should == "dispatched: test_macro"
136
+ # No dispatcher
137
+ d = macro_node :no_dispatcher
138
+ a = a_node :attr1
139
+ m = macro_node :test_macro
140
+ a << m
141
+ d << a
142
+ m.expand({}).should == "--test macro--"
109
143
  end
110
144
 
111
145
  end