glyph 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/AUTHORS.textile +8 -7
- data/CHANGELOG.textile +89 -8
- data/LICENSE.textile +1 -2
- data/README.textile +89 -61
- data/Rakefile +12 -10
- data/VERSION +1 -1
- data/benchmark.rb +1 -1
- data/book/config.yml +18 -4
- data/book/document.glyph +269 -45
- data/book/images/glyph/commands_tasks.png +0 -0
- data/book/images/{document_generation.png → glyph/document_generation.png} +0 -0
- data/book/images/glyph/glyph.eps +123 -0
- data/book/images/glyph/glyph.png +0 -0
- data/book/images/glyph/glyph.svg +29 -0
- data/book/lib/commands/commands.rb +11 -0
- data/book/lib/layouts/bookindex.glyph +127 -0
- data/book/lib/layouts/bookpage.glyph +129 -0
- data/book/lib/layouts/project.glyph +26 -0
- data/book/lib/macros/reference.rb +27 -7
- data/book/lib/tasks/tasks.rake +52 -0
- data/book/snippets.yml +1 -1
- data/book/text/{acknowledgement.glyph → acknowledgements.glyph} +4 -2
- data/book/text/changelog.glyph +29 -3
- data/book/text/compiling/compiling.glyph +44 -20
- data/book/text/compiling/lite_mode.glyph +0 -4
- data/book/text/compiling/programmatic_usage.glyph +1 -5
- data/book/text/config/document.glyph +35 -0
- data/book/text/config/filters.glyph +28 -0
- data/book/text/config/options.glyph +25 -0
- data/book/text/config/output.glyph +83 -0
- data/book/text/extending/bookmarks_headers.glyph +0 -5
- data/book/text/extending/command.glyph +56 -0
- data/book/text/extending/commands_tasks.glyph +39 -0
- data/book/text/extending/further_reading.glyph +0 -3
- data/book/text/extending/internals.glyph +3 -5
- data/book/text/extending/interpreting.glyph +0 -4
- data/book/text/extending/layouts.glyph +68 -0
- data/book/text/extending/macro_def.glyph +0 -5
- data/book/text/extending/output_format.glyph +78 -0
- data/book/text/extending/params_attrs.glyph +0 -3
- data/book/text/extending/placeholders.glyph +0 -4
- data/book/text/extending/task.glyph +46 -0
- data/book/text/extending/validators.glyph +5 -6
- data/book/text/getting_started/configuration.glyph +1 -5
- data/book/text/getting_started/create_project.glyph +1 -5
- data/book/text/getting_started/structure.glyph +0 -4
- data/book/text/introduction.glyph +100 -75
- data/book/text/license.glyph +1 -2
- data/book/text/macros/macros_block.glyph +8 -4
- data/book/text/macros/macros_core.glyph +0 -3
- data/book/text/macros/macros_filters.glyph +2 -7
- data/book/text/macros/macros_inline.glyph +0 -4
- data/book/text/macros/macros_structure.glyph +0 -4
- data/book/text/ref_commands.glyph +29 -7
- data/book/text/stats/bookmarks.glyph +49 -0
- data/book/text/stats/links.glyph +90 -0
- data/book/text/stats/macros.glyph +73 -0
- data/book/text/stats/snippets.glyph +50 -0
- data/book/text/stats/stats.glyph +79 -0
- data/book/text/text_editing/attribute_intro.glyph +22 -0
- data/book/text/text_editing/code.glyph +0 -5
- data/book/text/text_editing/conditionals.glyph +0 -4
- data/book/text/text_editing/esc_quot.glyph +64 -0
- data/book/text/text_editing/evaluation.glyph +0 -3
- data/book/text/text_editing/glyph_files.glyph +0 -3
- data/book/text/text_editing/images.glyph +0 -5
- data/book/text/text_editing/inclusions.glyph +0 -4
- data/book/text/text_editing/links.glyph +2 -7
- data/book/text/text_editing/macro_intro.glyph +1 -98
- data/book/text/text_editing/raw_html.glyph +0 -87
- data/book/text/text_editing/section_aliases.glyph +28 -0
- data/book/text/text_editing/sections.glyph +1 -32
- data/book/text/text_editing/stylesheets.glyph +3 -5
- data/book/text/text_editing/topics.glyph +33 -0
- data/book/text/text_editing/xml_fallback.glyph +73 -0
- data/book/text/troubleshooting/errors_command.glyph +0 -3
- data/book/text/troubleshooting/errors_generic.glyph +21 -6
- data/book/text/troubleshooting/errors_macro.glyph +11 -8
- data/book/text/troubleshooting/errors_parser.glyph +0 -3
- data/config.yml +60 -25
- data/glyph.gemspec +90 -36
- data/layouts/web/index.glyph +16 -0
- data/layouts/web/topic.glyph +15 -0
- data/layouts/web5/index.glyph +16 -0
- data/layouts/web5/topic.glyph +17 -0
- data/lib/glyph.rb +36 -49
- data/lib/glyph/analyzer.rb +253 -0
- data/lib/glyph/bookmark.rb +92 -0
- data/lib/glyph/commands.rb +9 -221
- data/lib/glyph/commands/add.rb +8 -0
- data/lib/glyph/commands/compile.rb +93 -0
- data/lib/glyph/commands/config.rb +38 -0
- data/lib/glyph/commands/init.rb +6 -0
- data/lib/glyph/commands/outline.rb +45 -0
- data/lib/glyph/commands/stats.rb +48 -0
- data/lib/glyph/commands/todo.rb +29 -0
- data/lib/glyph/config.rb +2 -0
- data/lib/glyph/document.rb +61 -30
- data/lib/glyph/interpreter.rb +2 -2
- data/lib/glyph/macro.rb +14 -5
- data/lib/glyph/macro_helpers.rb +280 -0
- data/lib/glyph/macro_validators.rb +37 -2
- data/lib/glyph/reporter.rb +182 -0
- data/lib/glyph/syntax_node.rb +37 -10
- data/lib/glyph/system_extensions.rb +8 -45
- data/lib/glyph/utils.rb +148 -0
- data/macros/core.rb +10 -15
- data/macros/filters.rb +4 -5
- data/macros/html/block.rb +46 -30
- data/macros/html/inline.rb +9 -35
- data/macros/html/structure.rb +59 -72
- data/macros/html5/block.rb +69 -0
- data/macros/html5/inline.rb +24 -0
- data/macros/html5/structure.rb +139 -0
- data/macros/xml.rb +1 -1
- data/spec/files/custom_command.rb +6 -0
- data/spec/files/custom_tasks.rake +6 -0
- data/spec/files/document_for_stats.glyph +12 -0
- data/spec/files/references.glyph +4 -0
- data/spec/files/web1.glyph +11 -0
- data/spec/files/web2.glyph +10 -0
- data/spec/files/web_doc.glyph +23 -0
- data/spec/lib/analyzer_spec.rb +137 -0
- data/spec/lib/bookmark_spec.rb +64 -0
- data/spec/lib/commands_spec.rb +30 -5
- data/spec/lib/document_spec.rb +49 -9
- data/spec/lib/glyph_spec.rb +21 -1
- data/spec/lib/macro_spec.rb +6 -6
- data/spec/lib/macro_validators_spec.rb +24 -0
- data/spec/lib/reporter_spec.rb +132 -0
- data/spec/macros/core_spec.rb +2 -3
- data/spec/macros/filters_spec.rb +2 -2
- data/spec/macros/html5_spec.rb +101 -0
- data/spec/macros/macros_spec.rb +16 -6
- data/spec/macros/web5_spec.rb +32 -0
- data/spec/macros/web_spec.rb +59 -0
- data/spec/macros/xml_spec.rb +1 -1
- data/spec/spec_helper.rb +24 -4
- data/spec/tasks/generate_spec.rb +54 -0
- data/spec/tasks/load_spec.rb +29 -3
- data/spec/tasks/project_spec.rb +21 -3
- data/styles/default.css +40 -4
- data/styles/pagination.css +59 -41
- data/tasks/generate.rake +110 -31
- data/tasks/load.rake +39 -7
- data/tasks/project.rake +9 -7
- metadata +115 -34
- data/book/images/glyph.png +0 -0
- data/book/images/glyph.svg +0 -351
- data/book/output/html/glyph.html +0 -4482
- data/book/output/html/images/document_generation.png +0 -0
- data/book/output/html/images/glyph.png +0 -0
- data/book/output/html/images/glyph.svg +0 -351
- data/book/output/pdf/glyph.pdf +4 -10254
- data/book/script/authors +0 -1
- data/book/script/changelog +0 -1
- data/book/script/license +0 -1
- data/book/script/readme +0 -1
- data/book/text/ref_config.glyph +0 -100
- data/book/text/ref_macros.glyph +0 -6
- data/book/text/troubleshooting/errors_intro.glyph +0 -3
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
5
|
+
|
6
|
+
describe Glyph::Bookmark do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@b = Glyph::Bookmark.new :id => :test, :file => "test.glyph"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be initialized with at least an id" do
|
13
|
+
lambda { Glyph::Bookmark.new }.should raise_error
|
14
|
+
lambda { Glyph::Bookmark.new({:id => :test}) }.should_not raise_error
|
15
|
+
lambda { Glyph::Bookmark.new({:file => "test"}) }.should raise_error
|
16
|
+
lambda { Glyph::Bookmark.new({:id => "test", :file => "test.glyph"}) }.should_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it "shiuld expose title, code and file" do
|
20
|
+
@b.file.should == "test.glyph"
|
21
|
+
@b.code.should == :test
|
22
|
+
@b.title.should == nil
|
23
|
+
Glyph::Bookmark.new(:id => :test2, :title => "Test 2").title.should == "Test 2"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should convert to a string" do
|
27
|
+
@b.code.to_s == @b.to_s
|
28
|
+
"#{@b}".should == @b.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should format the link for a single output file" do
|
32
|
+
# Link within the same file
|
33
|
+
@b.link.should == "#test"
|
34
|
+
# Link to a different file file
|
35
|
+
@b.link('intro.glyph').should == "#test"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should format the link for multiple output files" do
|
39
|
+
out = Glyph['document.output']
|
40
|
+
Glyph['document.output'] = 'web'
|
41
|
+
# Link within the same file
|
42
|
+
@b.link("test.glyph").should == "#test"
|
43
|
+
# Link to a different file file
|
44
|
+
@b.link("intro.glyph").should == "/test.html#test"
|
45
|
+
# Test that base directory is added correctly
|
46
|
+
Glyph["output.#{Glyph['document.output']}.base"] = ""
|
47
|
+
@b.link("intro.glyph").should == "test.html#test"
|
48
|
+
@b.link("test.glyph").should == "#test"
|
49
|
+
Glyph['document.output'] = out
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should check ID validity" do
|
53
|
+
lambda { Glyph::Bookmark.new :id => "#test$", :file => "test.glyph"}.should raise_error(RuntimeError, "Invalid bookmark ID: #test$")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should check bookmark equality" do
|
57
|
+
@b.should == Glyph::Bookmark.new(:id => :test, :file => 'test.glyph')
|
58
|
+
@b.should == Glyph::Bookmark.new(:id => :test, :file => "test.glyph")
|
59
|
+
@b.should == Glyph::Bookmark.new(:id => :test, :file => 'test.glyph', :level => 2)
|
60
|
+
@b.should_not == Glyph::Bookmark.new(:id => :test1, :file => 'test.glyph')
|
61
|
+
@b.should_not == Glyph::Bookmark.new(:id => :test, :file => 'test1.glyph')
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/spec/lib/commands_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe "glyph" do
|
|
23
23
|
it "[config] should read configuration settings" do
|
24
24
|
create_project
|
25
25
|
run_command_successfully(["config", "-g"]).should == false
|
26
|
-
run_command(["config", "
|
26
|
+
run_command(["config", "document.html.filter_target"]).match(/html/m).should_not == nil
|
27
27
|
end
|
28
28
|
|
29
29
|
it "[config] should write configuration settings" do
|
@@ -149,9 +149,18 @@ describe "glyph" do
|
|
149
149
|
Glyph.enable 'generate:html'
|
150
150
|
(Glyph::PROJECT/'article.html').unlink
|
151
151
|
Glyph['document.output'] = 'pdf'
|
152
|
-
|
153
|
-
|
154
|
-
|
152
|
+
src = Glyph::PROJECT/'article.html'
|
153
|
+
out = Glyph::PROJECT/'article.pdf'
|
154
|
+
generate_pdf = lambda do |gen|
|
155
|
+
Glyph.enable 'generate:pdf'
|
156
|
+
Glyph['output.pdf.generator'] = gen
|
157
|
+
run_command_successfully(["compile", "article.glyph"]).should == true
|
158
|
+
src.exist?.should == true
|
159
|
+
out.exist?.should == true
|
160
|
+
out.unlink
|
161
|
+
end
|
162
|
+
generate_pdf.call 'prince'
|
163
|
+
generate_pdf.call 'wkhtmltopdf'
|
155
164
|
Glyph.lite_mode = false
|
156
165
|
end
|
157
166
|
|
@@ -197,7 +206,7 @@ test_project - Outline
|
|
197
206
|
i_id = "[#h_2]"
|
198
207
|
m_id = "[#md]"
|
199
208
|
file_write Glyph::PROJECT/'document.glyph', "document[#{file_load(Glyph::PROJECT/'document.glyph')}]"
|
200
|
-
run_command(["outline"]).should == %{#{start}
|
209
|
+
run_command(["-d", "outline"]).should == %{#{start}
|
201
210
|
#{c_title}
|
202
211
|
#{i_title}
|
203
212
|
#{m_title}
|
@@ -218,4 +227,20 @@ test_project - Outline
|
|
218
227
|
}
|
219
228
|
end
|
220
229
|
|
230
|
+
it "[stats] should display project statistics" do
|
231
|
+
reset_quiet
|
232
|
+
create_project
|
233
|
+
out = run_command(["stats", "-ms"])
|
234
|
+
out.should match "-- Total Macro Definitions: 44"
|
235
|
+
out.should match "-- Unused Snippets: test"
|
236
|
+
out = run_command(["stats"])
|
237
|
+
out.should match "-- Total Macro Definitions: 44"
|
238
|
+
out.should_not match "-- Unused Snippets: test"
|
239
|
+
out.should match "-- Total Unreferenced Bookmarks: 3"
|
240
|
+
out = run_command(["stats", "-lb", "--bookmark=md"])
|
241
|
+
out.should match "-- Unreferenced Bookmarks: h_1, h_2, md"
|
242
|
+
out.should match "-- Defined in: text/a/b/c/markdown.markdown"
|
243
|
+
out.should_not match "-- Total Macro Definitions: 19"
|
244
|
+
end
|
245
|
+
|
221
246
|
end
|
data/spec/lib/document_spec.rb
CHANGED
@@ -17,15 +17,18 @@ describe Glyph::Document do
|
|
17
17
|
|
18
18
|
it "should expose document data" do
|
19
19
|
@doc.bookmarks.should == {}
|
20
|
+
@doc.headers.should == {}
|
21
|
+
@doc.styles.should == []
|
20
22
|
@doc.placeholders.should == {}
|
21
23
|
@doc.new?.should == true
|
22
24
|
end
|
23
25
|
|
24
26
|
it "should store bookmarks" do
|
25
|
-
lambda { @doc.bookmark(:id => "test", :title => "Test Bookmark #1")}.should_not raise_error
|
26
|
-
lambda { @doc.bookmark(:id => :test, :title => "Test Bookmark #
|
27
|
+
lambda { @doc.bookmark(:id => "test", :title => "Test Bookmark #1", :file => 'test.glyph')}.should_not raise_error
|
28
|
+
lambda { @doc.bookmark(:id => :test, :title => "Test Bookmark #1", :file => 'test.glyph')}.should raise_error
|
29
|
+
lambda { @doc.bookmark(:id => :test, :title => "Test Bookmark #2", :file => 'test2.glyph')}.should raise_error
|
27
30
|
@doc.bookmarks.length.should == 1
|
28
|
-
@doc.bookmarks[:test].should ==
|
31
|
+
@doc.bookmarks[:test].should == Glyph::Bookmark.new(:id => :test, :title => "Test Bookmark #1", :file => "test.glyph")
|
29
32
|
end
|
30
33
|
|
31
34
|
it "should store placeholders" do
|
@@ -34,20 +37,29 @@ describe Glyph::Document do
|
|
34
37
|
@doc.placeholders["‡‡‡‡‡PLACEHOLDER¤1‡‡‡‡‡".to_sym].should == p
|
35
38
|
end
|
36
39
|
|
40
|
+
it "should store styles" do
|
41
|
+
lambda {@doc.style "test.css"}.should_not raise_error
|
42
|
+
@doc.styles.include?(Pathname.new('test.css')).should == true
|
43
|
+
end
|
44
|
+
|
37
45
|
it "can inherit data from another document" do
|
38
|
-
@doc.bookmark :id => :test1, :title => "Test #1"
|
39
|
-
@doc.bookmark :id => :test2, :title => "Test #2"
|
46
|
+
@doc.bookmark :id => :test1, :title => "Test #1", :file => "test.glyph"
|
47
|
+
@doc.bookmark :id => :test2, :title => "Test #2", :file => "test.glyph"
|
40
48
|
@doc.placeholder { "test" }
|
41
|
-
@doc.
|
49
|
+
@doc.style "test.css"
|
50
|
+
@doc.header :id => :test3, :title => "Test #3", :level => 3, :file => "test.glyph"
|
51
|
+
@doc.toc[:contents] = "TOC goes here..."
|
42
52
|
doc2 = create_doc @tree
|
43
53
|
doc2.bookmarks.length.should == 0
|
44
54
|
doc2.placeholders.length.should == 0
|
45
|
-
doc2.bookmark :id => :test4, :title => "Test #4"
|
55
|
+
doc2.bookmark :id => :test4, :title => "Test #4", :file => "test.glyph"
|
46
56
|
doc2.inherit_from @doc
|
47
|
-
doc2.bookmarks.length.should ==
|
57
|
+
doc2.bookmarks.length.should == 3
|
48
58
|
doc2.placeholders.length.should == 1
|
49
59
|
doc2.headers.length.should == 1
|
50
|
-
doc2.
|
60
|
+
doc2.styles.length.should == 1
|
61
|
+
doc2.toc[:contents] = "TOC goes here..."
|
62
|
+
doc2.bookmarks[0].should_not == Glyph::Bookmark.new(:id => :test4, :title => "Test #4", :file => "test.glyph")
|
51
63
|
end
|
52
64
|
|
53
65
|
it "should analyze the syntax tree and finalize the document" do
|
@@ -109,5 +121,33 @@ describe Glyph::Document do
|
|
109
121
|
doc.finalize
|
110
122
|
doc.output.should == result
|
111
123
|
end
|
124
|
+
|
125
|
+
it "should store the Table of Contents" do
|
126
|
+
delete_project
|
127
|
+
create_project
|
128
|
+
Glyph.run! "load:all"
|
129
|
+
text = %{
|
130
|
+
document[
|
131
|
+
body[
|
132
|
+
toc[]
|
133
|
+
section[
|
134
|
+
@title[test 1]
|
135
|
+
...
|
136
|
+
section[
|
137
|
+
@title[test 2]
|
138
|
+
...
|
139
|
+
]
|
140
|
+
]
|
141
|
+
]
|
142
|
+
]
|
143
|
+
}
|
144
|
+
tree = create_tree text
|
145
|
+
doc = create_doc tree
|
146
|
+
doc.analyze
|
147
|
+
doc.finalize
|
148
|
+
doc.toc[:contents].match(%{<div class="contents">}).blank?.should == false
|
149
|
+
reset_quiet
|
150
|
+
end
|
151
|
+
|
112
152
|
end
|
113
153
|
|
data/spec/lib/glyph_spec.rb
CHANGED
@@ -39,7 +39,7 @@ describe Glyph do
|
|
39
39
|
lambda { Glyph.macro_alias("->" => :ref)}.should_not raise_error
|
40
40
|
Glyph::MACROS[:"->"].should == Glyph::MACROS[:ref]
|
41
41
|
Glyph.macro_alias :em => :ref
|
42
|
-
Glyph::MACROS[:em].
|
42
|
+
Glyph::MACROS[:em].should == Glyph::MACROS[:ref]
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should provide a filter method to convert raw text into HTML" do
|
@@ -73,4 +73,24 @@ describe Glyph do
|
|
73
73
|
Glyph.safe_mode = false
|
74
74
|
end
|
75
75
|
|
76
|
+
it "should rewrite macros using Glyph syntax" do
|
77
|
+
define_em_macro
|
78
|
+
Glyph.rewrite :test_rw_macro, %{em[{{0}} -- {{a}}]}
|
79
|
+
output_for("test_rw_macro[@a[!]?]").should == "<em>? -- !</em>"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should store alias information" do
|
83
|
+
delete_project_dir
|
84
|
+
create_project_dir
|
85
|
+
Glyph.run! 'project:create', Glyph::PROJECT
|
86
|
+
Glyph.run 'load:all'
|
87
|
+
Glyph::ALIASES[:by_def][:snippet].should == [:&]
|
88
|
+
Glyph::ALIASES[:by_alias][:"?"].should == :condition
|
89
|
+
Glyph.macro_aliases_for(:link).should == [:"=>"]
|
90
|
+
Glyph.macro_aliases_for(:"=>").should == nil
|
91
|
+
Glyph.macro_definition_for(:"=>").should == :link
|
92
|
+
Glyph.macro_definition_for(:link).should == nil
|
93
|
+
Glyph.macro_alias?(:"#").should == true
|
94
|
+
end
|
95
|
+
|
76
96
|
end
|
data/spec/lib/macro_spec.rb
CHANGED
@@ -44,17 +44,17 @@ describe Glyph::Macro do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should store and check bookmarks" do
|
47
|
-
h = { :id => "test2", :title => "Test 2" }
|
47
|
+
h = { :id => "test2", :title => "Test 2", :file => 'test.glyph' }
|
48
48
|
@macro.bookmark h
|
49
|
-
@doc.bookmark?(:test2).should == h
|
50
|
-
@macro.bookmark?(:test2).should == h
|
49
|
+
@doc.bookmark?(:test2).should == Glyph::Bookmark.new(h)
|
50
|
+
@macro.bookmark?(:test2).should == Glyph::Bookmark.new(h)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should store and check headers" do
|
54
|
-
h = { :level => 2, :id => "test3", :title => "Test 3" }
|
54
|
+
h = { :level => 2, :id => "test3", :title => "Test 3", :file => "test.glyph"}
|
55
55
|
@macro.header h
|
56
|
-
@doc.header?("test3").should == h
|
57
|
-
@macro.header?("test3").should == h
|
56
|
+
@doc.header?("test3").should == Glyph::Bookmark.new(h)
|
57
|
+
@macro.header?("test3").should == Glyph::Bookmark.new(h)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should store placeholders" do
|
@@ -51,5 +51,29 @@ describe Glyph::Macro::Validators do
|
|
51
51
|
output_for("test[test @.test[test]]").should == "<test>test</test>"
|
52
52
|
end
|
53
53
|
|
54
|
+
it "should validate required attributes" do
|
55
|
+
Glyph['document.output'] = 'web'
|
56
|
+
Glyph.run! 'load:macros'
|
57
|
+
lambda { output_for("contents[section[@src[test]]]") }.should raise_error(Glyph::MacroError, "Macro 'section' requires a 'title' attribute")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should validate if a macro is within another one" do
|
61
|
+
define_em_macro
|
62
|
+
Glyph.macro :within_m do
|
63
|
+
within :em
|
64
|
+
"---"
|
65
|
+
end
|
66
|
+
lambda { output_for("within_m[test]") }.should raise_error(Glyph::MacroError, "Macro 'within_m' must be within a 'em' macro")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should validate if a macro is not within another one" do
|
70
|
+
define_em_macro
|
71
|
+
Glyph.macro :within_m do
|
72
|
+
not_within :em
|
73
|
+
"---"
|
74
|
+
end
|
75
|
+
lambda { output_for("em[within_m[test]]") }.should raise_error(Glyph::MacroError, "Macro 'within_m' must not be within a 'em' macro")
|
76
|
+
end
|
77
|
+
|
54
78
|
end
|
55
79
|
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
5
|
+
|
6
|
+
describe Glyph::Reporter do
|
7
|
+
|
8
|
+
before do
|
9
|
+
delete_project
|
10
|
+
reset_quiet
|
11
|
+
create_project_dir
|
12
|
+
create_project
|
13
|
+
Glyph.file_copy Glyph::SPEC_DIR/'files/document_for_stats.glyph', Glyph::PROJECT/'document.glyph'
|
14
|
+
Glyph.file_copy Glyph::SPEC_DIR/'files/references.glyph', Glyph::PROJECT/'text/references.glyph'
|
15
|
+
Glyph.run! 'generate:document'
|
16
|
+
@a = Glyph::Analyzer.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def stats(name, *args)
|
20
|
+
@a.stats_for(name, *args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def rep
|
24
|
+
@r = Glyph::Reporter.new(@a.stats)
|
25
|
+
end
|
26
|
+
|
27
|
+
after do
|
28
|
+
delete_project_dir
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be initialized with stats" do
|
32
|
+
stats :macros
|
33
|
+
lambda { rep }.should_not raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should display macro stats" do
|
37
|
+
stats :macros
|
38
|
+
out = stdout_for { rep.display }
|
39
|
+
out.should match "Total Macro Instances: 20"
|
40
|
+
out.should match "-- Used Macro Definitions:"
|
41
|
+
@r.detailed = false
|
42
|
+
out = stdout_for { @r.display }
|
43
|
+
out.should_not match "-- Used Macro Definitions:"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should display stats for a single macro" do
|
47
|
+
stats :macro, :section
|
48
|
+
out = stdout_for { rep.display }
|
49
|
+
out.should match "text/a/b/c/markdown.markdown \\(1\\)"
|
50
|
+
out.should match "-- Total Instances: 4"
|
51
|
+
@r.detailed = false
|
52
|
+
out = stdout_for { @r.display }
|
53
|
+
out.should_not match "text/a/b/c/markdown.markdown \\(1\\)"
|
54
|
+
stats :macro, :"=>"
|
55
|
+
out = stdout_for { rep.display }
|
56
|
+
out.should match "alias for: link"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should display bookmark stats" do
|
60
|
+
stats :bookmarks
|
61
|
+
out = stdout_for { rep.display }
|
62
|
+
out.should match "-- Total Bookmarks: 6"
|
63
|
+
out.should match "h_1 h_2 md refs toc"
|
64
|
+
out.should match " - h_1 \\(1\\)"
|
65
|
+
@r.detailed = false
|
66
|
+
out = stdout_for { @r.display }
|
67
|
+
out.should_not match "-- Occurrences:"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should display stats for a single bookmark" do
|
71
|
+
stats :bookmark, 'refs'
|
72
|
+
out = stdout_for { rep.display }
|
73
|
+
out.should match "===== Bookmark 'refs' \\(header\\)"
|
74
|
+
out.should match " - text/references.glyph \\(1\\)"
|
75
|
+
@r.detailed = false
|
76
|
+
out = stdout_for { @r.display }
|
77
|
+
out.should_not match "-- Referenced in:"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should display snippet stats" do
|
81
|
+
stats :snippets
|
82
|
+
out = stdout_for { rep.display }
|
83
|
+
out.should match "-- Total Snippets: 2"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should display stats for a single snippet" do
|
87
|
+
stats :snippet, :test
|
88
|
+
out = stdout_for { rep.display }
|
89
|
+
out.should match "-- Total Used Instances: 2"
|
90
|
+
out.should match " - text/references.glyph \\(1\\)"
|
91
|
+
@r.detailed = false
|
92
|
+
out = stdout_for { @r.display }
|
93
|
+
out.should_not match "-- Usage Details:"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should display link stats" do
|
97
|
+
stats :links
|
98
|
+
out = stdout_for { rep.display }
|
99
|
+
out.should match "http://www.h3rald.com"
|
100
|
+
out.should match "-- Total Internal Links: 2"
|
101
|
+
@r.detailed = false
|
102
|
+
out = stdout_for { @r.display }
|
103
|
+
out.should_not match " - text/references.glyph (1)"
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should display stats for a single link" do
|
107
|
+
stats :link, 'h3'
|
108
|
+
out = stdout_for { rep.display }
|
109
|
+
out.should match "===== Links matching \\/h3\\/"
|
110
|
+
out.should match " - http://www.h3rald.com \\(1\\)"
|
111
|
+
@r.detailed = false
|
112
|
+
out = stdout_for { @r.display }
|
113
|
+
out.should_not match " - http://www.h3rald.com \\(1\\)"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should display files stats" do
|
117
|
+
stats :files
|
118
|
+
out = stdout_for { rep.display }
|
119
|
+
out.should match "-- Total Files: 6"
|
120
|
+
out.should match "-- /text -- 4"
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should display global stats" do
|
124
|
+
stats :global
|
125
|
+
out = stdout_for { rep.display }
|
126
|
+
out.should match "-- Total Files: 6"
|
127
|
+
out.should match " - http://www.h3rald.com"
|
128
|
+
out.should match "Total Macro Instances: 20"
|
129
|
+
out.should match "-- Total Snippets: 2"
|
130
|
+
out.should match "h_1 h_2 md refs toc"
|
131
|
+
end
|
132
|
+
end
|
data/spec/macros/core_spec.rb
CHANGED
@@ -83,7 +83,7 @@ describe "Macro:" do
|
|
83
83
|
Glyph["filters.by_extension"] = true
|
84
84
|
text = file_load(Glyph::PROJECT/'text/container.textile')
|
85
85
|
interpret text
|
86
|
-
@p.document.output.gsub(/\n|\t
|
86
|
+
@p.document.output.gsub(/\n|\t/, '').should == %{
|
87
87
|
<div class="section">
|
88
88
|
<h2 id="h_1">Container section</h2>
|
89
89
|
This is a test.
|
@@ -92,7 +92,7 @@ describe "Macro:" do
|
|
92
92
|
<p>…</p>
|
93
93
|
</div>
|
94
94
|
</div>
|
95
|
-
}.gsub(/\n|\t
|
95
|
+
}.gsub(/\n|\t/, '')
|
96
96
|
end
|
97
97
|
|
98
98
|
it "include should work in Lite mode" do
|
@@ -191,5 +191,4 @@ Test -- Test Snippet
|
|
191
191
|
end.should raise_error(Glyph::MacroError)
|
192
192
|
end
|
193
193
|
|
194
|
-
|
195
194
|
end
|