glyph 0.5.2 → 0.5.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/AUTHORS.textile +1 -0
- data/CHANGELOG.textile +104 -59
- data/Gemfile.lock +46 -0
- data/LICENSE.textile +1 -1
- data/README.textile +106 -120
- data/book/lib/layouts/bookindex.glyph +6 -106
- data/book/lib/layouts/bookpage.glyph +8 -108
- data/book/lib/layouts/project.glyph +0 -1
- data/book/text/acknowledgements.glyph +1 -0
- data/book/text/changelog.glyph +7 -1
- data/glyph.gemspec +10 -10
- data/lib/glyph.rb +1 -1
- data/spec/files/test.scss +1 -1
- data/spec/lib/analyzer_spec.rb +60 -61
- data/spec/lib/bookmark_spec.rb +21 -21
- data/spec/lib/commands_spec.rb +53 -54
- data/spec/lib/config_spec.rb +16 -16
- data/spec/lib/document_spec.rb +35 -35
- data/spec/lib/glyph_spec.rb +32 -32
- data/spec/lib/interpreter_spec.rb +8 -8
- data/spec/lib/macro_spec.rb +51 -49
- data/spec/lib/macro_validators_spec.rb +14 -14
- data/spec/lib/node_spec.rb +25 -25
- data/spec/lib/parser_spec.rb +26 -26
- data/spec/lib/reporter_spec.rb +32 -32
- data/spec/lib/syntax_node_spec.rb +33 -33
- data/spec/macros/core_spec.rb +95 -95
- data/spec/macros/filters_spec.rb +9 -8
- data/spec/macros/html5_spec.rb +17 -17
- data/spec/macros/macros_spec.rb +33 -33
- data/spec/macros/textile_spec.rb +15 -15
- data/spec/macros/web5_spec.rb +3 -3
- data/spec/macros/web_spec.rb +19 -19
- data/spec/macros/xml_spec.rb +15 -15
- data/spec/tasks/generate_spec.rb +34 -34
- data/spec/tasks/load_spec.rb +15 -15
- data/spec/tasks/project_spec.rb +15 -15
- data/styles/coderay.css +2 -0
- data/styles/coderay.css.map +7 -0
- data/styles/default.css +9 -7
- data/styles/default.css.map +7 -0
- data/styles/pagination.css +18 -23
- data/styles/pagination.css.map +7 -0
- data/tasks/generate.rake +12 -5
- metadata +47 -68
- data/glyph-0.5.1.gem +0 -0
data/spec/lib/glyph_spec.rb
CHANGED
@@ -11,39 +11,39 @@ describe Glyph do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should initialize a rake app and tasks" do
|
14
|
-
Rake.application.tasks.length.
|
14
|
+
expect(Rake.application.tasks.length).to be > 0
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should run rake tasks" do
|
18
18
|
delete_project_dir
|
19
19
|
create_project_dir
|
20
20
|
Glyph.run 'project:create', Glyph::PROJECT
|
21
|
-
|
21
|
+
expect { Glyph.run! 'project:create', Glyph::PROJECT }.to raise_error
|
22
22
|
delete_project_dir
|
23
23
|
create_project_dir
|
24
|
-
|
24
|
+
expect { Glyph.run! 'project:create', Glyph::PROJECT }.not_to raise_error
|
25
25
|
delete_project_dir
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should define macros" do
|
29
|
-
|
30
|
-
|
31
|
-
Glyph::MACROS.include?(:em).
|
32
|
-
Glyph::MACROS.include?(:ref).
|
29
|
+
expect { define_em_macro }.not_to raise_error
|
30
|
+
expect { define_ref_macro }.not_to raise_error
|
31
|
+
expect(Glyph::MACROS.include?(:em)).to eq(true)
|
32
|
+
expect(Glyph::MACROS.include?(:ref)).to eq(true)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should support macro aliases" do
|
36
36
|
define_ref_macro
|
37
37
|
define_em_macro
|
38
|
-
|
39
|
-
Glyph::MACROS[:"->"].
|
38
|
+
expect { Glyph.macro_alias("->" => :ref)}.not_to raise_error
|
39
|
+
expect(Glyph::MACROS[:"->"]).to eq(Glyph::MACROS[:ref])
|
40
40
|
Glyph.macro_alias :em => :ref
|
41
|
-
Glyph::MACROS[:em].
|
41
|
+
expect(Glyph::MACROS[:em]).to eq(Glyph::MACROS[:ref])
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should provide a filter method to convert raw text into HTML" do
|
45
45
|
Glyph['document.title'] = "Test"
|
46
|
-
Glyph.filter("title[]").gsub(/\n|\t/, '').
|
46
|
+
expect(Glyph.filter("title[]").gsub(/\n|\t/, '')).to eq("<h1>Test</h1>")
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should provide a compile method to compile files in lite mode" do
|
@@ -53,32 +53,32 @@ describe Glyph do
|
|
53
53
|
Glyph.debug_mode = true
|
54
54
|
Glyph.compile Glyph::PROJECT/'article.glyph'
|
55
55
|
#}.should_not raise_error
|
56
|
-
(Glyph::PROJECT/'article.html').exist
|
56
|
+
expect((Glyph::PROJECT/'article.html').exist?).to eq(true)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should provide a reset method to remove config overrides, reenable tasks, clear macros and reps" do
|
60
60
|
Glyph['test_setting'] = true
|
61
61
|
Glyph.reset
|
62
|
-
Glyph::MACROS.length.
|
63
|
-
Glyph::REPS.length.
|
64
|
-
Glyph['test_setting'].
|
62
|
+
expect(Glyph::MACROS.length).to eq(0)
|
63
|
+
expect(Glyph::REPS.length).to eq(0)
|
64
|
+
expect(Glyph['test_setting']).to eq(nil)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should not allow certain macros to be expanded in safe mode" do
|
68
68
|
create_project
|
69
69
|
Glyph.run! "load:all"
|
70
70
|
Glyph.safe_mode = true
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
expect { output_for("include[test.glyph]")}.to raise_error Glyph::MacroError
|
72
|
+
expect {output_for("config:[test|true]")}.to raise_error Glyph::MacroError
|
73
|
+
expect { output_for("ruby[Time.now]")}.to raise_error Glyph::MacroError
|
74
|
+
expect { output_for("def:[a|section[{{0}}]]")}.to raise_error Glyph::MacroError
|
75
75
|
Glyph.safe_mode = false
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should define macros using Glyph syntax" do
|
79
79
|
define_em_macro
|
80
80
|
Glyph.define :test_def_macro, %{em[{{0}} -- {{a}}]}
|
81
|
-
output_for("test_def_macro[@a[!]?]").
|
81
|
+
expect(output_for("test_def_macro[@a[!]?]")).to eq("<em>? -- !</em>")
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should store alias information" do
|
@@ -86,13 +86,13 @@ describe Glyph do
|
|
86
86
|
create_project_dir
|
87
87
|
Glyph.run! 'project:create', Glyph::PROJECT
|
88
88
|
Glyph.run 'load:all'
|
89
|
-
Glyph::ALIASES[:by_def][:snippet].
|
90
|
-
Glyph::ALIASES[:by_alias][:"?"].
|
91
|
-
Glyph.macro_aliases_for(:link).
|
92
|
-
Glyph.macro_aliases_for(:"=>").
|
93
|
-
Glyph.macro_definition_for(:"=>").
|
94
|
-
Glyph.macro_definition_for(:link).
|
95
|
-
Glyph.macro_alias?(:"#").
|
89
|
+
expect(Glyph::ALIASES[:by_def][:snippet]).to eq([:&])
|
90
|
+
expect(Glyph::ALIASES[:by_alias][:"?"]).to eq(:condition)
|
91
|
+
expect(Glyph.macro_aliases_for(:link)).to eq([:"=>"])
|
92
|
+
expect(Glyph.macro_aliases_for(:"=>")).to eq(nil)
|
93
|
+
expect(Glyph.macro_definition_for(:"=>")).to eq(:link)
|
94
|
+
expect(Glyph.macro_definition_for(:link)).to eq(nil)
|
95
|
+
expect(Glyph.macro_alias?(:"#")).to eq(true)
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should store macro representations" do
|
@@ -104,15 +104,15 @@ describe Glyph do
|
|
104
104
|
Glyph.rep :test_rep do |data|
|
105
105
|
"TEST - #{data[:a]}"
|
106
106
|
end
|
107
|
-
Glyph::REPS[:test_rep].call(:a => 1).
|
108
|
-
Glyph::REPS[:test_rep_alias].call(:a => 1).
|
107
|
+
expect(Glyph::REPS[:test_rep].call(:a => 1)).to eq("TEST - 1")
|
108
|
+
expect(Glyph::REPS[:test_rep_alias].call(:a => 1)).to eq("TEST - 1")
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should load reps for a given output" do
|
112
112
|
Glyph.reps_for(:html)
|
113
|
-
Glyph::REPS[:section].
|
114
|
-
Glyph::REPS[:link].
|
115
|
-
Glyph::REPS[:"=>"].
|
113
|
+
expect(Glyph::REPS[:section]).not_to be_blank
|
114
|
+
expect(Glyph::REPS[:link]).not_to be_blank
|
115
|
+
expect(Glyph::REPS[:"=>"]).not_to be_blank
|
116
116
|
end
|
117
117
|
|
118
118
|
end
|
@@ -18,16 +18,16 @@ describe Glyph::Interpreter do
|
|
18
18
|
it "should process text and run simple macros" do
|
19
19
|
define_em_macro
|
20
20
|
text = "This is a em[test]. It em[should] work."
|
21
|
-
output_for(text).
|
21
|
+
expect(output_for(text)).to eq("This is a <em>test</em>. It <em>should</em> work.")
|
22
22
|
text2 = "This is pointless, but valid: em[]. This em[will] though."
|
23
|
-
output_for(text2).
|
23
|
+
expect(output_for(text2)).to eq("This is pointless, but valid: <em></em>. This <em>will</em> though.")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should process and run complex macros" do
|
27
27
|
define_ref_macro
|
28
28
|
text = "This is a ref[http://www.h3rald.com|test]."
|
29
29
|
interpret text
|
30
|
-
@p.document.output.
|
30
|
+
expect(@p.document.output).to eq("This is a <a href=\"http://www.h3rald.com\">test</a>.")
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should support multiline macros" do
|
@@ -39,7 +39,7 @@ describe Glyph::Interpreter do
|
|
39
39
|
|
40
40
|
] macro.}
|
41
41
|
interpret text
|
42
|
-
@p.document.output.
|
42
|
+
expect(@p.document.output).to eq(%{This is a test containing a <a href="http://www.h3rald.com">multiline</a> macro.})
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should support escape characters" do
|
@@ -47,7 +47,7 @@ describe Glyph::Interpreter do
|
|
47
47
|
text = %{This text contains em[
|
48
48
|
some escaped em\\[content\\]... etc.].}
|
49
49
|
interpret text
|
50
|
-
@p.document.output.
|
50
|
+
expect(@p.document.output).to eq(%{This text contains <em>some escaped em[content]... etc.</em>.})
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should support nested macros" do
|
@@ -55,7 +55,7 @@ describe Glyph::Interpreter do
|
|
55
55
|
define_ref_macro
|
56
56
|
text = %{This is an ref[#test|em[emphasized] link]}
|
57
57
|
interpret text
|
58
|
-
@p.document.output.
|
58
|
+
expect(@p.document.output).to eq(%{This is an <a href="#test"><em>emphasized</em> link</a>})
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should store syntax node information in context" do
|
@@ -66,12 +66,12 @@ describe Glyph::Interpreter do
|
|
66
66
|
end
|
67
67
|
text = %{Test em[test_node[em[test_node[---]]]].}
|
68
68
|
interpret text
|
69
|
-
@p.document.output.
|
69
|
+
expect(@p.document.output).to eq("Test <em>em</em>.")
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should provide diagnostic information on errors" do
|
73
73
|
failure = "-- [1, 12] Macro 'section' not closed"
|
74
|
-
|
74
|
+
expect { interpret("section[em[]").document }.to raise_error(Glyph::SyntaxError, failure)
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|
data/spec/lib/macro_spec.rb
CHANGED
@@ -18,11 +18,11 @@ describe Glyph::Macro do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should raise macro errors" do
|
21
|
-
|
21
|
+
expect { @macro.macro_error "Error!" }.to raise_error(Glyph::MacroError)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should interpret strings" do
|
25
|
-
@macro.interpret("test[--]").
|
25
|
+
expect(@macro.interpret("test[--]")).to eq("Test: --")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should not interpret escaped macros" do
|
@@ -36,33 +36,33 @@ describe Glyph::Macro do
|
|
36
36
|
text2 = "int_1[=int_2[Test]=]"
|
37
37
|
text3 = "int_1[=int_2\\[Test\\]=]"
|
38
38
|
text4 = "int_2[int_1[=int_1[wrong_macro[Test]]=]]"
|
39
|
-
@macro.interpret(text1).
|
40
|
-
@macro.interpret(text2).
|
41
|
-
@macro.interpret(text3).
|
42
|
-
@macro.interpret(text4).
|
39
|
+
expect(@macro.interpret(text1)).to eq("->=>Test<=<-")
|
40
|
+
expect(@macro.interpret(text2)).to eq("->int_2\\[Test\\]<-")
|
41
|
+
expect(@macro.interpret(text3)).to eq("->int_2\\[Test\\]<-")
|
42
|
+
expect(@macro.interpret(text4)).to eq("=>->int_1\\[wrong_macro\\[Test\\]\\]<-<=")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should store and check bookmarks" do
|
46
46
|
h = { :id => "test2", :title => "Test 2", :file => 'test.glyph' }
|
47
47
|
@macro.bookmark h
|
48
|
-
@doc.bookmark?(:test2).
|
49
|
-
@macro.bookmark?(:test2).
|
48
|
+
expect(@doc.bookmark?(:test2)).to eq(Glyph::Bookmark.new(h))
|
49
|
+
expect(@macro.bookmark?(:test2)).to eq(Glyph::Bookmark.new(h))
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should store and check headers" do
|
53
53
|
h = { :level => 2, :id => "test3", :title => "Test 3", :file => "test.glyph"}
|
54
54
|
@macro.header h
|
55
|
-
@doc.header?("test3").
|
56
|
-
@macro.header?("test3").
|
55
|
+
expect(@doc.header?("test3")).to eq(Glyph::Bookmark.new(h))
|
56
|
+
expect(@macro.header?("test3")).to eq(Glyph::Bookmark.new(h))
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should store placeholders" do
|
60
60
|
@macro.placeholder { |document| }
|
61
|
-
@doc.placeholders.length.
|
61
|
+
expect(@doc.placeholders.length).to eq(1)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should expand" do
|
65
|
-
@macro.expand.
|
65
|
+
expect(@macro.expand).to eq("Test: Testing...")
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should support rewriting" do
|
@@ -88,8 +88,9 @@ describe Glyph::Macro do
|
|
88
88
|
]
|
89
89
|
]
|
90
90
|
}
|
91
|
-
output_for(text).gsub(/\n|\t/, '').
|
91
|
+
expect(output_for(text).gsub(/\n|\t/, '')).to eq(
|
92
92
|
"ReleaseFeatures: a-2b-3c-4-1"
|
93
|
+
)
|
93
94
|
test = 0
|
94
95
|
Glyph.macro :test do
|
95
96
|
interpret "#{value}-#{test+=1}"
|
@@ -103,8 +104,9 @@ describe Glyph::Macro do
|
|
103
104
|
Glyph.macro :feature do
|
104
105
|
interpret "test[#{value}]\n"
|
105
106
|
end
|
106
|
-
output_for(text).gsub(/\n|\t/, '').
|
107
|
+
expect(output_for(text).gsub(/\n|\t/, '')).to eq(
|
107
108
|
"ReleaseFeatures: a-1b-2c-3-4"
|
109
|
+
)
|
108
110
|
end
|
109
111
|
|
110
112
|
it "should support access to parameters and attributes" do
|
@@ -116,13 +118,13 @@ describe Glyph::Macro do
|
|
116
118
|
end
|
117
119
|
node = Glyph::Parser.new("test[@a[test1[...]]test1[...]|test1[---]]").parse
|
118
120
|
m = Glyph::Macro.new(node&0)
|
119
|
-
m.parameters.
|
120
|
-
m.attributes.
|
121
|
-
m.parameter(0).
|
122
|
-
m.parameter(1).
|
123
|
-
m.parameter(2).
|
124
|
-
m.attribute(:a).
|
125
|
-
m.attribute(:b).
|
121
|
+
expect(m.parameters).to eq(["test1: ...", "test1: ---"])
|
122
|
+
expect(m.attributes).to eq({:a => "test1: ..."})
|
123
|
+
expect(m.parameter(0)).to eq("test1: ...")
|
124
|
+
expect(m.parameter(1)).to eq("test1: ---")
|
125
|
+
expect(m.parameter(2)).to eq(nil)
|
126
|
+
expect(m.attribute(:a)).to eq("test1: ...")
|
127
|
+
expect(m.attribute(:b)).to eq(nil)
|
126
128
|
end
|
127
129
|
|
128
130
|
it "should not evaluate attributes unless specifically requested" do
|
@@ -142,12 +144,12 @@ describe Glyph::Macro do
|
|
142
144
|
p10 = p_node 0
|
143
145
|
(p1&0) << p10
|
144
146
|
p10 << text_node("---")
|
145
|
-
m.node.parameters.
|
146
|
-
m.node.parameters[0][:value].
|
147
|
-
m.node.parameters[1][:value].
|
148
|
-
m.parameter(0).
|
149
|
-
m.node.parameters[0][:value].
|
150
|
-
m.node.parameters[1][:value].
|
147
|
+
expect(m.node.parameters).to eq([p0, p1])
|
148
|
+
expect(m.node.parameters[0][:value]).to eq(nil)
|
149
|
+
expect(m.node.parameters[1][:value]).to eq(nil)
|
150
|
+
expect(m.parameter(0)).to eq("<em>...</em>")
|
151
|
+
expect(m.node.parameters[0][:value]).to eq("<em>...</em>")
|
152
|
+
expect(m.node.parameters[1][:value]).to eq(nil)
|
151
153
|
end
|
152
154
|
|
153
155
|
it "should not evaluate parameters unless specifically requested" do
|
@@ -167,12 +169,12 @@ describe Glyph::Macro do
|
|
167
169
|
p10 = p_node 0
|
168
170
|
(p1&0) << p10
|
169
171
|
p10 << text_node("---")
|
170
|
-
m.node.attributes.
|
171
|
-
m.node.attribute(:a)[:value].
|
172
|
-
m.node.attribute(:b)[:value].
|
173
|
-
m.attribute(:a).
|
174
|
-
m.node.attribute(:a)[:value].
|
175
|
-
m.node.attribute(:b)[:value].
|
172
|
+
expect(m.node.attributes).to eq([p0, p1])
|
173
|
+
expect(m.node.attribute(:a)[:value]).to eq(nil)
|
174
|
+
expect(m.node.attribute(:b)[:value]).to eq(nil)
|
175
|
+
expect(m.attribute(:a)).to eq("<em>...</em>")
|
176
|
+
expect(m.node.attribute(:a)[:value]).to eq("<em>...</em>")
|
177
|
+
expect(m.node.attribute(:b)[:value]).to eq(nil)
|
176
178
|
end
|
177
179
|
|
178
180
|
it "should treat empty parameters/attributes as null" do
|
@@ -195,10 +197,10 @@ describe Glyph::Macro do
|
|
195
197
|
end
|
196
198
|
result
|
197
199
|
end
|
198
|
-
output_for("test_ap[]").
|
199
|
-
output_for("test_ap[@a[]|]").
|
200
|
-
output_for("test_ap[@a[.]|]").
|
201
|
-
output_for("test_ap[@a[.].|.]").
|
200
|
+
expect(output_for("test_ap[]")).to eq("(!a)(!0)(!1)")
|
201
|
+
expect(output_for("test_ap[@a[]|]")).to eq("(!a)(!0)(!1)")
|
202
|
+
expect(output_for("test_ap[@a[.]|]")).to eq("(a)(!0)(!1)")
|
203
|
+
expect(output_for("test_ap[@a[.].|.]")).to eq("(a)(0)(1)")
|
202
204
|
end
|
203
205
|
|
204
206
|
it "should expose a path method to determine its location" do
|
@@ -211,7 +213,7 @@ describe Glyph::Macro do
|
|
211
213
|
]}).parse
|
212
214
|
node = tree&1&1&1&0&1&0&0
|
213
215
|
m = Glyph::Macro.new(node)
|
214
|
-
m.path.
|
216
|
+
expect(m.path).to eq("test1/1/b/test2/@a/x")
|
215
217
|
end
|
216
218
|
|
217
219
|
it "should substitute bracket escapes properly" do
|
@@ -223,9 +225,9 @@ describe Glyph::Macro do
|
|
223
225
|
text2 = "em[=test\\\\\\/[...\\\\\\/]=]" # test\\\/[\\\/]
|
224
226
|
text3 = "test_int[em[=test\\\\\\/[...\\\\\\/]=]]"
|
225
227
|
out = "<em>test\\[...\\]</em>"
|
226
|
-
output_for(text1).
|
227
|
-
output_for(text2).
|
228
|
-
output_for(text3).
|
228
|
+
expect(output_for(text1)).to eq(out)
|
229
|
+
expect(output_for(text2)).to eq(out)
|
230
|
+
expect(output_for(text3)).to eq("- #{out} -")
|
229
231
|
end
|
230
232
|
|
231
233
|
it "should render representations" do
|
@@ -236,8 +238,8 @@ describe Glyph::Macro do
|
|
236
238
|
Glyph.rep :em_with_rep do |data|
|
237
239
|
%{<em>!#{data[:value]}!</em>}
|
238
240
|
end
|
239
|
-
output_for("em_with_rep[testing...]").
|
240
|
-
Glyph::Macro.new({}).render(:em_with_rep, :value => "test").
|
241
|
+
expect(output_for("em_with_rep[testing...]")).to eq("<em>!testing...!</em>")
|
242
|
+
expect(Glyph::Macro.new({}).render(:em_with_rep, :value => "test")).to eq("<em>!test!</em>")
|
241
243
|
end
|
242
244
|
|
243
245
|
it "should perform dispatching" do
|
@@ -250,18 +252,18 @@ describe Glyph::Macro do
|
|
250
252
|
"...#{value}"
|
251
253
|
end
|
252
254
|
define_em_macro
|
253
|
-
output_for("dispatcher[em[test]]").
|
254
|
-
output_for("dispatcher[em[@attr[test]]]").
|
255
|
-
output_for("dispatcher[...|em[@attr[test]]]").
|
256
|
-
output_for("dispatcher[another_macro[test]]").
|
257
|
-
output_for("dispatcher[another_macro[another_macro[test]]]").
|
255
|
+
expect(output_for("dispatcher[em[test]]")).to eq("dispatched: em")
|
256
|
+
expect(output_for("dispatcher[em[@attr[test]]]")).to eq("dispatched: em")
|
257
|
+
expect(output_for("dispatcher[...|em[@attr[test]]]")).to eq("...") # Dispatcher macros should only take one parameter
|
258
|
+
expect(output_for("dispatcher[another_macro[test]]")).to eq("...test")
|
259
|
+
expect(output_for("dispatcher[another_macro[another_macro[test]]]")).to eq("......test")
|
258
260
|
end
|
259
261
|
|
260
262
|
it "should apply text with placeholders to macro data" do
|
261
263
|
Glyph.macro :data do
|
262
264
|
apply "{{1}} {{a}} {{0}}"
|
263
265
|
end
|
264
|
-
output_for("data[@a[is]a test|This]").
|
266
|
+
expect(output_for("data[@a[is]a test|This]")).to eq("This is a test")
|
265
267
|
end
|
266
268
|
|
267
269
|
end
|
@@ -18,42 +18,42 @@ describe Glyph::Macro::Validators do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should provide custom validation" do
|
21
|
-
|
22
|
-
|
21
|
+
expect { interpret("section[validated_test[invalid]]").document.output }.to raise_error Glyph::MacroError
|
22
|
+
expect { interpret("chapter[validated_test[valid]]").document.output }.not_to raise_error
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should validate the number of parameters" do
|
26
26
|
# exact
|
27
|
-
|
27
|
+
expect { interpret("section[sfsdg|saf]").document.output }.to raise_error Glyph::MacroError
|
28
28
|
# none
|
29
|
-
|
29
|
+
expect { interpret("title[test]").document.output }.to raise_error Glyph::MacroError
|
30
30
|
# min
|
31
|
-
|
31
|
+
expect { interpret("?[]").document.output }.to raise_error Glyph::MacroError
|
32
32
|
# max
|
33
|
-
|
33
|
+
expect { interpret("not[a|b|c]").document.output }.to raise_error Glyph::MacroError
|
34
34
|
# correct
|
35
|
-
|
35
|
+
expect { interpret("chapter[fmi[something|#something]]").document.output }.not_to raise_error
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should check for mutual inclusion" do
|
39
|
-
interpret("&:[inc|Test &[inc]]&[inc] test").document.output.
|
39
|
+
expect(interpret("&:[inc|Test &[inc]]&[inc] test").document.output).to eq("Test [SNIPPET 'inc' NOT PROCESSED] test")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should validate XML elements" do
|
43
43
|
language 'xml'
|
44
|
-
|
45
|
-
|
44
|
+
expect { interpret("<test[test]").document}.to raise_error
|
45
|
+
expect { interpret("_test[test]").document}.not_to raise_error
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should validate XML attributes" do
|
49
49
|
language 'xml'
|
50
|
-
output_for("test[test @.test[test]]").
|
50
|
+
expect(output_for("test[test @.test[test]]")).to eq("<test>test </test>")
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should validate required attributes" do
|
54
54
|
Glyph['document.output'] = 'web'
|
55
55
|
Glyph.run! 'load:macros'
|
56
|
-
|
56
|
+
expect { output_for("section[section[@src[test]]]") }.to raise_error(Glyph::MacroError, "Macro 'section' requires a 'title' attribute")
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should validate if a macro is within another one" do
|
@@ -62,7 +62,7 @@ describe Glyph::Macro::Validators do
|
|
62
62
|
within :em
|
63
63
|
"---"
|
64
64
|
end
|
65
|
-
|
65
|
+
expect { output_for("within_m[test]") }.to raise_error(Glyph::MacroError, "Macro 'within_m' must be within a 'em' macro")
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should validate if a macro is not within another one" do
|
@@ -71,7 +71,7 @@ describe Glyph::Macro::Validators do
|
|
71
71
|
not_within :em
|
72
72
|
"---"
|
73
73
|
end
|
74
|
-
|
74
|
+
expect { output_for("em[within_m[test]]") }.to raise_error(Glyph::MacroError, "Macro 'within_m' must not be within a 'em' macro")
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|