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,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
macro :note do
|
4
|
+
%{<aside class="#{@name}">
|
5
|
+
<span class="note-title">#{@name.to_s.capitalize}</span>#{value}
|
6
|
+
|
7
|
+
</aside>}
|
8
|
+
end
|
9
|
+
|
10
|
+
macro :box do
|
11
|
+
exact_parameters 2
|
12
|
+
%{<aside class="box">
|
13
|
+
<div class="box-title">#{param(0)}</div>
|
14
|
+
#{param(1)}
|
15
|
+
|
16
|
+
</aside>}
|
17
|
+
end
|
18
|
+
|
19
|
+
macro :figure do
|
20
|
+
min_parameters 1
|
21
|
+
max_parameters 2
|
22
|
+
image = param(0)
|
23
|
+
alt = "@alt[-]" unless attr(:alt)
|
24
|
+
caption = "figcaption[#{param(1)}]" rescue nil
|
25
|
+
figure_element_for image, alt, caption do |alt, dest_file, caption|
|
26
|
+
interpret %{=figure[
|
27
|
+
img[#{alt}@src[#{Glyph['document.base']}#{dest_file}]#{@node.attrs.join}]
|
28
|
+
#{caption}
|
29
|
+
]}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
macro :pubdate do
|
34
|
+
no_parameters
|
35
|
+
t = Time.now
|
36
|
+
%{<time class="pubdate" datetime="#{t.strftime("%Y-%m-%d")}">
|
37
|
+
#{Time.now.strftime("%B %Y")}
|
38
|
+
</time>}
|
39
|
+
end
|
40
|
+
|
41
|
+
macro :navigation do
|
42
|
+
exact_parameters 1
|
43
|
+
procs = {}
|
44
|
+
procs[:contents] = lambda do
|
45
|
+
%{<a href="#{Glyph["output.#{Glyph['document.output']}.base"]}index.html">Contents</a>}
|
46
|
+
end
|
47
|
+
procs[:previous] = lambda do |topic|
|
48
|
+
if topic then
|
49
|
+
%{<a href="#{Glyph["output.#{Glyph['document.output']}.base"]}#{topic[:src].gsub(/\..+$/, '.html')}">#{topic[:title]} ←</a>}
|
50
|
+
else
|
51
|
+
""
|
52
|
+
end
|
53
|
+
end
|
54
|
+
procs[:next] = lambda do |topic|
|
55
|
+
if topic then
|
56
|
+
%{<a href="#{Glyph["output.#{Glyph['document.output']}.base"]}#{topic[:src].gsub(/\..+$/, '.html')}">→ #{topic[:title]}</a>}
|
57
|
+
else
|
58
|
+
""
|
59
|
+
end
|
60
|
+
end
|
61
|
+
procs[:navigation] = lambda do |contents, prev_link, next_link|
|
62
|
+
%{<nav>#{prev_link}#{contents}#{next_link}</nav>}
|
63
|
+
end
|
64
|
+
navigation_element_for param(0).to_sym, procs
|
65
|
+
end
|
66
|
+
|
67
|
+
macro_alias :important => :note
|
68
|
+
macro_alias :tip => :note
|
69
|
+
macro_alias :caution => :note
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
macro :fmi do
|
4
|
+
exact_parameters 2, :level => :warning
|
5
|
+
fmi_element_for param(0), param(1) do |topic, link|
|
6
|
+
%{<span class="fmi">for more information on <mark>#{topic}</mark>, see #{link}</span>}
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
macro :draftcomment do
|
11
|
+
draftcomment_element do |value|
|
12
|
+
%{<aside class="comment"><span class="comment-pre"><strong>Comment:</strong> </span>#{value}</aside>}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
macro :todo do
|
17
|
+
exact_parameters 1
|
18
|
+
todo_element do |value|
|
19
|
+
%{<aside class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>#{value}</aside>}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
macro_alias '!' => :todo
|
24
|
+
macro_alias :dc => :draftcomment
|
@@ -0,0 +1,139 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
macro :section do
|
4
|
+
max_parameters 1
|
5
|
+
if raw_attribute(:src) && Glyph.multiple_output_files? then
|
6
|
+
required_attribute :title
|
7
|
+
end
|
8
|
+
procs = {}
|
9
|
+
procs[:title] = lambda do |level, ident, title|
|
10
|
+
%{<header><h1 id="#{ident}">#{title}</h1></header>\n}
|
11
|
+
end
|
12
|
+
procs[:body] = lambda do |title, value|
|
13
|
+
%{<section class="#{@name}">
|
14
|
+
#{title}#{value}
|
15
|
+
|
16
|
+
</section>}
|
17
|
+
end
|
18
|
+
section_element_for procs
|
19
|
+
end
|
20
|
+
|
21
|
+
macro :article do
|
22
|
+
exact_parameters 1
|
23
|
+
head = raw_attr(:head)
|
24
|
+
head ||= %{style[default.css]}
|
25
|
+
pre_title = raw_attr(:"pre-title")
|
26
|
+
post_title = raw_attr(:"post-title")
|
27
|
+
pubdate = @node.attr(:pubdate) ? "time[@class[pubdate]#{@node.attr(:pubdate).contents}]" : "pubdate[]"
|
28
|
+
halftitlepage = raw_attr(:halftitlepage)
|
29
|
+
halftitlepage ||= %{
|
30
|
+
#{pre_title}
|
31
|
+
hgroup[
|
32
|
+
title[]
|
33
|
+
subtitle[]
|
34
|
+
]
|
35
|
+
author[]
|
36
|
+
#{pubdate}
|
37
|
+
#{post_title}
|
38
|
+
}
|
39
|
+
interpret %{document[
|
40
|
+
head[#{head}]
|
41
|
+
body[
|
42
|
+
=article[
|
43
|
+
halftitlepage[
|
44
|
+
#{halftitlepage}
|
45
|
+
]
|
46
|
+
#{@node.value}
|
47
|
+
]
|
48
|
+
]
|
49
|
+
]}
|
50
|
+
end
|
51
|
+
|
52
|
+
macro :book do
|
53
|
+
no_parameters
|
54
|
+
head = raw_attr(:head)
|
55
|
+
head ||= %{style[default.css]}
|
56
|
+
pre_title = raw_attr(:"pre-title")
|
57
|
+
post_title = raw_attr(:"post-title")
|
58
|
+
titlepage = raw_attr(:titlepage)
|
59
|
+
pubdate = @node.attr(:pubdate) ? "time[@class[pubdate]#{@node.attr(:pubdate).contents}]" : "pubdate[]"
|
60
|
+
titlepage ||= %{
|
61
|
+
#{pre_title}
|
62
|
+
hgroup[
|
63
|
+
title[]
|
64
|
+
subtitle[]
|
65
|
+
]
|
66
|
+
revision[]
|
67
|
+
author[]
|
68
|
+
#{pubdate}
|
69
|
+
#{post_title}
|
70
|
+
}
|
71
|
+
frontmatter = raw_attr(:frontmatter)
|
72
|
+
bodymatter = raw_attr(:bodymatter)
|
73
|
+
backmatter = raw_attr(:backmatter)
|
74
|
+
frontmatter = "frontmatter[\n#{frontmatter}\n]" if frontmatter
|
75
|
+
bodymatter = "bodymatter[\n#{bodymatter}\n]" if bodymatter
|
76
|
+
backmatter = "backmatter[\n#{backmatter}\n]" if backmatter
|
77
|
+
interpret %{document[
|
78
|
+
head[#{head}]
|
79
|
+
body[
|
80
|
+
titlepage[
|
81
|
+
#{titlepage}
|
82
|
+
]
|
83
|
+
#{frontmatter}
|
84
|
+
#{bodymatter}
|
85
|
+
#{backmatter}
|
86
|
+
]
|
87
|
+
]}
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
macro :document do
|
92
|
+
exact_parameters 1
|
93
|
+
%{<!DOCTYPE html>
|
94
|
+
<html lang="en">
|
95
|
+
#{value}
|
96
|
+
|
97
|
+
</html>}
|
98
|
+
end
|
99
|
+
|
100
|
+
macro :toc do
|
101
|
+
max_parameters 1
|
102
|
+
link_proc = lambda do |head|
|
103
|
+
(!Glyph.multiple_output_files? || (head.definition != head.file)) ? %{<a href="#{head.link(@source_file)}">#{head.title}</a>} : head.title
|
104
|
+
end
|
105
|
+
toc_list_proc = lambda do |descend_proc, bmk, document|
|
106
|
+
%{<nav class="contents">
|
107
|
+
<h1 class="toc-header" id="#{bmk}">#{bmk.title}</h1>
|
108
|
+
<ol class="toc">
|
109
|
+
#{descend_proc.call(document.structure, nil)}
|
110
|
+
</ol>
|
111
|
+
</nav>}
|
112
|
+
end
|
113
|
+
toc_item_proc = lambda do |classes, header|
|
114
|
+
"<li class=\"#{classes.join(" ").strip}\">#{header}</li>"
|
115
|
+
end
|
116
|
+
toc_sublist_proc = lambda do |contents|
|
117
|
+
"<li><ol>#{contents}</ol></li>\n"
|
118
|
+
end
|
119
|
+
toc_element_for param(0), attr(:title),
|
120
|
+
:link => link_proc,
|
121
|
+
:toc_list => toc_list_proc,
|
122
|
+
:toc_item => toc_item_proc,
|
123
|
+
:toc_sublist => toc_sublist_proc
|
124
|
+
end
|
125
|
+
|
126
|
+
# See:
|
127
|
+
# http://microformats.org/wiki/book-brainstorming
|
128
|
+
# http://en.wikipedia.org/wiki/Book_design
|
129
|
+
|
130
|
+
(Glyph['system.structure.frontmatter'] + Glyph['system.structure.bodymatter'] + Glyph['system.structure.backmatter']).
|
131
|
+
each {|s| macro_alias s => :section }
|
132
|
+
|
133
|
+
macro_alias :frontcover => :section
|
134
|
+
macro_alias :titlepage => :section
|
135
|
+
macro_alias :halftitlepage => :section
|
136
|
+
macro_alias :frontmatter => :section
|
137
|
+
macro_alias :bodymatter => :section
|
138
|
+
macro_alias :backmatter => :section
|
139
|
+
macro_alias :backcover => :section
|
data/macros/xml.rb
CHANGED
@@ -12,7 +12,7 @@ macro "|xml|" do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
name = @node[:element]
|
15
|
-
if name.to_s.in?
|
15
|
+
if Glyph["options.xml_blacklist"] && name.to_s.in?(Glyph['options.xml_blacklist']) then
|
16
16
|
""
|
17
17
|
else
|
18
18
|
attributes # evaluate attributes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
document[
|
2
|
+
head[
|
3
|
+
style[default.css]
|
4
|
+
style[test.sass]
|
5
|
+
]
|
6
|
+
body[
|
7
|
+
toc[]
|
8
|
+
contents[
|
9
|
+
section[
|
10
|
+
@title[Web Document]
|
11
|
+
...
|
12
|
+
section[
|
13
|
+
@src[a/web1.glyph]
|
14
|
+
@title[Topic #1]
|
15
|
+
]
|
16
|
+
section[
|
17
|
+
@src[a/b/web2.glyph]
|
18
|
+
@title[Topic #2]
|
19
|
+
]
|
20
|
+
]
|
21
|
+
]
|
22
|
+
]
|
23
|
+
]
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
5
|
+
|
6
|
+
describe Glyph::Analyzer do
|
7
|
+
|
8
|
+
before do
|
9
|
+
reset_quiet
|
10
|
+
create_project_dir
|
11
|
+
create_project
|
12
|
+
Glyph.file_copy Glyph::SPEC_DIR/'files/document_for_stats.glyph', Glyph::PROJECT/'document.glyph'
|
13
|
+
Glyph.file_copy Glyph::SPEC_DIR/'files/references.glyph', Glyph::PROJECT/'text/references.glyph'
|
14
|
+
Glyph.run! 'generate:document'
|
15
|
+
@a = Glyph::Analyzer.new
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
delete_project_dir
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be initialized with a document" do
|
23
|
+
lambda { Glyph::Analyzer.new(Glyph.document) }.should_not raise_error
|
24
|
+
lambda { Glyph::Analyzer.new }.should_not raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should expose a macro node iterator" do
|
28
|
+
lambda { @a.with_macros }.should raise_error(ArgumentError, "No block given")
|
29
|
+
count = 0
|
30
|
+
lambda { @a.with_macros {|n| count+=1} }.should_not raise_error
|
31
|
+
count.should == 20
|
32
|
+
count = 0
|
33
|
+
lambda { @a.with_macros(:snippet) {|n| count+=1} }.should_not raise_error
|
34
|
+
count.should == 2
|
35
|
+
count = 0
|
36
|
+
lambda { @a.with_macros(:&) {|n| count+=1} }.should_not raise_error
|
37
|
+
count.should == 2
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should access macro instance arrays by definition" do
|
41
|
+
@a.macro_array_for(:snippet).should == []
|
42
|
+
@a.with_macros {}
|
43
|
+
@a.macro_array_for(:snippet).length.should == 2
|
44
|
+
@a.macro_array_for(:&).length.should == 2
|
45
|
+
@a.macro_array_for(:section).length.should == 4
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should raise an error if a stat is not available" do
|
49
|
+
lambda { @a.stats_for :unknown }.should raise_error(RuntimeError, "Unable to calculate unknown stats")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should calculate stats for all macros" do
|
53
|
+
lambda {@a.stats_for :macros}.should_not raise_error
|
54
|
+
@a.stats[:macros].blank?.should == false
|
55
|
+
c = @a.stats[:macros]
|
56
|
+
c[:definitions].should == (Glyph::MACROS.keys - Glyph::ALIASES[:by_alias].keys).uniq.sort
|
57
|
+
c[:aliases].should == Glyph::ALIASES[:by_alias].keys.sort
|
58
|
+
c[:instances].length.should == 20
|
59
|
+
c[:used_definitions].should == [:anchor, :include, :link, :markdown, :section, :snippet, :"snippet:", :textile, :toc]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should calculate stats for a single macro" do
|
63
|
+
lambda {@a.stats_for :macro, :dsfash }.should raise_error(ArgumentError, "Unknown macro 'dsfash'")
|
64
|
+
lambda {@a.stats_for :macro, :frontmatter }.should
|
65
|
+
raise_error(ArgumentError, "Alias 'frontmatter' is not used in this document, did you mean 'section'?")
|
66
|
+
lambda {@a.stats_for :macro, :section }.should_not raise_error
|
67
|
+
c = @a.stats[:macro]
|
68
|
+
c[:instances].length.should == 4
|
69
|
+
c[:files].should == [["document.glyph", 1], ["text/a/b/c/included.textile", 1],
|
70
|
+
["text/a/b/c/markdown.markdown", 1], ["text/container.textile", 1]]
|
71
|
+
@a.stats_for :macro, :"&"
|
72
|
+
c = @a.stats[:macro]
|
73
|
+
c[:alias_for].should == :snippet
|
74
|
+
c[:instances].length.should == 2
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should calculate stats for all bookmarks" do
|
78
|
+
lambda {@a.stats_for :bookmarks}.should_not raise_error
|
79
|
+
c = @a.stats[:bookmarks]
|
80
|
+
c[:codes].should == [:h_1, :h_2, :md, :refs, :toc, :unused]
|
81
|
+
c[:unreferenced].should == [:h_2, :md, :toc, :unused]
|
82
|
+
c[:referenced].should == [[:h_1, 1], [:refs, 1]]
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should calculate stats for a single bookmark" do
|
86
|
+
lambda {@a.stats_for :bookmark, '#h_7'}.should raise_error(ArgumentError, "Bookmark 'h_7' does not exist")
|
87
|
+
lambda {@a.stats_for :bookmark, '#h_1'}.should_not raise_error
|
88
|
+
c = @a.stats[:bookmark]
|
89
|
+
c[:file].should == "text/container.textile"
|
90
|
+
c[:references].should == [["text/references.glyph", 1]]
|
91
|
+
c[:type].should == :header
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should calculate stats for all links do" do
|
95
|
+
lambda {@a.stats_for :links}.should_not raise_error
|
96
|
+
c = @a.stats[:links]
|
97
|
+
c[:internal].should == [["#h_1", {:total=>1, :files=>[["text/references.glyph", 1]]}],
|
98
|
+
["#refs", {:total=>1, :files=>[["text/references.glyph", 1]]}]]
|
99
|
+
c[:external].should == [["http://www.h3rald.com", {:total=>1, :files=>[["text/references.glyph", 1]]}]]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should calculate stats for a single link" do
|
103
|
+
lambda {@a.stats_for :link, 'q'}.should raise_error(ArgumentError, "No link matching /q/ was found")
|
104
|
+
lambda {@a.stats_for :link, 'h'}.should_not raise_error
|
105
|
+
c = @a.stats[:link][:stats]
|
106
|
+
c.should == [["#h_1", {:total=>1, :files=>[["text/references.glyph", 1]]}],
|
107
|
+
["http://www.h3rald.com",{:total=>1, :files=>[["text/references.glyph", 1]]}]]
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should calculate stats for all snippets" do
|
111
|
+
lambda {@a.stats_for :snippets}.should_not raise_error
|
112
|
+
c = @a.stats[:snippets]
|
113
|
+
c[:used].should == [:test]
|
114
|
+
c[:total].should == 2
|
115
|
+
c[:unused].should == [:unused]
|
116
|
+
c[:definitions].should == [:test, :unused]
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should calculate stats for a single snippet" do
|
120
|
+
lambda {@a.stats_for :snippet, 'test1'}.should raise_error(ArgumentError, "Snippet 'test1' does not exist")
|
121
|
+
lambda {@a.stats_for :snippet, 'unused'}.should raise_error(ArgumentError, "Snippet 'unused' is not used in this document")
|
122
|
+
lambda {@a.stats_for :snippet, 'test'}.should_not raise_error
|
123
|
+
c = @a.stats[:snippet][:stats]
|
124
|
+
c.should == {:total=>2, :files=>[["document.glyph", 1], ["text/references.glyph", 1]]}
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should calculate global stats" do
|
128
|
+
lambda {@a.stats_for :global}.should_not raise_error
|
129
|
+
c = @a.stats
|
130
|
+
c[:bookmarks].blank?.should == false
|
131
|
+
c[:links].blank?.should == false
|
132
|
+
c[:snippets].blank?.should == false
|
133
|
+
c[:macros].blank?.should == false
|
134
|
+
c[:files].should == {:layouts=>0, :images=>1, :styles=>1, :text=>4, :lib=>0}
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|