glyph 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS.textile +1 -1
- data/CHANGELOG.textile +119 -222
- data/LICENSE.textile +1 -1
- data/README.textile +42 -23
- data/Rakefile +1 -3
- data/VERSION +1 -1
- data/benchmark.rb +72 -0
- data/book/config.yml +4 -4
- data/book/document.glyph +90 -57
- data/book/images/document_generation.png +0 -0
- data/book/lib/macros/reference.rb +75 -22
- data/book/output/html/glyph.html +3183 -2121
- data/book/output/html/images/document_generation.png +0 -0
- data/book/output/pdf/glyph.pdf +7370 -4913
- data/book/resources/document_generation.txt +34 -0
- data/book/snippets.yml +6 -0
- data/book/text/changelog.glyph +45 -34
- data/book/text/compiling/compiling.glyph +23 -0
- data/book/text/compiling/lite_mode.glyph +23 -0
- data/book/text/compiling/programmatic_usage.glyph +77 -0
- data/book/text/extending/bookmarks_headers.glyph +21 -0
- data/book/text/extending/further_reading.glyph +13 -0
- data/book/text/extending/internals.glyph +79 -0
- data/book/text/extending/interpreting.glyph +51 -0
- data/book/text/extending/macro_def.glyph +64 -0
- data/book/text/extending/params_attrs.glyph +70 -0
- data/book/text/extending/placeholders.glyph +34 -0
- data/book/text/extending/validators.glyph +16 -0
- data/book/text/getting_started/configuration.glyph +49 -0
- data/book/text/getting_started/create_project.glyph +41 -0
- data/book/text/getting_started/structure.glyph +55 -0
- data/book/text/introduction.glyph +49 -26
- data/book/text/license.glyph +1 -1
- data/book/text/macros/macros_block.glyph +99 -0
- data/book/text/macros/macros_core.glyph +208 -0
- data/book/text/macros/macros_filters.glyph +40 -0
- data/book/text/macros/macros_inline.glyph +50 -0
- data/book/text/macros/macros_structure.glyph +100 -0
- data/book/text/ref_commands.glyph +94 -73
- data/book/text/ref_config.glyph +34 -42
- data/book/text/ref_macros.glyph +1 -373
- data/book/text/text_editing/code.glyph +51 -0
- data/book/text/text_editing/conditionals.glyph +49 -0
- data/book/text/text_editing/evaluation.glyph +13 -0
- data/book/text/text_editing/glyph_files.glyph +7 -0
- data/book/text/text_editing/images.glyph +29 -0
- data/book/text/text_editing/inclusions.glyph +44 -0
- data/book/text/text_editing/links.glyph +53 -0
- data/book/text/text_editing/macro_intro.glyph +111 -0
- data/book/text/text_editing/raw_html.glyph +112 -0
- data/book/text/text_editing/sections.glyph +63 -0
- data/book/text/text_editing/stylesheets.glyph +36 -0
- data/book/text/troubleshooting/errors_command.glyph +39 -0
- data/book/text/troubleshooting/errors_generic.glyph +29 -0
- data/book/text/troubleshooting/errors_intro.glyph +3 -0
- data/book/text/troubleshooting/errors_macro.glyph +98 -0
- data/book/text/troubleshooting/errors_parser.glyph +29 -0
- data/config.yml +77 -58
- data/document.glyph +25 -25
- data/glyph.gemspec +57 -22
- data/lib/glyph.rb +54 -13
- data/lib/glyph/commands.rb +84 -17
- data/lib/glyph/config.rb +3 -3
- data/lib/glyph/document.rb +14 -8
- data/lib/glyph/interpreter.rb +18 -58
- data/lib/glyph/macro.rb +160 -55
- data/lib/glyph/macro_validators.rb +104 -12
- data/lib/glyph/node.rb +24 -0
- data/lib/glyph/parser.rb +278 -0
- data/lib/glyph/syntax_node.rb +225 -0
- data/macros/core.rb +212 -0
- data/macros/filters.rb +66 -15
- data/macros/html/block.rb +43 -105
- data/macros/html/inline.rb +11 -12
- data/macros/html/structure.rb +123 -58
- data/macros/xml.rb +33 -0
- data/spec/files/container.textile +2 -2
- data/spec/files/document.glyph +2 -2
- data/spec/files/document_with_toc.glyph +3 -3
- data/spec/files/included.textile +1 -1
- data/spec/files/ligature.jpg +0 -0
- data/spec/files/markdown.markdown +2 -1
- data/spec/lib/commands_spec.rb +46 -3
- data/spec/lib/document_spec.rb +4 -4
- data/spec/lib/glyph_spec.rb +17 -46
- data/spec/lib/interpreter_spec.rb +6 -25
- data/spec/lib/macro_spec.rb +141 -43
- data/spec/lib/macro_validators_spec.rb +27 -5
- data/spec/lib/node_spec.rb +26 -1
- data/spec/lib/parser_spec.rb +246 -0
- data/spec/lib/syntax_node_spec.rb +111 -0
- data/spec/macros/core_spec.rb +195 -0
- data/spec/macros/filters_spec.rb +38 -4
- data/spec/macros/macros_spec.rb +20 -176
- data/spec/macros/textile_spec.rb +13 -71
- data/spec/macros/xml_spec.rb +77 -0
- data/spec/spec_helper.rb +50 -10
- data/spec/tasks/load_spec.rb +13 -2
- data/styles/default.css +18 -6
- data/styles/pagination.css +1 -19
- data/tasks/generate.rake +2 -2
- data/tasks/load.rake +27 -17
- data/tasks/project.rake +1 -1
- metadata +75 -62
- data/book/script/compile.rb +0 -8
- data/book/script/prof +0 -1
- data/book/script/prof_results.htm +0 -21079
- data/book/text/authoring.glyph +0 -548
- data/book/text/extending.glyph +0 -224
- data/book/text/getting_started.glyph +0 -158
- data/book/text/troubleshooting.glyph +0 -179
- data/lib/glyph/glyph_language.rb +0 -538
- data/lib/glyph/glyph_language.treetop +0 -27
- data/macros/common.rb +0 -160
@@ -0,0 +1,195 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
3
|
+
|
4
|
+
describe "Macro:" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
create_project
|
8
|
+
Glyph.run! 'load:all'
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Glyph.lite_mode = false
|
13
|
+
delete_project
|
14
|
+
end
|
15
|
+
|
16
|
+
it "snippet" do
|
17
|
+
define_em_macro
|
18
|
+
interpret "Testing a snippet: &[test]."
|
19
|
+
@p.document.output.should == "Testing a snippet: This is a \nTest snippet."
|
20
|
+
interpret("Testing &[wrong].")
|
21
|
+
@p.document.output.should == "Testing [SNIPPET 'wrong' NOT PROCESSED]."
|
22
|
+
Glyph::SNIPPETS[:a] = "this is a em[test] &[b]"
|
23
|
+
Glyph::SNIPPETS[:b] = "and another em[test]"
|
24
|
+
text = "TEST: &[a]"
|
25
|
+
interpret text
|
26
|
+
@p.document.output.should == "TEST: this is a <em>test</em> and another <em>test</em>"
|
27
|
+
# Check snippets with links
|
28
|
+
Glyph::SNIPPETS[:c] = "This is a link to something afterwards: =>[#other]"
|
29
|
+
text = "Test. &[c]. #[other|Test]."
|
30
|
+
output_for(text).should == %{Test. This is a link to something afterwards: <a href="#other">Test</a>. <a id="other">Test</a>.}
|
31
|
+
end
|
32
|
+
|
33
|
+
it "snippet:" do
|
34
|
+
interpret("&[t1] - &:[t1|Test #1] - &[t1]")
|
35
|
+
@p.document.output.should == "[SNIPPET 't1' NOT PROCESSED] - - Test #1"
|
36
|
+
Glyph::SNIPPETS[:t1].should == "Test #1"
|
37
|
+
Glyph::SNIPPETS.delete :t1
|
38
|
+
end
|
39
|
+
|
40
|
+
it "condition" do
|
41
|
+
define_em_macro
|
42
|
+
interpret("?[$[document.invalid]|em[test]]")
|
43
|
+
@p.document.output.should == ""
|
44
|
+
interpret("?[$[document.output]|em[test]]")
|
45
|
+
@p.document.output.should == "<em>test</em>"
|
46
|
+
interpret("?[not[eq[$[document.output]|]]|em[test]]")
|
47
|
+
@p.document.output.should == "<em>test</em>"
|
48
|
+
interpret %{?[
|
49
|
+
or[
|
50
|
+
eq[$[document.target]|htmls]|
|
51
|
+
not[eq[$[document.author]|x]]
|
52
|
+
]|em[test]]}
|
53
|
+
@p.document.output.should == "<em>test</em>"
|
54
|
+
# "false" should be regarded as false
|
55
|
+
interpret(%{?[%["test".blank?]|---]})
|
56
|
+
@p.document.output.should == ""
|
57
|
+
interpret("?[not[match[$[document.source]|/^docu/]]|em[test]]")
|
58
|
+
@p.document.output.should == ""
|
59
|
+
# Invalid regexp
|
60
|
+
lambda { interpret("?[match[$[document.source]|document]em[test]]").document.output }.should raise_error
|
61
|
+
interpret "?[%[lite?]|test]"
|
62
|
+
@p.document.output.should == ""
|
63
|
+
interpret "?[%[!lite?]|test]"
|
64
|
+
@p.document.output.should == "test"
|
65
|
+
interpret "?[%[lite?]|%[\"test\"]]"
|
66
|
+
@p.document.output.should == ""
|
67
|
+
# Condition not satisfied...
|
68
|
+
interpret "?[%[lite?]|%[ Glyph\\['test_config'\\] = true ]]"
|
69
|
+
@p.document.output.should == ""
|
70
|
+
Glyph['test_config'].should_not == true
|
71
|
+
# Condition satisfied...
|
72
|
+
interpret "?[%[!lite?]|%[ Glyph\\['test_config'\\] = true ]]"
|
73
|
+
@p.document.output.should == "true"
|
74
|
+
Glyph['test_config'].should == true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "comment" do
|
78
|
+
output_for("--[config:[some_random_setting|test]]").should == ""
|
79
|
+
Glyph[:some_random_setting].should == nil
|
80
|
+
end
|
81
|
+
|
82
|
+
it "include" do
|
83
|
+
Glyph["filters.by_extension"] = true
|
84
|
+
text = file_load(Glyph::PROJECT/'text/container.textile')
|
85
|
+
interpret text
|
86
|
+
@p.document.output.gsub(/\n|\t|_\d{1,3}/, '').should == %{
|
87
|
+
<div class="section">
|
88
|
+
<h2 id="h_1">Container section</h2>
|
89
|
+
This is a test.
|
90
|
+
<div class="section">
|
91
|
+
<h3 id="h_2">Test Section</h3>
|
92
|
+
<p>…</p>
|
93
|
+
</div>
|
94
|
+
</div>
|
95
|
+
}.gsub(/\n|\t|_\d{1,3}/, '')
|
96
|
+
end
|
97
|
+
|
98
|
+
it "include should work in Lite mode" do
|
99
|
+
Glyph.lite_mode = true
|
100
|
+
result = %{<div class="section">
|
101
|
+
<h2 id="h_1">Container section</h2>
|
102
|
+
This is a test.
|
103
|
+
<div class="section">
|
104
|
+
<h3 id="h_2">Test Section</h3>
|
105
|
+
<p>…</p>
|
106
|
+
</div>
|
107
|
+
|
108
|
+
</div>}.gsub(/\n|\t/, '')
|
109
|
+
Dir.chdir Glyph::SPEC_DIR/"files"
|
110
|
+
text = file_load(Glyph::SPEC_DIR/"files/container.textile").gsub("a/b/c/", '')
|
111
|
+
Glyph.filter(text).gsub(/\n|\t/, '').should == result
|
112
|
+
Dir.chdir Glyph::PROJECT
|
113
|
+
Glyph.lite_mode = false
|
114
|
+
end
|
115
|
+
|
116
|
+
it "include should assume .glyph as the default extension" do
|
117
|
+
file_copy Glyph::SPEC_DIR/'files/article.glyph', Glyph::PROJECT/'text/article.glyph'
|
118
|
+
output_for("include[article]").gsub(/\n|\t/, '').should == %{<div class="section">
|
119
|
+
Test -- Test Snippet
|
120
|
+
|
121
|
+
</div>}.gsub(/\n|\t/, '')
|
122
|
+
end
|
123
|
+
|
124
|
+
it "include should evaluate .rb file in the context of Glyph" do
|
125
|
+
text = %{
|
126
|
+
macro :day do
|
127
|
+
Time.now.day
|
128
|
+
end
|
129
|
+
}
|
130
|
+
file_write Glyph::PROJECT/"lib/test.rb", text
|
131
|
+
output_for("include[test.rb]day[]").should == Time.now.day.to_s
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
it "escape" do
|
136
|
+
define_em_macro
|
137
|
+
text = %{This is a test em[This can .[=contain test[macros em[test]]=]]}
|
138
|
+
interpret text
|
139
|
+
@p.document.output.should == %{This is a test <em>This can contain test[macros em[test]]</em>}
|
140
|
+
end
|
141
|
+
|
142
|
+
it "ruby" do
|
143
|
+
interpret "2 + 2 = %[2+2]"
|
144
|
+
@p.document.output.should == %{2 + 2 = 4}
|
145
|
+
interpret "%[lite?]"
|
146
|
+
@p.document.output.should == %{false}
|
147
|
+
interpret "%[def test; end]"
|
148
|
+
end
|
149
|
+
|
150
|
+
it "config" do
|
151
|
+
Glyph["test.setting"] = "TEST"
|
152
|
+
interpret "test.setting = $[test.setting]"
|
153
|
+
@p.document.output.should == %{test.setting = TEST}
|
154
|
+
end
|
155
|
+
|
156
|
+
it "config:" do
|
157
|
+
Glyph["test.setting"] = "TEST"
|
158
|
+
interpret "test.setting = $[test.setting]"
|
159
|
+
@p.document.output.should == %{test.setting = TEST}
|
160
|
+
interpret "test.setting = $:[test.setting|TEST2]$[test.setting]"
|
161
|
+
@p.document.output.should == %{test.setting = TEST2}
|
162
|
+
interpret("$:[test.setting]").process
|
163
|
+
Glyph['test.setting'].should == nil
|
164
|
+
Glyph['system.test'] = 1
|
165
|
+
interpret("$:[system.test|2]").process
|
166
|
+
Glyph['system.test'].should == 1
|
167
|
+
end
|
168
|
+
|
169
|
+
it "macro:" do
|
170
|
+
interpret '%:[e_macro|
|
171
|
+
"Test: #{value}"]e_macro[OK!]'
|
172
|
+
@p.document.output.should == "Test: OK!"
|
173
|
+
end
|
174
|
+
|
175
|
+
it "alias:" do
|
176
|
+
define_em_macro
|
177
|
+
interpret("alias:[test|em]").process
|
178
|
+
Glyph::MACROS[:test].should == Glyph::MACROS[:em]
|
179
|
+
end
|
180
|
+
|
181
|
+
it "rewrite:" do
|
182
|
+
define_em_macro
|
183
|
+
interpret("rewrite:[rw_test|em[{{0}}\\.em[{{a}}]]]").process
|
184
|
+
output_for("rw_test[test @a[em[A!]]]").should == "<em>test<em><em>A!</em></em></em>"
|
185
|
+
end
|
186
|
+
|
187
|
+
it "rewrite should detect mutual definitions" do
|
188
|
+
define_em_macro
|
189
|
+
lambda do
|
190
|
+
interpret("rw:[rw_test2|em[rw_test2[{{0}}]]]").process
|
191
|
+
end.should raise_error(Glyph::MacroError)
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
end
|
data/spec/macros/filters_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe "Filter Macros" do
|
|
12
12
|
after do
|
13
13
|
delete_project
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it "should filter textile input" do
|
17
17
|
text = "textile[This is a _TEST_(TM).]"
|
18
18
|
interpret text
|
@@ -34,9 +34,43 @@ describe "Filter Macros" do
|
|
34
34
|
- item 3
|
35
35
|
|
36
36
|
etc.]"
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
interpret text
|
38
|
+
@p.document.output.gsub(/\n|\t|\s{2}/, '').should ==
|
39
|
+
"<p>This is a test:</p><ul><li>item 1</li><li>item 2</li><li>item 3</li></ul><p>etc.</p>"
|
40
40
|
end
|
41
41
|
|
42
|
+
it "highlight" do
|
43
|
+
cr = false
|
44
|
+
uv = false
|
45
|
+
begin
|
46
|
+
require 'coderay'
|
47
|
+
cr = true
|
48
|
+
rescue Exception
|
49
|
+
end
|
50
|
+
begin
|
51
|
+
require 'uv'
|
52
|
+
uv = true
|
53
|
+
rescue Exception
|
54
|
+
end
|
55
|
+
code = %{def test_method(a, b)
|
56
|
+
puts a+b
|
57
|
+
end}
|
58
|
+
cr_result = %{<div class=\"CodeRay\"> <div class=\"code\"><pre><span class=\"r\">def</span>
|
59
|
+
<span class=\"fu\">test_method</span>(a, b) puts a+b <span class=\"r\">end</span></pre></div> </div>}
|
60
|
+
uv_result = %{<pre class=\"iplastic\"><span class=\"Keyword\">def</span>
|
61
|
+
<span class=\"FunctionName\">test_method</span>(<span class=\"Arguments\">a<span class=\"Arguments\">,</span> b</span>)
|
62
|
+
puts a<span class=\"Keyword\">+</span>b <span class=\"Keyword\">end</span> </pre>}
|
63
|
+
Glyph['filters.ultraviolet.theme'] = 'iplastic'
|
64
|
+
check = lambda do |hl, result|
|
65
|
+
Glyph["filters.highlighter"] = hl.to_sym
|
66
|
+
Glyph.debug_mode = true
|
67
|
+
interpret("highlight[=ruby|\n#{code}=]")
|
68
|
+
@p.document.output.gsub(/\s+/, ' ').strip.should == result.gsub(/\s+/, ' ').strip
|
69
|
+
end
|
70
|
+
Glyph['filters.ultraviolet.line_numbers'] = false
|
71
|
+
check.call 'ultraviolet', uv_result if uv
|
72
|
+
check.call 'coderay', cr_result if cr
|
73
|
+
end
|
74
|
+
|
75
|
+
|
42
76
|
end
|
data/spec/macros/macros_spec.rb
CHANGED
@@ -10,6 +10,7 @@ describe "Macro:" do
|
|
10
10
|
|
11
11
|
after do
|
12
12
|
Glyph.lite_mode = false
|
13
|
+
reset_quiet
|
13
14
|
delete_project
|
14
15
|
end
|
15
16
|
|
@@ -21,78 +22,16 @@ describe "Macro:" do
|
|
21
22
|
lambda { interpret "this is a #[test|test]. #[test|This won't work!]"; @p.document }.should raise_error(Glyph::MacroError)
|
22
23
|
end
|
23
24
|
|
24
|
-
it "snippet" do
|
25
|
-
define_em_macro
|
26
|
-
interpret "Testing a snippet: &[test]."
|
27
|
-
@p.document.output.should == "Testing a snippet: This is a \nTest snippet."
|
28
|
-
interpret("Testing &[wrong].")
|
29
|
-
@p.document.output.should == "Testing [SNIPPET 'wrong' NOT PROCESSED]."
|
30
|
-
Glyph::SNIPPETS[:a] = "this is a em[test] &[b]"
|
31
|
-
Glyph::SNIPPETS[:b] = "and another em[test]"
|
32
|
-
text = "TEST: &[a]"
|
33
|
-
interpret text
|
34
|
-
@p.document.output.should == "TEST: this is a <em>test</em> and another <em>test</em>"
|
35
|
-
# Check snippets with links
|
36
|
-
Glyph::SNIPPETS[:c] = "This is a link to something afterwards: =>[#other]"
|
37
|
-
text = "Test. &[c]. #[other|Test]."
|
38
|
-
interpret text
|
39
|
-
@p.document.output.should == %{Test. This is a link to something afterwards: <a href="#other">Test</a>. <a id="other">Test</a>.}
|
40
|
-
end
|
41
|
-
|
42
|
-
it "snippet:" do
|
43
|
-
interpret("&[t1] - &:[t1|Test #1] - &[t1]")
|
44
|
-
@p.document.output.should == "[SNIPPET 't1' NOT PROCESSED] - - Test #1"
|
45
|
-
Glyph::SNIPPETS[:t1].should == "Test #1"
|
46
|
-
Glyph::SNIPPETS.delete :t1
|
47
|
-
end
|
48
|
-
|
49
|
-
it "condition" do
|
50
|
-
define_em_macro
|
51
|
-
interpret("?[$[document.invalid]|em[test]]")
|
52
|
-
@p.document.output.should == ""
|
53
|
-
interpret("?[$[document.output]|em[test]]")
|
54
|
-
@p.document.output.should == "<em>test</em>"
|
55
|
-
interpret("?[not[eq[$[document.output]|]]|em[test]]")
|
56
|
-
@p.document.output.should == "<em>test</em>"
|
57
|
-
interpret %{?[
|
58
|
-
or[
|
59
|
-
eq[$[document.target]|htmls]|
|
60
|
-
not[eq[$[document.author]|x]]
|
61
|
-
]|em[test]]}
|
62
|
-
@p.document.output.should == "<em>test</em>"
|
63
|
-
# "false" should be regarded as false
|
64
|
-
interpret(%{?[%["test".blank?]|---]})
|
65
|
-
@p.document.output.should == ""
|
66
|
-
interpret("?[not[match[$[document.source]|/^docu/]]|em[test]]")
|
67
|
-
@p.document.output.should == ""
|
68
|
-
# Invalid regexp
|
69
|
-
lambda { interpret("?[match[$[document.source]|document]em[test]]").document.output }.should raise_error
|
70
|
-
interpret "?[%[lite?]|test]"
|
71
|
-
@p.document.output.should == ""
|
72
|
-
interpret "?[%[!lite?]|test]"
|
73
|
-
@p.document.output.should == "test"
|
74
|
-
interpret "?[%[lite?]|%[\"test\"]]"
|
75
|
-
@p.document.output.should == ""
|
76
|
-
# Condition not satisfied...
|
77
|
-
interpret "?[%[lite?]|*[= %[ Glyph\\['test_config'\\] = true ] =]]"
|
78
|
-
@p.document.output.should == ""
|
79
|
-
Glyph['test_config'].should_not == true
|
80
|
-
# Condition satisfied...
|
81
|
-
interpret "?[%[!lite?]|*[= --[%[ Glyph\\['test_config'\\] = true ]] =]]"
|
82
|
-
@p.document.output.should == ""
|
83
|
-
Glyph['test_config'].should == true
|
84
|
-
end
|
85
|
-
|
86
25
|
it "section, chapter, header" do
|
87
|
-
text = "chapter[
|
26
|
+
text = "chapter[@title[Chapter X] ... section[@title[Section Y]@id[sec-y] ... section[@title[Another section] ...]]]"
|
88
27
|
interpret text
|
89
28
|
doc = @p.document
|
90
29
|
doc.output.gsub(/\n|\t/, '').should == %{<div class="chapter">
|
91
|
-
<h2 id="h_1">Chapter X</h2
|
30
|
+
<h2 id="h_1">Chapter X</h2>...
|
92
31
|
<div class="section">
|
93
|
-
<h3 id="sec-y">Section Y</h3
|
32
|
+
<h3 id="sec-y">Section Y</h3>...
|
94
33
|
<div class="section">
|
95
|
-
<h4 id="h_3">Another section</h4
|
34
|
+
<h4 id="h_3">Another section</h4>...
|
96
35
|
</div>
|
97
36
|
</div>
|
98
37
|
</div>
|
@@ -100,29 +39,6 @@ describe "Macro:" do
|
|
100
39
|
doc.bookmark?(:"sec-y").should == {:id => :"sec-y", :title => "Section Y"}
|
101
40
|
end
|
102
41
|
|
103
|
-
it "include" do
|
104
|
-
Glyph["filters.by_extension"] = true
|
105
|
-
text = file_load(Glyph::PROJECT/'text/container.textile')
|
106
|
-
interpret text
|
107
|
-
@p.document.output.gsub(/\n|\t|_\d{1,3}/, '').should == %{
|
108
|
-
<div class="section">
|
109
|
-
<h2 id="h_1">Container section</h2>
|
110
|
-
This is a test.
|
111
|
-
<div class="section">
|
112
|
-
<h3 id="h_2">Test Section</h3>
|
113
|
-
<p>…</p>
|
114
|
-
</div>
|
115
|
-
</div>
|
116
|
-
}.gsub(/\n|\t|_\d{1,3}/, '')
|
117
|
-
end
|
118
|
-
|
119
|
-
it "include should not work in Lite mode" do
|
120
|
-
text = file_load(Glyph::PROJECT/'text/container.textile')
|
121
|
-
Glyph.lite_mode = true
|
122
|
-
lambda { interpret(text).document.output }.should raise_error Glyph::MacroError
|
123
|
-
Glyph.lite_mode = false
|
124
|
-
end
|
125
|
-
|
126
42
|
it "document, head, style" do
|
127
43
|
interpret "document[head[style[test.sass]]]"
|
128
44
|
@p.document.output.gsub(/\n|\t/, '').should == %{
|
@@ -134,7 +50,7 @@ describe "Macro:" do
|
|
134
50
|
<meta name="author" content="#{Glyph["document.author"]}" />
|
135
51
|
<meta name="copyright" content="#{Glyph["document.author"]}" />
|
136
52
|
<meta name="generator" content="Glyph v#{Glyph::VERSION} (http://www.h3rald.com/glyph)" />
|
137
|
-
<style type=\"text/css\">#main { background-color:
|
53
|
+
<style type=\"text/css\">#main { background-color: blue; }</style>
|
138
54
|
</head>
|
139
55
|
</html>
|
140
56
|
}.gsub(/\n|\t/, '')
|
@@ -150,7 +66,7 @@ describe "Macro:" do
|
|
150
66
|
<meta name="author" content="#{Glyph["document.author"]}" />
|
151
67
|
<meta name="copyright" content="#{Glyph["document.author"]}" />
|
152
68
|
<meta name="generator" content="Glyph v#{Glyph::VERSION} (http://www.h3rald.com/glyph)" />
|
153
|
-
<style type=\"text/css\">#main { background-color:
|
69
|
+
<style type=\"text/css\">#main { background-color: blue; }</style>
|
154
70
|
</head>
|
155
71
|
</html>
|
156
72
|
}.gsub(/\n|\t/, '')
|
@@ -162,35 +78,6 @@ describe "Macro:" do
|
|
162
78
|
@p.document.output.gsub(/\n|\t/, '').should == result
|
163
79
|
end
|
164
80
|
|
165
|
-
it "escape" do
|
166
|
-
define_em_macro
|
167
|
-
text = %{This is a test em[This can .[=contain test[macros em[test]]=]]}
|
168
|
-
interpret text
|
169
|
-
@p.document.output.should == %{This is a test <em>This can contain test[macros em[test]]</em>}
|
170
|
-
end
|
171
|
-
|
172
|
-
it "ruby" do
|
173
|
-
interpret "2 + 2 = %[2+2]"
|
174
|
-
@p.document.output.should == %{2 + 2 = 4}
|
175
|
-
interpret "%[lite?]"
|
176
|
-
@p.document.output.should == %{false}
|
177
|
-
interpret "%[def test; end]"
|
178
|
-
end
|
179
|
-
|
180
|
-
it "config" do
|
181
|
-
Glyph["test.setting"] = "TEST"
|
182
|
-
interpret "test.setting = $[test.setting]"
|
183
|
-
@p.document.output.should == %{test.setting = TEST}
|
184
|
-
end
|
185
|
-
|
186
|
-
it "config:" do
|
187
|
-
Glyph["test.setting"] = "TEST"
|
188
|
-
interpret "test.setting = $[test.setting]"
|
189
|
-
@p.document.output.should == %{test.setting = TEST}
|
190
|
-
interpret "test.setting = $:[test.setting|TEST2]$[test.setting]"
|
191
|
-
@p.document.output.should == %{test.setting = TEST2}
|
192
|
-
end
|
193
|
-
|
194
81
|
it "toc" do
|
195
82
|
file_copy Glyph::PROJECT/'../files/document_with_toc.glyph', Glyph::PROJECT/'document.glyph'
|
196
83
|
interpret file_load(Glyph::PROJECT/'document.glyph')
|
@@ -201,9 +88,6 @@ describe "Macro:" do
|
|
201
88
|
<h2 class="toc-header" id="h_toc">Table of Contents</h2>
|
202
89
|
<ol class="toc">
|
203
90
|
<li class=" section"><a href="#h_1">Container section</a></li>
|
204
|
-
<li><ol>
|
205
|
-
<li class=" section"><a href="#h_2">Test Section</a></li>
|
206
|
-
</ol></li>
|
207
91
|
<li class=" section"><a href="#md">Markdown</a></li>
|
208
92
|
</ol>
|
209
93
|
</div>
|
@@ -233,32 +117,30 @@ describe "Macro:" do
|
|
233
117
|
see <a href="#test">Test</a></span> <a id="test">Test</a>}.gsub(/\n|\t/, '')
|
234
118
|
end
|
235
119
|
|
236
|
-
it "
|
237
|
-
interpret "
|
120
|
+
it "image" do
|
121
|
+
interpret "image[@width[90%]@height[90%]@alt[-]ligature.jpg]"
|
238
122
|
@p.document.output.gsub(/\t|\n/, '').should == %{
|
239
|
-
<img src="images/ligature.jpg"
|
240
|
-
width="90%" height="90%" alt="-"/>
|
123
|
+
<img src="images/ligature.jpg" width="90%" height="90%" alt="-" />
|
241
124
|
}.gsub(/\n|\t/, '')
|
242
125
|
end
|
243
126
|
|
244
|
-
it "
|
127
|
+
it "image should link files by absolute or relative path in Lite mode" do
|
245
128
|
result = %{
|
246
|
-
<img src="images/ligature.jpg"
|
247
|
-
width="90%" height="90%" alt="-"/>
|
129
|
+
<img alt="-" src="images/ligature.jpg" width="90%" height="90%" />
|
248
130
|
}.gsub(/\n|\t/, '')
|
249
131
|
Glyph.lite_mode = true
|
250
132
|
Dir.chdir Glyph::PROJECT
|
251
|
-
interpret "
|
133
|
+
interpret "image[@width[90%]@height[90%]images/ligature.jpg]"
|
252
134
|
@p.document.output.gsub(/\t|\n/, '').should == result
|
253
|
-
interpret "
|
135
|
+
interpret "image[@width[90%]@height[90%]#{Glyph::PROJECT}/images/ligature.jpg]"
|
254
136
|
@p.document.output.gsub(/\t|\n/, '').gsub(Glyph::PROJECT.to_s+'/', '').should == result
|
255
137
|
end
|
256
138
|
|
257
|
-
it "
|
258
|
-
interpret "
|
139
|
+
it "figure" do
|
140
|
+
interpret "figure[@alt[ligature]ligature.jpg|Ligature]"
|
259
141
|
@p.document.output.gsub(/\t|\n/, '').should == %{
|
260
142
|
<div class="figure">
|
261
|
-
<img src="images/ligature.jpg" alt="
|
143
|
+
<img src="images/ligature.jpg" alt="ligature" />
|
262
144
|
<div class="caption">Ligature</div>
|
263
145
|
</div>
|
264
146
|
}.gsub(/\n|\t/, '')
|
@@ -267,15 +149,15 @@ describe "Macro:" do
|
|
267
149
|
it "fig should link files by absolute or relative path in Lite mode" do
|
268
150
|
result = %{
|
269
151
|
<div class="figure">
|
270
|
-
<img src="images/ligature.jpg"
|
152
|
+
<img alt="-" src="images/ligature.jpg" />
|
271
153
|
<div class="caption">Ligature</div>
|
272
154
|
</div>
|
273
155
|
}.gsub(/\n|\t/, '')
|
274
156
|
Glyph.lite_mode = true
|
275
157
|
Dir.chdir Glyph::PROJECT
|
276
|
-
interpret "
|
158
|
+
interpret "figure[images/ligature.jpg|Ligature]"
|
277
159
|
@p.document.output.gsub(/\t|\n/, '').should == result
|
278
|
-
interpret "
|
160
|
+
interpret "figure[#{Glyph::PROJECT}/images/ligature.jpg|Ligature]"
|
279
161
|
@p.document.output.gsub(/\t|\n/, '').gsub(Glyph::PROJECT.to_s+'/', '').should == result
|
280
162
|
end
|
281
163
|
|
@@ -295,42 +177,4 @@ describe "Macro:" do
|
|
295
177
|
Glyph['document.draft'] = false
|
296
178
|
end
|
297
179
|
|
298
|
-
it "highlight" do
|
299
|
-
cr = false
|
300
|
-
uv = false
|
301
|
-
begin
|
302
|
-
require 'coderay'
|
303
|
-
cr = true
|
304
|
-
rescue Exception
|
305
|
-
end
|
306
|
-
begin
|
307
|
-
require 'uv'
|
308
|
-
uv = true
|
309
|
-
rescue Exception
|
310
|
-
end
|
311
|
-
code = %{def test_method(a, b)
|
312
|
-
puts a+b
|
313
|
-
end}
|
314
|
-
cr_result = %{<div class=\"CodeRay\"> <div class=\"code\"><pre> <span class=\"r\">def</span>
|
315
|
-
<span class=\"fu\">test_method</span>(a, b) puts a+b <span class=\"r\">end</span></pre></div> </div>}
|
316
|
-
uv_result = %{<pre class=\"iplastic\"> <span class=\"Keyword\">def</span>
|
317
|
-
<span class=\"FunctionName\">test_method</span>(<span class=\"Arguments\">a<span class=\"Arguments\">,</span> b</span>)
|
318
|
-
puts a<span class=\"Keyword\">+</span>b <span class=\"Keyword\">end</span> </pre>}
|
319
|
-
Glyph['highlighters.ultraviolet.theme'] = 'iplastic'
|
320
|
-
check = lambda do |hl, result|
|
321
|
-
Glyph["highlighters.current"] = hl
|
322
|
-
Glyph.debug_mode = true
|
323
|
-
interpret("highlight[=ruby|\n#{code}=]")
|
324
|
-
@p.document.output.gsub(/\s+/, ' ').strip.should == result.gsub(/\s+/, ' ').strip
|
325
|
-
end
|
326
|
-
check.call 'ultraviolet', uv_result if uv
|
327
|
-
check.call 'coderay', cr_result if cr
|
328
|
-
end
|
329
|
-
|
330
|
-
it "macro:" do
|
331
|
-
interpret '%:[e_macro|
|
332
|
-
"Test: #@value"]e_macro[OK!]'
|
333
|
-
@p.document.output.should == "Test: OK!"
|
334
|
-
end
|
335
|
-
|
336
180
|
end
|