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/bookmark_spec.rb
CHANGED
@@ -10,55 +10,55 @@ describe Glyph::Bookmark do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should be initialized with at least an id" do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
expect { Glyph::Bookmark.new }.to raise_error
|
14
|
+
expect { Glyph::Bookmark.new({:id => :test}) }.not_to raise_error
|
15
|
+
expect { Glyph::Bookmark.new({:file => "test"}) }.to raise_error
|
16
|
+
expect { Glyph::Bookmark.new({:id => "test", :file => "test.glyph"}) }.not_to raise_error
|
17
17
|
end
|
18
18
|
|
19
19
|
it "shiuld expose title, code and file" do
|
20
|
-
@b.file.
|
21
|
-
@b.code.
|
22
|
-
@b.title.
|
23
|
-
Glyph::Bookmark.new(:id => :test2, :title => "Test 2").title.
|
20
|
+
expect(@b.file).to eq("test.glyph")
|
21
|
+
expect(@b.code).to eq(:test)
|
22
|
+
expect(@b.title).to eq(nil)
|
23
|
+
expect(Glyph::Bookmark.new(:id => :test2, :title => "Test 2").title).to eq("Test 2")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should convert to a string" do
|
27
27
|
@b.code.to_s == @b.to_s
|
28
|
-
"#{@b}".
|
28
|
+
expect("#{@b}").to eq(@b.to_s)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should format the link for a single output file" do
|
32
32
|
# Link within the same file
|
33
|
-
@b.link.
|
33
|
+
expect(@b.link).to eq("#test")
|
34
34
|
# Link to a different file file
|
35
|
-
@b.link('intro.glyph').
|
35
|
+
expect(@b.link('intro.glyph')).to eq("#test")
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should format the link for multiple output files" do
|
39
39
|
out = Glyph['document.output']
|
40
40
|
Glyph['document.output'] = 'web'
|
41
41
|
# Link within the same file
|
42
|
-
@b.link("test.glyph").
|
42
|
+
expect(@b.link("test.glyph")).to eq("#test")
|
43
43
|
# Link to a different file file
|
44
|
-
@b.link("intro.glyph").
|
44
|
+
expect(@b.link("intro.glyph")).to eq("/test.html#test")
|
45
45
|
# Test that base directory is added correctly
|
46
46
|
Glyph["output.#{Glyph['document.output']}.base"] = ""
|
47
|
-
@b.link("intro.glyph").
|
48
|
-
@b.link("test.glyph").
|
47
|
+
expect(@b.link("intro.glyph")).to eq("test.html#test")
|
48
|
+
expect(@b.link("test.glyph")).to eq("#test")
|
49
49
|
Glyph['document.output'] = out
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should check ID validity" do
|
53
|
-
|
53
|
+
expect { Glyph::Bookmark.new :id => "#test$", :file => "test.glyph"}.to raise_error(RuntimeError, "Invalid bookmark ID: #test$")
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should check bookmark equality" do
|
57
|
-
@b.
|
58
|
-
@b.
|
59
|
-
@b.
|
60
|
-
@b.
|
61
|
-
@b.
|
57
|
+
expect(@b).to eq(Glyph::Bookmark.new(:id => :test, :file => 'test.glyph'))
|
58
|
+
expect(@b).to eq(Glyph::Bookmark.new(:id => :test, :file => "test.glyph"))
|
59
|
+
expect(@b).to eq(Glyph::Bookmark.new(:id => :test, :file => 'test.glyph', :level => 2))
|
60
|
+
expect(@b).not_to eq(Glyph::Bookmark.new(:id => :test1, :file => 'test.glyph'))
|
61
|
+
expect(@b).not_to eq(Glyph::Bookmark.new(:id => :test, :file => 'test1.glyph'))
|
62
62
|
end
|
63
63
|
|
64
64
|
end
|
data/spec/lib/commands_spec.rb
CHANGED
@@ -19,57 +19,57 @@ describe "glyph" do
|
|
19
19
|
delete_project
|
20
20
|
Glyph.enable "project:create"
|
21
21
|
Dir.chdir Glyph::PROJECT.to_s
|
22
|
-
run_command_successfully(['init']).
|
22
|
+
expect(run_command_successfully(['init'])).to eq(true)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "[config] should read configuration settings" do
|
26
26
|
create_project
|
27
|
-
run_command_with_status(["config", "-g"]).
|
28
|
-
run_command(["config", "document.output"]).match(/html/m).
|
27
|
+
expect(run_command_with_status(["config", "-g"])).to eq(-10)
|
28
|
+
expect(run_command(["config", "document.output"]).match(/html/m)).not_to eq(nil)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "[config] should write configuration settings" do
|
32
32
|
create_project
|
33
|
-
run_command_successfully(["config", "test_setting", "true"]).
|
34
|
-
Glyph::CONFIG.get(:test_setting).
|
33
|
+
expect(run_command_successfully(["config", "test_setting", "true"])).to eq(true)
|
34
|
+
expect(Glyph::CONFIG.get(:test_setting)).to eq(true)
|
35
35
|
Glyph::PROJECT_CONFIG.read
|
36
|
-
Glyph::PROJECT_CONFIG.get('test_setting').
|
36
|
+
expect(Glyph::PROJECT_CONFIG.get('test_setting')).to eq(true)
|
37
37
|
Glyph::GLOBAL_CONFIG.read
|
38
|
-
Glyph::GLOBAL_CONFIG.get('test_setting').
|
39
|
-
run_command_successfully(["config", "-g", "another.test", "something else"]).
|
40
|
-
(Glyph::SPEC_DIR/'.glyphrc').exist
|
41
|
-
Glyph::CONFIG.get("another.test").
|
38
|
+
expect(Glyph::GLOBAL_CONFIG.get('test_setting')).not_to eq(true)
|
39
|
+
expect(run_command_successfully(["config", "-g", "another.test", "something else"])).to eq(true)
|
40
|
+
expect((Glyph::SPEC_DIR/'.glyphrc').exist?).to eq(true)
|
41
|
+
expect(Glyph::CONFIG.get("another.test")).to eq("something else")
|
42
42
|
Glyph::PROJECT_CONFIG.read
|
43
|
-
Glyph::PROJECT_CONFIG.get('another.test').
|
43
|
+
expect(Glyph::PROJECT_CONFIG.get('another.test')).not_to eq("something else")
|
44
44
|
Glyph::GLOBAL_CONFIG.read
|
45
|
-
Glyph::GLOBAL_CONFIG.get('another.test').
|
45
|
+
expect(Glyph::GLOBAL_CONFIG.get('another.test')).to eq("something else")
|
46
46
|
(Glyph::SPEC_DIR/'.glyphrc').unlink
|
47
47
|
end
|
48
48
|
|
49
49
|
it "[config] should not overwrite system settings" do
|
50
50
|
create_project
|
51
51
|
Glyph['system.test_setting'] = false
|
52
|
-
run_command(["config", "system.test_setting", "true"]).match(/warning.+\(system use only\)/m).
|
53
|
-
Glyph['system.test_setting'].
|
52
|
+
expect(run_command(["config", "system.test_setting", "true"]).match(/warning.+\(system use only\)/m)).not_to eq(nil)
|
53
|
+
expect(Glyph['system.test_setting']).to eq(false)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "[add] should create a new text file" do
|
57
57
|
create_project
|
58
|
-
run_command_successfully(["add", "test.textile"]).
|
59
|
-
(Glyph::PROJECT/'text/test.textile').exist
|
58
|
+
expect(run_command_successfully(["add", "test.textile"])).to eq(true)
|
59
|
+
expect((Glyph::PROJECT/'text/test.textile').exist?).to eq(true)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "[compile] should compile the project" do
|
63
63
|
create_project
|
64
|
-
run_command(["compile"]).match(/test_project\.html/m).
|
65
|
-
(Glyph::PROJECT/'output/html/test_project.html').exist
|
64
|
+
expect(run_command(["compile"]).match(/test_project\.html/m)).not_to eq(nil)
|
65
|
+
expect((Glyph::PROJECT/'output/html/test_project.html').exist?).to eq(true)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "[compile] should support a custom source file" do
|
69
69
|
create_project
|
70
70
|
file_copy Glyph::PROJECT/'document.glyph', Glyph::PROJECT/'custom.glyph'
|
71
|
-
run_command(["-d", "compile", "-s", "custom.glyph"]).match(/custom\.glyph/m).
|
72
|
-
(Glyph::PROJECT/'output/html/test_project.html').exist
|
71
|
+
expect(run_command(["-d", "compile", "-s", "custom.glyph"]).match(/custom\.glyph/m)).not_to eq(nil)
|
72
|
+
expect((Glyph::PROJECT/'output/html/test_project.html').exist?).to eq(true)
|
73
73
|
end
|
74
74
|
|
75
75
|
it "[compile] should not continue execution in case of macro errors" do
|
@@ -84,10 +84,10 @@ describe "glyph" do
|
|
84
84
|
}
|
85
85
|
file_write Glyph::PROJECT/'document.glyph', text
|
86
86
|
res = run_command(["compile"])
|
87
|
-
res.match(/Bookmark 'invalid1' does not exist/).
|
88
|
-
res.match(/Bookmark 'invalid2' does not exist/).
|
89
|
-
res.match(/Bookmark 'valid' does not exist/).
|
90
|
-
res.match(/Snippet 'invalid3' does not exist/).
|
87
|
+
expect(res.match(/Bookmark 'invalid1' does not exist/)).not_to eq(nil)
|
88
|
+
expect(res.match(/Bookmark 'invalid2' does not exist/)).not_to eq(nil)
|
89
|
+
expect(res.match(/Bookmark 'valid' does not exist/)).to eq(nil)
|
90
|
+
expect(res.match(/Snippet 'invalid3' does not exist/)).not_to eq(nil)
|
91
91
|
end
|
92
92
|
|
93
93
|
it "[compile] should regenerate output with auto switch set" do
|
@@ -122,17 +122,17 @@ describe "glyph" do
|
|
122
122
|
compile_thread.join
|
123
123
|
|
124
124
|
output2 = file_load output_file
|
125
|
-
output.
|
126
|
-
output2.match(/<p>This is another test.<\/p>/).
|
125
|
+
expect(output).not_to eq(output2)
|
126
|
+
expect(output2.match(/<p>This is another test.<\/p>/)).not_to eq(nil)
|
127
127
|
|
128
|
-
res.match(/Auto-regeneration enabled/).
|
129
|
-
res.match(/Regeneration started: 1 files changed/).
|
128
|
+
expect(res.match(/Auto-regeneration enabled/)).not_to eq(nil)
|
129
|
+
expect(res.match(/Regeneration started: 1 files changed/)).not_to eq(nil)
|
130
130
|
reset_quiet
|
131
131
|
end
|
132
132
|
|
133
133
|
it "[compile] should not compile the project in case of an unknown output format" do
|
134
134
|
reset_quiet
|
135
|
-
run_command_successfully(["compile", "-f", "wrong"]).
|
135
|
+
expect(run_command_successfully(["compile", "-f", "wrong"])).to eq(false)
|
136
136
|
end
|
137
137
|
|
138
138
|
it "[compile] should compile a single source file" do
|
@@ -140,14 +140,13 @@ describe "glyph" do
|
|
140
140
|
Dir.chdir Glyph::PROJECT
|
141
141
|
file_copy "#{Glyph::PROJECT}/../files/article.glyph", "#{Glyph::PROJECT}/article.glyph"
|
142
142
|
file_copy "#{Glyph::PROJECT}/../files/ligature.jpg", "#{Glyph::PROJECT}/ligature.jpg"
|
143
|
-
run_command_successfully(["compile", "article.glyph"]).
|
144
|
-
Pathname.new('article.html').exist
|
145
|
-
compact_html(file_load('article.html')).
|
146
|
-
<?xml version="1.0"?>
|
143
|
+
expect(run_command_successfully(["compile", "article.glyph"])).to eq(true)
|
144
|
+
expect(Pathname.new('article.html').exist?).to eq(true)
|
145
|
+
expect(compact_html(file_load('article.html'))).to eq(compact_html(%{
|
147
146
|
<div class="section">
|
148
|
-
|
147
|
+
改善 Test -- Test Snippet
|
149
148
|
</div>
|
150
|
-
})
|
149
|
+
}))
|
151
150
|
(Glyph::PROJECT/'article.html').unlink
|
152
151
|
Glyph['document.output'] = 'pdf'
|
153
152
|
src = Glyph::PROJECT/'article.html'
|
@@ -155,9 +154,9 @@ describe "glyph" do
|
|
155
154
|
Glyph.enable 'generate:html'
|
156
155
|
Glyph.enable 'generate:pdf'
|
157
156
|
Glyph.enable 'generate:pdf_through_html'
|
158
|
-
run_command_successfully(["compile", "article.glyph"]).
|
159
|
-
src.exist
|
160
|
-
out.exist
|
157
|
+
expect(run_command_successfully(["compile", "article.glyph"])).to eq(true)
|
158
|
+
expect(src.exist?).to eq(true)
|
159
|
+
expect(out.exist?).to eq(true)
|
161
160
|
out.unlink
|
162
161
|
Glyph.lite_mode = false
|
163
162
|
end
|
@@ -167,9 +166,9 @@ describe "glyph" do
|
|
167
166
|
Dir.chdir Glyph::PROJECT
|
168
167
|
file_copy "#{Glyph::PROJECT}/../files/article.glyph", "#{Glyph::PROJECT}/article.glyph"
|
169
168
|
file_copy "#{Glyph::PROJECT}/../files/ligature.jpg", "#{Glyph::PROJECT}/ligature.jpg"
|
170
|
-
run_command_successfully(["compile", "article.glyph", "out/article.htm"]).
|
169
|
+
expect(run_command_successfully(["compile", "article.glyph", "out/article.htm"])).to eq(true)
|
171
170
|
Glyph.lite_mode = false
|
172
|
-
Pathname.new('out/article.htm').exist
|
171
|
+
expect(Pathname.new('out/article.htm').exist?).to eq(true)
|
173
172
|
end
|
174
173
|
|
175
174
|
it "[compile] should finalize the document in case of errors in included files" do
|
@@ -180,8 +179,8 @@ describe "glyph" do
|
|
180
179
|
err = "Document cannot be finalized due to previous errors"
|
181
180
|
res = run_command(["compile"])
|
182
181
|
out = file_load Glyph::PROJECT/'output/html/test_project.html'
|
183
|
-
compact_html(out).
|
184
|
-
res.match("error: #{err}").
|
182
|
+
expect(compact_html(out)).to eq(%{<div class="section"><h2 id="h_1" class="toc">Test</h2></div>})
|
183
|
+
expect(res.match("error: #{err}")).to eq(nil)
|
185
184
|
end
|
186
185
|
|
187
186
|
it "[outline] should display the document outline" do
|
@@ -199,25 +198,25 @@ test_project - Outline
|
|
199
198
|
i_id = "[#h_2]"
|
200
199
|
m_id = "[#md]"
|
201
200
|
file_write Glyph::PROJECT/'document.glyph', "document[#{file_load(Glyph::PROJECT/'document.glyph')}]"
|
202
|
-
run_command(["-d", "outline"]).
|
201
|
+
expect(run_command(["-d", "outline"])).to eq(%{#{start}
|
203
202
|
#{c_title}
|
204
203
|
#{i_title}
|
205
204
|
#{m_title}
|
206
|
-
}
|
205
|
+
})
|
207
206
|
reset_quiet
|
208
|
-
run_command(["outline", "-l", "1"]).
|
207
|
+
expect(run_command(["outline", "-l", "1"])).to eq(%{#{start}
|
209
208
|
#{c_title}
|
210
209
|
#{m_title}
|
211
|
-
}
|
210
|
+
})
|
212
211
|
reset_quiet
|
213
|
-
run_command(["outline", "-ift"]).
|
212
|
+
expect(run_command(["outline", "-ift"])).to eq(%{#{start}
|
214
213
|
#{c_file}
|
215
214
|
#{c_title}#{c_id}
|
216
215
|
#{i_file}
|
217
216
|
#{i_title}#{i_id}
|
218
217
|
#{m_file}
|
219
218
|
#{m_title}#{m_id}
|
220
|
-
}
|
219
|
+
})
|
221
220
|
end
|
222
221
|
|
223
222
|
it "[stats] should display project statistics" do
|
@@ -225,14 +224,14 @@ test_project - Outline
|
|
225
224
|
create_project
|
226
225
|
out = run_command(["stats", "-ms"])
|
227
226
|
total_macros = (Glyph::MACROS.keys - Glyph::ALIASES[:by_alias].keys).uniq.length
|
228
|
-
out.
|
227
|
+
expect(out).to match "-- Total Macro Definitions: #{total_macros}"
|
229
228
|
out = run_command(["stats"])
|
230
|
-
out.
|
231
|
-
out.
|
229
|
+
expect(out).to match "-- Total Macro Definitions: #{total_macros}"
|
230
|
+
expect(out).to match "-- Total Unreferenced Bookmarks: 3"
|
232
231
|
out = run_command(["stats", "-lb", "--bookmark=md"])
|
233
|
-
out.
|
234
|
-
out.
|
235
|
-
out.
|
232
|
+
expect(out).to match "-- Unreferenced Bookmarks: h_1, h_2, md"
|
233
|
+
expect(out).to match "-- Defined in: text/a/b/c/markdown.markdown"
|
234
|
+
expect(out).not_to match "-- Total Macro Definitions: 19"
|
236
235
|
end
|
237
236
|
|
238
237
|
end
|
data/spec/lib/config_spec.rb
CHANGED
@@ -19,34 +19,34 @@ describe Glyph::Config do
|
|
19
19
|
|
20
20
|
it "should load a YAML configuration file" do
|
21
21
|
@write_config_file.call @invalid
|
22
|
-
|
22
|
+
expect { @cfg.read }.to raise_error
|
23
23
|
@write_config_file.call @valid
|
24
|
-
@cfg.read.
|
24
|
+
expect(@cfg.read).to eq({:test => true})
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should get and set configuration data through dot notation" do
|
28
28
|
@write_config_file.call @valid
|
29
29
|
@cfg.read
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@cfg.get("test2.value").
|
34
|
-
|
35
|
-
@cfg.get("test2.value").
|
36
|
-
@cfg.get("test2.value2").
|
37
|
-
@cfg.to_hash.
|
30
|
+
expect { @cfg.set :test, false }.not_to raise_error
|
31
|
+
expect { @cfg.set "test.wrong", true}.to raise_error
|
32
|
+
expect { @cfg.set "test2.value", true}.not_to raise_error
|
33
|
+
expect(@cfg.get("test2.value")).to eq(true)
|
34
|
+
expect { @cfg.set "test2.value", "false"}.not_to raise_error
|
35
|
+
expect(@cfg.get("test2.value")).to eq(false)
|
36
|
+
expect(@cfg.get("test2.value2")).to eq(nil)
|
37
|
+
expect(@cfg.to_hash).to eq({:test => false, :test2 => {:value => false}})
|
38
38
|
end
|
39
39
|
|
40
40
|
it "can be resetted with a Hash, if resettable" do
|
41
|
-
|
41
|
+
expect { @cfg.reset }.to raise_error
|
42
42
|
cfg2 = Glyph::Config.new :resettable => true
|
43
43
|
cfg2.reset :test => "reset!"
|
44
|
-
cfg2.to_hash.
|
44
|
+
expect(cfg2.to_hash).to eq({:test => "reset!"})
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should be set to an empty Hash by default" do
|
48
48
|
cfg2 = Glyph::Config.new
|
49
|
-
cfg2.to_hash.
|
49
|
+
expect(cfg2.to_hash).to eq({})
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should write a YAML configuration file" do
|
@@ -58,7 +58,7 @@ describe Glyph::Config do
|
|
58
58
|
@cfg.write
|
59
59
|
cfg2 = Glyph::Config.new :file => @config_path
|
60
60
|
cfg2.read
|
61
|
-
cfg2.to_hash.
|
61
|
+
expect(cfg2.to_hash).to eq(@cfg.to_hash)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should merge with another Config without data loss" do
|
@@ -70,9 +70,9 @@ describe Glyph::Config do
|
|
70
70
|
cfg2 = Glyph::Config.new :file => @config_path
|
71
71
|
@cfg.update cfg2
|
72
72
|
updated = {:a =>1, :b => {:b1 => 1111, :b2 => 2222, :b3 => {:b11 => 1, :b12 =>2222}, :b4 => 4}, :c=> 3}
|
73
|
-
@cfg.to_hash.
|
73
|
+
expect(@cfg.to_hash).to eq(updated)
|
74
74
|
hash1.merge! hash2
|
75
|
-
hash1.
|
75
|
+
expect(hash1).to eq({:a =>1, :b => {:b1 => 1111, :b2 => 2222, :b3 => {:b12 =>2222}}, :c=> 3})
|
76
76
|
end
|
77
77
|
|
78
78
|
|
data/spec/lib/document_spec.rb
CHANGED
@@ -16,30 +16,30 @@ describe Glyph::Document do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should expose document data" do
|
19
|
-
@doc.bookmarks.
|
20
|
-
@doc.headers.
|
21
|
-
@doc.styles.
|
22
|
-
@doc.placeholders.
|
23
|
-
@doc.new
|
19
|
+
expect(@doc.bookmarks).to eq({})
|
20
|
+
expect(@doc.headers).to eq({})
|
21
|
+
expect(@doc.styles).to eq([])
|
22
|
+
expect(@doc.placeholders).to eq({})
|
23
|
+
expect(@doc.new?).to eq(true)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should store bookmarks" do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@doc.bookmarks.length.
|
31
|
-
@doc.bookmarks[:test].
|
27
|
+
expect { @doc.bookmark(:id => "test", :title => "Test Bookmark #1", :file => 'test.glyph')}.not_to raise_error
|
28
|
+
expect { @doc.bookmark(:id => :test, :title => "Test Bookmark #1", :file => 'test.glyph')}.to raise_error
|
29
|
+
expect { @doc.bookmark(:id => :test, :title => "Test Bookmark #2", :file => 'test2.glyph')}.to raise_error
|
30
|
+
expect(@doc.bookmarks.length).to eq(1)
|
31
|
+
expect(@doc.bookmarks[:test]).to eq(Glyph::Bookmark.new(:id => :test, :title => "Test Bookmark #1", :file => "test.glyph"))
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should store placeholders" do
|
35
35
|
p = lambda { "test" }
|
36
|
-
|
37
|
-
@doc.placeholders["‡‡‡‡‡PLACEHOLDER¤1‡‡‡‡‡".to_sym].
|
36
|
+
expect { @doc.placeholder &p }.not_to raise_error
|
37
|
+
expect(@doc.placeholders["‡‡‡‡‡PLACEHOLDER¤1‡‡‡‡‡".to_sym]).to eq(p)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should store styles" do
|
41
|
-
|
42
|
-
@doc.styles.include?(Pathname.new('test.css')).
|
41
|
+
expect {@doc.style "test.css"}.not_to raise_error
|
42
|
+
expect(@doc.styles.include?(Pathname.new('test.css'))).to eq(true)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "can inherit data from another document" do
|
@@ -50,33 +50,33 @@ describe Glyph::Document do
|
|
50
50
|
@doc.header :id => :test3, :title => "Test #3", :level => 3, :file => "test.glyph"
|
51
51
|
@doc.toc[:contents] = "TOC goes here..."
|
52
52
|
doc2 = create_doc @tree
|
53
|
-
doc2.bookmarks.length.
|
54
|
-
doc2.placeholders.length.
|
53
|
+
expect(doc2.bookmarks.length).to eq(0)
|
54
|
+
expect(doc2.placeholders.length).to eq(0)
|
55
55
|
doc2.bookmark :id => :test4, :title => "Test #4", :file => "test.glyph"
|
56
56
|
doc2.inherit_from @doc
|
57
|
-
doc2.bookmarks.length.
|
58
|
-
doc2.placeholders.length.
|
59
|
-
doc2.headers.length.
|
60
|
-
doc2.styles.length.
|
57
|
+
expect(doc2.bookmarks.length).to eq(3)
|
58
|
+
expect(doc2.placeholders.length).to eq(1)
|
59
|
+
expect(doc2.headers.length).to eq(1)
|
60
|
+
expect(doc2.styles.length).to eq(1)
|
61
61
|
doc2.toc[:contents] = "TOC goes here..."
|
62
|
-
doc2.bookmarks[0].
|
62
|
+
expect(doc2.bookmarks[0]).not_to eq(Glyph::Bookmark.new(:id => :test4, :title => "Test #4", :file => "test.glyph"))
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should analyze the syntax tree and finalize the document" do
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
@doc.analyzed
|
71
|
-
|
72
|
-
|
73
|
-
@doc.output.
|
66
|
+
expect { @doc.output }.to raise_error
|
67
|
+
expect { @doc.finalize }.to raise_error
|
68
|
+
expect { @doc.analyze }.not_to raise_error
|
69
|
+
expect { @doc.analyze }.to raise_error
|
70
|
+
expect(@doc.analyzed?).to eq(true)
|
71
|
+
expect { @doc.output }.to raise_error
|
72
|
+
expect { @doc.finalize }.not_to raise_error
|
73
|
+
expect(@doc.output).to eq("Test: Test: Test: Test|]...")
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should expose document structure" do
|
77
|
-
|
77
|
+
expect { @doc.structure }.to raise_error
|
78
78
|
@doc.analyze
|
79
|
-
@doc.structure.is_a?(Node).
|
79
|
+
expect(@doc.structure.is_a?(Node)).to eq(true)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should substitute placeholders when finalizing" do
|
@@ -105,7 +105,7 @@ describe Glyph::Document do
|
|
105
105
|
doc = create_doc tree
|
106
106
|
doc.analyze
|
107
107
|
doc.finalize
|
108
|
-
doc.output.gsub(/\n|\t/, '')[0..14].
|
108
|
+
expect(doc.output.gsub(/\n|\t/, '')[0..14]).to eq("Total: 4 tests.")
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should substitute escaped pipes only when finalizing the document" do
|
@@ -119,7 +119,7 @@ describe Glyph::Document do
|
|
119
119
|
doc = create_doc tree
|
120
120
|
doc.analyze
|
121
121
|
doc.finalize
|
122
|
-
doc.output.
|
122
|
+
expect(doc.output).to eq(result)
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should store the Table of Contents" do
|
@@ -145,7 +145,7 @@ describe Glyph::Document do
|
|
145
145
|
doc = create_doc tree
|
146
146
|
doc.analyze
|
147
147
|
doc.finalize
|
148
|
-
doc.toc[:contents].match(%{<div class="contents">}).blank
|
148
|
+
expect(doc.toc[:contents].match(%{<div class="contents">}).blank?).to eq(false)
|
149
149
|
reset_quiet
|
150
150
|
end
|
151
151
|
|
@@ -155,7 +155,7 @@ describe Glyph::Document do
|
|
155
155
|
Glyph.run! "load:all"
|
156
156
|
doc = create_doc create_tree("testing ##[frag1|fragments!] -- ##[frag2|another fragment]")
|
157
157
|
doc.analyze
|
158
|
-
doc.fragments.
|
158
|
+
expect(doc.fragments).to eq({:frag1 => "fragments!", :frag2 => "another fragment"})
|
159
159
|
reset_quiet
|
160
160
|
end
|
161
161
|
|