glyph 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +19 -40
- data/benchmark.rb +1 -2
- data/book/config.yml +8 -8
- data/book/document.glyph +18 -19
- data/book/images/glyph/commands_tasks.png +0 -0
- data/book/lib/layouts/bookindex.glyph +113 -111
- data/book/lib/layouts/bookpage.glyph +112 -108
- data/book/lib/macros/reference.rb +2 -2
- data/book/lib/tasks/tasks.rake +1 -1
- data/book/text/acknowledgements.glyph +1 -0
- data/book/text/changelog.glyph +140 -112
- data/book/text/compiling/compiling.glyph +36 -24
- data/book/text/compiling/lite_mode.glyph +11 -11
- data/book/text/compiling/programmatic_usage.glyph +57 -57
- data/book/text/config/document.glyph +7 -1
- data/book/text/config/options.glyph +5 -3
- data/book/text/config/output.glyph +41 -8
- data/book/text/extending/bookmarks_headers.glyph +13 -11
- data/book/text/extending/command.glyph +1 -1
- data/book/text/extending/commands_tasks.glyph +2 -2
- data/book/text/extending/internals.glyph +29 -29
- data/book/text/extending/interpreting.glyph +48 -9
- data/book/text/extending/macro_def.glyph +80 -32
- data/book/text/extending/output_format.glyph +2 -2
- data/book/text/extending/placeholders.glyph +27 -15
- data/book/text/extending/validators.glyph +1 -1
- data/book/text/getting_started/configuration.glyph +1 -1
- data/book/text/getting_started/create_project.glyph +4 -5
- data/book/text/getting_started/structure.glyph +2 -2
- data/book/text/macros/macros_core.glyph +341 -199
- data/book/text/macros/macros_filters.glyph +1 -1
- data/book/text/macros/macros_inline.glyph +3 -3
- data/book/text/macros/macros_structure.glyph +1 -1
- data/book/text/ref_commands.glyph +98 -93
- data/book/text/snippets.glyph +18 -0
- data/book/text/stats/bookmarks.glyph +16 -16
- data/book/text/stats/links.glyph +23 -23
- data/book/text/stats/macros.glyph +14 -14
- data/book/text/stats/snippets.glyph +26 -26
- data/book/text/stats/stats.glyph +14 -15
- data/book/text/text_editing/attribute_intro.glyph +8 -8
- data/book/text/text_editing/code.glyph +16 -16
- data/book/text/text_editing/conditionals.glyph +12 -13
- data/book/text/text_editing/esc_quot.glyph +3 -3
- data/book/text/text_editing/evaluation.glyph +57 -3
- data/book/text/text_editing/inclusions.glyph +34 -25
- data/book/text/text_editing/macro_composition.glyph +28 -0
- data/book/text/text_editing/macro_intro.glyph +4 -4
- data/book/text/text_editing/section_aliases.glyph +23 -23
- data/book/text/text_editing/sections.glyph +22 -22
- data/book/text/text_editing/stylesheets.glyph +33 -33
- data/book/text/text_editing/topics.glyph +6 -6
- data/book/text/text_editing/xml_fallback.glyph +1 -1
- data/book/text/troubleshooting/errors_command.glyph +4 -4
- data/book/text/troubleshooting/errors_generic.glyph +16 -10
- data/book/text/troubleshooting/errors_macro.glyph +18 -21
- data/book/text/troubleshooting/errors_parser.glyph +7 -7
- data/config.yml +51 -29
- data/document.glyph +18 -18
- data/glyph.gemspec +39 -287
- data/layouts/web5/topic.glyph +1 -1
- data/lib/glyph.rb +42 -10
- data/lib/glyph/analyzer.rb +5 -2
- data/lib/glyph/bookmark.rb +3 -1
- data/lib/glyph/commands.rb +11 -9
- data/lib/glyph/commands/add.rb +3 -1
- data/lib/glyph/commands/compile.rb +10 -7
- data/lib/glyph/commands/config.rb +7 -5
- data/lib/glyph/commands/init.rb +2 -0
- data/lib/glyph/commands/outline.rb +2 -0
- data/lib/glyph/commands/stats.rb +3 -0
- data/lib/glyph/commands/todo.rb +2 -0
- data/lib/glyph/config.rb +2 -0
- data/lib/glyph/document.rb +34 -9
- data/lib/glyph/interpreter.rb +2 -0
- data/lib/glyph/macro.rb +97 -25
- data/lib/glyph/macro_validators.rb +9 -6
- data/lib/glyph/node.rb +3 -1
- data/lib/glyph/parser.rb +68 -33
- data/lib/glyph/reporter.rb +3 -1
- data/lib/glyph/syntax_node.rb +23 -28
- data/lib/glyph/system_extensions.rb +21 -0
- data/lib/glyph/utils.rb +24 -4
- data/macros/block.rb +111 -0
- data/macros/core.rb +163 -33
- data/macros/filters.rb +3 -2
- data/macros/inline.rb +97 -0
- data/macros/reps/html.rb +180 -0
- data/macros/reps/html5.rb +100 -0
- data/macros/reps/web.rb +4 -0
- data/macros/reps/web5.rb +4 -0
- data/macros/structure.rb +229 -0
- data/macros/xml.rb +29 -24
- data/spec/config.yml +7 -0
- data/spec/files/article.glyph +2 -2
- data/spec/files/web_doc.glyph +9 -5
- data/spec/lib/commands_spec.rb +13 -9
- data/spec/lib/config_spec.rb +2 -2
- data/spec/lib/document_spec.rb +10 -0
- data/spec/lib/glyph_spec.rb +30 -8
- data/spec/lib/macro_spec.rb +39 -4
- data/spec/lib/macro_validators_spec.rb +3 -4
- data/spec/lib/parser_spec.rb +7 -0
- data/spec/lib/reporter_spec.rb +1 -0
- data/spec/lib/syntax_node_spec.rb +40 -6
- data/spec/macros/core_spec.rb +154 -21
- data/spec/macros/filters_spec.rb +1 -1
- data/spec/macros/html5_spec.rb +4 -5
- data/spec/macros/macros_spec.rb +6 -7
- data/spec/macros/web5_spec.rb +3 -3
- data/spec/macros/web_spec.rb +10 -7
- data/spec/macros/xml_spec.rb +11 -2
- data/spec/spec_helper.rb +11 -5
- data/spec/tasks/generate_spec.rb +40 -5
- data/spec/tasks/load_spec.rb +1 -13
- data/styles/coderay.css +147 -38
- data/styles/default.css +19 -22
- data/styles/pagination.css +30 -30
- data/tasks/generate.rake +54 -18
- data/tasks/load.rake +9 -24
- data/tasks/project.rake +0 -2
- metadata +208 -207
- data/.gitignore +0 -7
- data/VERSION +0 -1
- data/book/snippets.yml +0 -18
- data/lib/glyph/macro_helpers.rb +0 -282
- data/macros/html/block.rb +0 -124
- data/macros/html/inline.rb +0 -42
- data/macros/html/structure.rb +0 -191
- data/macros/html5/block.rb +0 -69
- data/macros/html5/inline.rb +0 -24
- 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
|
4
|
-
|
5
|
-
|
4
|
+
macro :xml do
|
5
|
+
dispatch do |node|
|
6
|
+
name = node[:name]
|
7
|
+
valid_xml_element name
|
6
8
|
max_parameters 1
|
7
|
-
|
8
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
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
data/spec/files/article.glyph
CHANGED
data/spec/files/web_doc.glyph
CHANGED
@@ -5,14 +5,18 @@ document[
|
|
5
5
|
]
|
6
6
|
body[
|
7
7
|
toc[]
|
8
|
-
|
8
|
+
section[
|
9
9
|
section[
|
10
10
|
@title[Web Document]
|
11
11
|
...
|
12
|
-
|
13
|
-
|
14
|
-
|
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]
|
data/spec/lib/commands_spec.rb
CHANGED
@@ -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
|
-
|
26
|
-
run_command(["config", "document.
|
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
|
-
|
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"
|
data/spec/lib/config_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
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
|
data/spec/lib/document_spec.rb
CHANGED
@@ -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
|
|
data/spec/lib/glyph_spec.rb
CHANGED
@@ -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 {
|
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
|
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("
|
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
|
78
|
+
it "should define macros using Glyph syntax" do
|
77
79
|
define_em_macro
|
78
|
-
Glyph.
|
79
|
-
output_for("
|
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
|
data/spec/lib/macro_spec.rb
CHANGED
@@ -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
|
224
|
-
text2 = "em[=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
|
-
|
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("
|
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
|
data/spec/lib/parser_spec.rb
CHANGED
@@ -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
|
data/spec/lib/reporter_spec.rb
CHANGED
@@ -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
|