zenweb 2.18.1 → 3.0.0.b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +18 -0
  3. data/.gemtest +0 -0
  4. data/History.txt +6 -0
  5. data/Manifest.txt +52 -50
  6. data/README.txt +27 -22
  7. data/Rakefile +8 -9
  8. data/example-site/.isolate.rb +8 -0
  9. data/example-site/Rakefile +32 -0
  10. data/example-site/_config.yml +3 -0
  11. data/example-site/_includes/analytics.html.erb +11 -0
  12. data/example-site/_includes/header.html.erb +3 -0
  13. data/example-site/_includes/page_list_item.html +5 -0
  14. data/example-site/_includes/post_list_item.html +5 -0
  15. data/example-site/_layouts/post.erb +13 -0
  16. data/example-site/_layouts/project.erb +39 -0
  17. data/example-site/_layouts/site.erb +62 -0
  18. data/example-site/about/index.html.md +8 -0
  19. data/example-site/atom.xml.erb +43 -0
  20. data/example-site/blog/2012-01-02-page1.html.md +5 -0
  21. data/example-site/blog/2012-01-03-page2.html.md +5 -0
  22. data/example-site/blog/2012-01-04-page3.html.md +5 -0
  23. data/example-site/blog/_config.yml +1 -0
  24. data/example-site/blog/index.html.erb +19 -0
  25. data/example-site/config.ru +33 -0
  26. data/example-site/css/colors.css.less +71 -0
  27. data/example-site/css/styles.css +223 -0
  28. data/example-site/css/syntax.css +171 -0
  29. data/example-site/img/bg.png +0 -0
  30. data/example-site/index.html.erb +27 -0
  31. data/example-site/js/jquery.js +154 -0
  32. data/example-site/js/site.js +37 -0
  33. data/example-site/pages/index.html.erb +17 -0
  34. data/example-site/pages/nonblogpage.html.md +8 -0
  35. data/example-site/projects/index.html.erb +18 -0
  36. data/example-site/projects/zenweb.html.erb +9 -0
  37. data/example-site/sitemap.xml.erb +24 -0
  38. data/lib/zenweb.rb +12 -0
  39. data/lib/zenweb/config.rb +126 -0
  40. data/lib/zenweb/extensions.rb +51 -0
  41. data/lib/zenweb/page.rb +409 -0
  42. data/lib/zenweb/plugins/disqus.rb +18 -0
  43. data/lib/zenweb/plugins/erb.rb +43 -0
  44. data/lib/zenweb/plugins/google.rb +20 -0
  45. data/lib/zenweb/plugins/less.rb +10 -0
  46. data/lib/zenweb/plugins/markdown.rb +121 -0
  47. data/lib/zenweb/site.rb +237 -0
  48. data/lib/zenweb/tasks.rake +165 -0
  49. data/test/helper.rb +53 -0
  50. data/test/test_zenweb_config.rb +90 -0
  51. data/test/test_zenweb_extensions.rb +33 -0
  52. data/test/test_zenweb_page.rb +381 -0
  53. data/test/test_zenweb_plugins_disqus.rb +41 -0
  54. data/test/test_zenweb_plugins_erb.rb +60 -0
  55. data/test/test_zenweb_plugins_google.rb +38 -0
  56. data/test/test_zenweb_plugins_less.rb +33 -0
  57. data/test/test_zenweb_plugins_markdown.rb +227 -0
  58. data/test/test_zenweb_site.rb +294 -0
  59. metadata +230 -86
  60. metadata.gz.sig +0 -0
  61. data/bin/zenweb +0 -27
  62. data/bin/zenwebpage +0 -66
  63. data/bin/zenwebsite +0 -39
  64. data/design/REQUIREMENTS.txt +0 -52
  65. data/design/ZENWEB_2.txt +0 -69
  66. data/design/heirarchy.png +0 -0
  67. data/design/heirarchy.tgif +0 -311
  68. data/docs/Customizing +0 -76
  69. data/docs/FAQ +0 -12
  70. data/docs/Features +0 -128
  71. data/docs/Presentation +0 -88
  72. data/docs/QuickStart +0 -32
  73. data/docs/Renderers +0 -85
  74. data/docs/SiteMap +0 -13
  75. data/docs/YourOwnWebsite +0 -32
  76. data/docs/index +0 -14
  77. data/docs/metadata.txt +0 -10
  78. data/lib/ZenWeb.rb +0 -850
  79. data/lib/ZenWeb/CalendarRenderer.rb +0 -162
  80. data/lib/ZenWeb/CompactRenderer.rb +0 -45
  81. data/lib/ZenWeb/CompositeRenderer.rb +0 -63
  82. data/lib/ZenWeb/FileAttachmentRenderer.rb +0 -57
  83. data/lib/ZenWeb/FooterRenderer.rb +0 -38
  84. data/lib/ZenWeb/GenericRenderer.rb +0 -143
  85. data/lib/ZenWeb/HeaderRenderer.rb +0 -52
  86. data/lib/ZenWeb/HtmlRenderer.rb +0 -81
  87. data/lib/ZenWeb/HtmlTableRenderer.rb +0 -94
  88. data/lib/ZenWeb/HtmlTemplateRenderer.rb +0 -173
  89. data/lib/ZenWeb/MetadataRenderer.rb +0 -83
  90. data/lib/ZenWeb/RelativeRenderer.rb +0 -97
  91. data/lib/ZenWeb/RubyCodeRenderer.rb +0 -56
  92. data/lib/ZenWeb/SitemapRenderer.rb +0 -56
  93. data/lib/ZenWeb/StandardRenderer.rb +0 -40
  94. data/lib/ZenWeb/StupidRenderer.rb +0 -91
  95. data/lib/ZenWeb/SubpageRenderer.rb +0 -45
  96. data/lib/ZenWeb/TextToHtmlRenderer.rb +0 -219
  97. data/lib/ZenWeb/TocRenderer.rb +0 -60
  98. data/lib/ZenWeb/XXXRenderer.rb +0 -32
  99. data/test/SiteMap +0 -14
  100. data/test/Something +0 -4
  101. data/test/include.txt +0 -3
  102. data/test/index +0 -8
  103. data/test/metadata.txt +0 -10
  104. data/test/ryand/SiteMap +0 -10
  105. data/test/ryand/blah +0 -4
  106. data/test/ryand/blah-blah +0 -4
  107. data/test/ryand/index +0 -52
  108. data/test/ryand/metadata.txt +0 -2
  109. data/test/ryand/stuff/index +0 -4
  110. data/test/test_zenweb.rb +0 -1619
@@ -1,60 +0,0 @@
1
- require 'ZenWeb/GenericRenderer'
2
-
3
- =begin
4
-
5
- = Class TocRenderer
6
-
7
- This renderer generate a table-of-contents at the beginning of the
8
- document in a format compatible with the text-to-html renderer. It
9
- uses the header notation (** to ******) of the text-to-html renderer
10
- to decide what goes in the TOC. It expects your document to be
11
- formatted properly (ie, don't jump from ** to ****--just like in
12
- English class).
13
-
14
- === Methods
15
-
16
- =end
17
-
18
- class TocRenderer < GenericRenderer
19
-
20
- =begin
21
-
22
- --- TocRenderer#render(content)
23
-
24
- Renders the TOC content.
25
-
26
- =end
27
-
28
- def render(content)
29
-
30
- toc = [
31
- "** <A NAME=\"0\">Contents:</A>\n",
32
- "\n",
33
- "+ <A HREF=\"\#0\">Contents</A>\n" ]
34
- count = 1
35
-
36
- content.each_line { | line |
37
- if line =~ /^(\*\*+)\s+(.*)/ then
38
- header = $1
39
- text = $2
40
-
41
- text = text.sub(/:$/, '')
42
-
43
- level = header.length - 2
44
-
45
- toc.push(("\t" * level) + "+ <A HREF=\"\##{count}\">#{text}</A>\n")
46
-
47
- push "#{header} <A NAME=\"#{count}\">#{text}</A>\n"
48
- # " [<A HREF=\"\#0\">toc</A>]\n"
49
-
50
- count += 1
51
- else
52
- push line
53
- end
54
- }
55
-
56
- unshift(toc) if toc.length > 3
57
-
58
- return self.result
59
- end
60
- end
@@ -1,32 +0,0 @@
1
- # this is a simple template. Globally replace XXX with the name of
2
- # your renderer and then go fill in YYY with the appropriate content.
3
-
4
- require 'ZenWeb/GenericRenderer'
5
-
6
- =begin
7
-
8
- = Class XXXRenderer
9
-
10
- YYY
11
-
12
- === Methods
13
-
14
- =end
15
-
16
- class XXXRenderer < GenericRenderer
17
-
18
- =begin
19
-
20
- --- XXXRenderer#render(content)
21
-
22
- YYY
23
-
24
- =end
25
-
26
- def render(content)
27
- # YYY
28
- push(content)
29
- return self.result
30
- end
31
-
32
- end
data/test/SiteMap DELETED
@@ -1,14 +0,0 @@
1
- #
2
- # Test Website v. 1.0.0
3
- #
4
- # 'title' = 'Sitemap'
5
- # 'renderers' = [ 'SitemapRenderer', 'StandardRenderer' ]
6
-
7
- /index.html
8
- /SiteMap.html
9
- /Something.html
10
- /~ryand/index.html
11
- /~ryand/blah.html
12
- /~ryand/stuff/index.html
13
-
14
-
data/test/Something DELETED
@@ -1,4 +0,0 @@
1
- # 'title' = 'Something'
2
-
3
- this is the url: /Something.html
4
-
data/test/include.txt DELETED
@@ -1,3 +0,0 @@
1
- #metadata = false
2
- This is some #{key1}
3
- common text.
data/test/index DELETED
@@ -1,8 +0,0 @@
1
- # "title" = "My Website"
2
- # "subtitle" = "Subtitle"
3
-
4
- # this is a normal comment
5
-
6
- # "key4" = 69
7
-
8
- this is the url: /index.html
data/test/metadata.txt DELETED
@@ -1,10 +0,0 @@
1
- "key3" = "another string"
2
-
3
- "key1" = 24
4
-
5
- "renderers" = [ 'StandardRenderer', 'RelativeRenderer' ]
6
-
7
- 'author' = 'Ryan Davis'
8
- # 'banner' = 'some sort of link to a banner image'
9
- 'copyright' = '1996-2001, Zen Spider Software'
10
- 'email' = 'mailto:ryand-web@zenspider.com'
data/test/ryand/SiteMap DELETED
@@ -1,10 +0,0 @@
1
- #
2
- # Test Website v. 1.0.0
3
- #
4
- # 'title' = 'Sitemap'
5
- # 'renderers' = [ 'SitemapRenderer', 'TextToHtmlRenderer', 'HtmlTemplateRenderer' ]
6
-
7
- /~ryand/index.html
8
- /~ryand/SiteMap.html
9
- /~ryand/blah.html
10
- /~ryand/stuff/index.html
data/test/ryand/blah DELETED
@@ -1,4 +0,0 @@
1
- # 'title' = 'blah'
2
-
3
- this is the url: /~ryand/blah.html
4
-
data/test/ryand/blah-blah DELETED
@@ -1,4 +0,0 @@
1
- # 'title' = 'blah'
2
-
3
- this is the url: /~ryand/blah.html
4
-
data/test/ryand/index DELETED
@@ -1,52 +0,0 @@
1
- # 'title' = "Ryan's Homepage"
2
- # 'subtitle' = "Version 2.0"
3
- # 'footer' = '<P>This is my footer, jive turkey</P>'
4
-
5
- Everything is separated by paragraphs (two or more returns).
6
-
7
- ** Head 2
8
-
9
- *** Head 3
10
-
11
- **** Head 4
12
-
13
- ***** Head 5
14
-
15
- ****** Head 6
16
-
17
- + Lists (should have two items).
18
- + Continuted Lists.
19
-
20
- + Another List (should have a sub list).
21
- + With a sub-list
22
- + another item
23
-
24
- = Ordered lists
25
- = are cool
26
- = Especially when you make ordered sublists
27
-
28
- %- Term 1
29
- %= Def 1
30
- %- Term 2
31
- %= Def 2
32
-
33
- Glossary lookups for #{key1} and #{key2} (see metadata.txt for a hint).
34
- #{key99} should not look up.
35
-
36
- ---
37
-
38
- Paragraphs can contain http://www.ZenSpider.com/ZSS/ZenWeb/ and mailto:zss@ZenSpider.com and they will automatically be converted. Don't forget less-than "\<" \& greater-than "\>", but only if backslashed.
39
-
40
- Supports <A HREF="http://www.yahoo.com">Unaltered urls</A> as well.
41
-
42
- Likewise, two lines side by side
43
- are considered one paragraph. Supports <I>Embedded HTML</I>.
44
-
45
- ===
46
-
47
- PRE blocks are paragraphs that are indented two spaces on each line.
48
- The two spaces will be stripped, and all other indentation will be left
49
- alone.
50
- this allows me to put things like code examples in and retain
51
- their formatting.
52
-
@@ -1,2 +0,0 @@
1
- "key1" = 42
2
- "key2" = "some string"
@@ -1,4 +0,0 @@
1
- # 'title' = 'my stuff'
2
-
3
- this is the url: /~ryand/stuff/index.html
4
-
data/test/test_zenweb.rb DELETED
@@ -1,1619 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- $TESTING = TRUE
4
-
5
- require 'ZenWeb'
6
- require 'ZenWeb/SitemapRenderer'
7
- require 'ZenWeb/TocRenderer'
8
- require 'ZenWeb/StupidRenderer'
9
- require 'ZenWeb/FooterRenderer'
10
-
11
- require 'minitest/autorun'
12
-
13
- # TODO: get rid of all calls to renderContent
14
-
15
- # this is used across different classes for html list tests
16
- $text_list_data = "+ a\n\t+ a1\n\t\t+ a1a\n+ b\n\t+ b1\n\t\t+ b1a\n\t\t+ b1b\n+ c\n\t+ c1\n\t\t+ c1a\n\t+ c2\n\t\t+ c2a\n\t\t+ c2b\n\t\t+ c2c\n\t\t+ c2d"
17
- $array_list_data = ['a', ['a1', ['a1a']], 'b', ['b1', ['b1a', 'b1b' ]], 'c', ['c1', ['c1a'], 'c2', ['c2a', 'c2b', 'c2c', 'c2d']]]
18
- $html_list_data = "<UL>\n<LI>a\n<UL>\n<LI>a1\n<UL>\n<LI>a1a</LI>\n</UL>\n</LI>\n</UL>\n</LI>\n<LI>b\n<UL>\n<LI>b1\n<UL>\n<LI>b1a</LI>\n<LI>b1b</LI>\n</UL>\n</LI>\n</UL>\n</LI>\n<LI>c\n<UL>\n<LI>c1\n<UL>\n<LI>c1a</LI>\n</UL>\n</LI>\n<LI>c2\n<UL>\n<LI>c2a</LI>\n<LI>c2b</LI>\n<LI>c2c</LI>\n<LI>c2d</LI>\n</UL>\n</LI>\n</UL>\n</LI>\n</UL>\n"
19
-
20
- class String
21
- def uberstrip
22
- (self.split($/).map {|x| x.strip}).join($/)
23
- end
24
- end
25
-
26
- def shutupwhile_18
27
- $dead = File.open("/dev/null", "w")
28
-
29
- $stdout.flush
30
- $stderr.flush
31
-
32
- oldstdout = $stdout
33
- oldstderr = $stderr
34
-
35
- $stdout = $dead
36
- $stderr = $dead
37
-
38
- yield
39
-
40
- $stdout.flush
41
- $stderr.flush
42
-
43
- $stdout = oldstdout
44
- $stderr = oldstderr
45
- end
46
-
47
- def shutupwhile_16
48
- $dead = File.open("/dev/null", "w")
49
-
50
- $stdout.flush
51
- $stderr.flush
52
- $defout.flush
53
-
54
- oldstdout = $stdout.dup
55
- oldstderr = $stderr.dup
56
-
57
- $stdout.reopen($dead)
58
- $stderr.reopen($dead)
59
- $defout.reopen($dead)
60
-
61
- yield
62
-
63
- $stdout.flush
64
- $stderr.flush
65
- $defout.flush
66
-
67
- $stdout = oldstdout
68
- $stderr = oldstderr
69
- $defout.reopen($stdout)
70
- end
71
-
72
- if RUBY_VERSION.sub(/(\d+)\.(\d+).*/, '\1\2').to_i <= 16 then
73
- alias :shutupwhile :shutupwhile_16
74
- else
75
- alias :shutupwhile :shutupwhile_18
76
- end
77
-
78
- class ZenTestCase < MiniTest::Unit::TestCase # ZenTest SKIP
79
-
80
- def setup
81
- $stderr.puts name if $DEBUG
82
- @datadir = "test"
83
- @htmldir = "testhtml"
84
- @sitemapUrl = "/SiteMap.html"
85
- @url = "/~ryand/index.html"
86
- @web = ZenWebsite.new(@sitemapUrl, @datadir, @htmldir)
87
- @doc = @web[@url]
88
- end
89
-
90
- def teardown
91
- if (test(?d, @htmldir)) then
92
- `rm -rf #{@htmldir}`
93
- end
94
- end
95
-
96
- def test_null
97
- # shuts up test::unit's stupid logic
98
- end
99
- end
100
-
101
- ############################################################
102
- # ZenWebsite:
103
-
104
- class TestZenWebsite < ZenTestCase
105
-
106
- def test_initialize_bad_sitemap
107
- util_initialize("/doesn't exist", @datadir, @htmldir)
108
- end
109
-
110
- def test_initialize_missing_datadir
111
- util_initialize(@sitemapUrl, "/doesn't exist", @htmldir)
112
- end
113
-
114
- def test_initialize_missing_leading_slash
115
- # missing a leading slash
116
- util_initialize("SiteMap.html", @datadir, @htmldir)
117
- end
118
-
119
- def test_initialize_tilde
120
- # this should work fine
121
- util_initialize("/~ryand/SiteMap.html", @datadir, @htmldir, false)
122
- end
123
-
124
- def util_initialize(sitemap_url, data_dir, html_dir, should_fail=true)
125
- if (should_fail) then
126
- assert_raises(ArgumentError, "Must throw an ArgumentError") {
127
- ZenWebsite.new(sitemap_url, data_dir, html_dir)
128
- }
129
- else
130
- ZenWebsite.new(sitemap_url, data_dir, html_dir)
131
- end
132
- end
133
-
134
- def util_checkContent(path, expected)
135
- assert(test(?f, path),
136
- "File '#{path}' must exist")
137
- file = IO.readlines(path).join('')
138
- refute_nil(file.index(expected),
139
- "File '#{path}' must have correct content")
140
- end
141
-
142
- def test_renderSite
143
- @web.renderSite
144
-
145
- assert(test(?d, @htmldir),
146
- "HTML directory must be created by renderSite")
147
-
148
- util_checkContent(@htmldir + "/index.html",
149
- "this is the url: /index.html")
150
-
151
- util_checkContent(@htmldir + "/SiteMap.html",
152
- "/~ryand/stuff/index.html")
153
-
154
- util_checkContent(@htmldir + "/Something.html",
155
- "this is the url: /Something.html")
156
-
157
- util_checkContent(@htmldir + "/ryand/index.html",
158
- "Everything is separated by paragraphs")
159
-
160
- util_checkContent(@htmldir + "/ryand/blah.html",
161
- "this is the url: /~ryand/blah.html")
162
-
163
- util_checkContent(@htmldir + "/ryand/stuff/index.html",
164
- "this is the url: /~ryand/stuff/index.html")
165
-
166
- end
167
-
168
- def test_index
169
- refute_nil(@web.sitemap,
170
- "index accessor must return the sitemap")
171
- assert_nil(@web["doesn't exist"],
172
- "index accessor must return nil for bad urls")
173
- end
174
-
175
- def test_datadir
176
- datadir = @web.datadir
177
- assert(datadir.instance_of?(String),
178
- "ZenWebsite's htmldir must be instantiated")
179
- assert(test(?d, datadir),
180
- "ZenWebsite's datadir must be a directory")
181
- end
182
-
183
- # WARN: I think these tests are too prescriptive
184
- # REFACTOR: make an OrderedHash
185
- def test_doc_order
186
- doc_order = @web.doc_order
187
- assert_kind_of(Array, doc_order)
188
- assert(doc_order.size > 0, "doc_order better not be empty")
189
- end
190
-
191
- def test_documents
192
- documents = @web.documents
193
- assert_kind_of(Hash, documents)
194
- assert(documents.size > 0, "Documents better not be empty")
195
- refute_nil(documents["/SiteMap.html"], "SiteMap must exist")
196
- end
197
-
198
- def test_htmldir
199
- htmldir = @web.htmldir
200
- refute_nil(htmldir, "htmldir must be initialized")
201
- assert_instance_of(String, htmldir)
202
- end
203
-
204
- def test_sitemap
205
- sitemap = @web.sitemap
206
- assert(sitemap.instance_of?(ZenSitemap),
207
- "ZenWebsite's Sitemap must be instantiated")
208
- end
209
-
210
- end
211
-
212
- ############################################################
213
- # ZenDocument
214
-
215
- class TestZenDocument < ZenTestCase
216
-
217
- def setup
218
- super
219
- @expected_datapath = "test/ryand/index"
220
- @expected_htmlpath = "testhtml/ryand/index.html"
221
- @expected_dir = "test/ryand"
222
- @expected_subpages = [ '/~ryand/blah.html', '/~ryand/stuff/index.html' ]
223
- end
224
-
225
- def test_initialize_good_url
226
- ZenDocument.new("/Something.html", @web)
227
- end
228
-
229
- def test_initialize_missing_ext
230
- ZenDocument.new("/Something", @web)
231
- end
232
-
233
- def test_initialize_missing_slash
234
- assert_raises(ArgumentError) {
235
- ZenDocument.new("Something.html", @web)
236
- }
237
- end
238
-
239
- def test_initialize_bad_url
240
- assert_raises(ArgumentError) {
241
- ZenDocument.new("/missing.html", @web)
242
- }
243
- end
244
-
245
- def test_initialize_nil_website
246
- assert_raises(ArgumentError) {
247
- ZenDocument.new("Something.html", nil)
248
- }
249
- end
250
-
251
- def test_subpages
252
- @web.renderSite
253
- @doc = @web[@url]
254
- assert_equal(@expected_subpages,
255
- @doc.subpages.sort)
256
- end
257
-
258
- def test_render
259
- file = @doc.htmlpath
260
- if (test(?f, file)) then
261
- File.delete(file)
262
- end
263
-
264
- @doc.render
265
-
266
- assert(test(?f, file), "document must render in correct location")
267
- end
268
-
269
- def test_renderContent_bad
270
- @doc = @web.sitemap
271
- @doc['renderers'] = [ 'NonExistantRenderer' ]
272
-
273
- assert_raises(NotImplementedError,
274
- "renderContent must throw a NotImplementedError") {
275
- @doc.renderContent
276
- }
277
- end
278
-
279
- def test_newerThanTarget_missing
280
- # setup, delete target file, call function. Must return true
281
-
282
- if not test ?f, @doc.datapath then
283
- puts "datafile does not exist"
284
- end
285
-
286
- if test ?f, @doc.htmlpath then
287
- File.delete(@doc.htmlpath)
288
- end
289
-
290
- assert(@doc.newerThanTarget,
291
- "doc must be newer because target is missing")
292
- end
293
-
294
- def test_newerThanTarget_yes
295
- util_newerThanTarget(true)
296
- end
297
-
298
- def test_newerThanTarget_no
299
- util_newerThanTarget(false)
300
- end
301
-
302
- def test_newerThanTarget_sitemap
303
- util_newerThanTarget(false, true)
304
- util_newerThanTarget(true, true)
305
- end
306
-
307
- def util_newerThanTarget(page_is_newer, sitemap_is_newer=false)
308
-
309
- @web.renderSite
310
-
311
- doc_htmlpath = @doc.htmlpath
312
- doc_datapath = @doc.datapath
313
-
314
- assert(test(?f, doc_htmlpath),
315
- "htmlpath must exist at #{doc_htmlpath}")
316
- assert(test(?f, doc_datapath),
317
- "datapath must exist at #{doc_datapath}")
318
-
319
- time_old = '01010000'
320
- time_new = '01020000'
321
-
322
- # unify times
323
- `touch -t #{time_old} #{doc_datapath} #{doc_htmlpath}`
324
-
325
- # update page
326
- if page_is_newer then `touch -t #{time_new} #{doc_datapath}` end
327
-
328
- # test
329
- if (page_is_newer) then
330
- assert(@doc.newerThanTarget,
331
- "doc must be newer: #{page_is_newer} #{sitemap_is_newer}")
332
- else
333
- assert(! @doc.newerThanTarget,
334
- "doc must not be newer")
335
- end
336
- end
337
-
338
- def test_parentURL
339
- # 1 level deep
340
- @doc = ZenDocument.new("/Something.html", @web)
341
- assert_equal("/index.html", @doc.parentURL())
342
-
343
- # 2 levels deep - index
344
- @doc = ZenDocument.new("/ryand/index.html", @web)
345
- assert_equal("/index.html", @doc.parentURL())
346
-
347
- # 2 levels deep
348
- # yes, using metadata.txt is cheating, but it is a valid file...
349
- @doc = ZenDocument.new("/ryand/metadata.txt", @web)
350
- assert_equal("/ryand/index.html", @doc.parentURL())
351
-
352
- # 1 levels deep with a tilde
353
- @doc = ZenDocument.new("/~ryand/index.html", @web)
354
- assert_equal("/index.html", @doc.parentURL())
355
-
356
- # 2 levels deep with a tilde
357
- @doc = ZenDocument.new("/~ryand/stuff/index.html", @web)
358
- assert_equal("/~ryand/index.html", @doc.parentURL())
359
- end
360
-
361
- def test_parent
362
- parent = @doc.parent
363
-
364
- refute_nil(parent,
365
- "Parent must not be nil")
366
-
367
- assert_equal("/index.html", parent.url,
368
- "Parent url must be correct")
369
- end
370
-
371
- def test_dir
372
- assert_equal(@expected_dir, @doc.dir)
373
- end
374
-
375
- def test_datapath
376
- assert_equal(@expected_datapath, @doc.datapath)
377
- end
378
-
379
- def test_htmlpath
380
- assert_equal(@expected_htmlpath, @doc.htmlpath)
381
- end
382
-
383
- def test_metadata_lookup
384
- assert_nil(@doc['nothing'])
385
-
386
- @doc = ZenDocument.new("/Something.html", @web)
387
- assert_equal(['StandardRenderer', 'RelativeRenderer'],
388
- @doc['renderers'])
389
- end
390
-
391
- def test_addSubpage_bad
392
- assert_raises(ArgumentError, "addSubpage must raise if arg wrong type") {
393
- @doc.addSubpage []
394
- }
395
- assert_raises(ArgumentError, "subpage must be a url, not a page") {
396
- @doc.addSubpage @doc
397
- }
398
- end
399
-
400
- def test_addSubpage_different
401
- oldpages = @doc.subpages.clone
402
- url = "/Something.html"
403
- @doc.addSubpage(url)
404
- newpages = @doc.subpages
405
- assert(newpages.size == oldpages.size + 1,
406
- "Page must grow the list of subpages")
407
- found = newpages.find {|p| p == url }
408
- refute_nil(found, "Page must be contained in new list")
409
- end
410
-
411
- def test_addSubpage_same
412
- oldpages = @doc.subpages.clone
413
- url = @url
414
- @doc.addSubpage(url)
415
- newpages = @doc.subpages
416
- assert(newpages.size == oldpages.size,
417
- "Page must NOT grow the list of subpages")
418
- found = newpages.find {|p| p == url }
419
- assert_nil(found, "Page must be contained in new list")
420
- end
421
-
422
- def test_content
423
- content = @doc.content
424
- refute_nil(content, "Content must not be nil")
425
- assert_instance_of(String, content)
426
- end
427
-
428
- def test_content=()
429
- orig_content = @doc.content
430
- @doc.content = "blah"
431
- new_content = @doc.content
432
- refute_nil(new_content, "Content must not be nil")
433
- assert_instance_of(String, new_content)
434
- assert_equal("blah", new_content)
435
- end
436
-
437
- def test_datadir # same as TestZenWebsite#test_datadir since it's a delegate
438
- datadir = @web.datadir
439
- assert(datadir.instance_of?(String),
440
- "ZenWebsite's htmldir must be instantiated")
441
- assert(test(?d, datadir),
442
- "ZenWebsite's datadir must be a directory")
443
- end
444
-
445
- def test_fulltitle
446
- @doc['title'] = "Title"
447
- @doc['subtitle'] = "Subtitle"
448
- assert_equal("Title: Subtitle", @doc.fulltitle)
449
- end
450
-
451
- def test_htmldir # same as TestZenWebsite#test_htmldir since it's a delegate
452
- htmldir = @doc.htmldir
453
- refute_nil(htmldir, "htmldir must be initialized")
454
- assert_instance_of(String, htmldir)
455
- end
456
-
457
- def test_index
458
- result = @doc["renderers"]
459
- refute_nil(result, "renderers must exist for document")
460
- assert_instance_of(Array, result)
461
- end
462
-
463
- def test_index_equals
464
- newrenderers = ["Something"]
465
- @doc["renderers"] = newrenderers
466
- metadata = @doc.metadata
467
- refute_nil(metadata, "metadata must not be nil")
468
- assert_instance_of(Metadata, metadata)
469
- result = metadata["renderers"]
470
- refute_nil(result, "renderers must exist in sitemap")
471
- assert_instance_of(Array, result)
472
- refute_nil(result.find {|x| x == "Something"})
473
- end
474
-
475
- def test_metadata
476
- metadata = @doc.metadata
477
- refute_nil(metadata, "metadata must not be nil")
478
- assert_instance_of(Metadata, metadata)
479
- result = metadata["renderers"]
480
- refute_nil(result, "renderers must exist in sitemap")
481
- assert_instance_of(Array, result)
482
- end
483
-
484
- def test_parseMetadata
485
- @doc = ZenDocument.new('/index.html', @web)
486
-
487
- # metadata should be nil at this point.
488
- # content should be an empty string
489
- # as soon as we ask for metadata, it should
490
- # parse... /index.html has 'key4' defined in
491
- # it.
492
-
493
- assert_equal('', @doc.content)
494
- refute_nil(@doc.metadata, 'metadata should always be non-nil')
495
- assert(@doc.content.length > 0, 'file should be parsed now')
496
- assert_equal(69, @doc['key4'])
497
- end
498
-
499
- def test_url
500
- url = @doc.url
501
- refute_nil(url, "Each document must know it's url")
502
- assert_kind_of(String, url)
503
- assert_equal(@url, url)
504
- end
505
-
506
- def test_website
507
- website = @doc.website
508
- refute_nil(website, "Each document must know of it's website")
509
- assert_kind_of(ZenWebsite, website)
510
- end
511
- end
512
-
513
- ############################################################
514
- # ZenSitemap
515
-
516
- class TestZenSitemap < TestZenDocument
517
-
518
- def setup
519
- super
520
- @url = @sitemapUrl
521
- @web = ZenWebsite.new(@url, "test", "testhtml")
522
- @doc = @web[@url]
523
-
524
- @expected_datapath = "test/SiteMap"
525
- @expected_dir = "test"
526
- @expected_htmlpath = "testhtml/SiteMap.html"
527
- @expected_subpages = []
528
-
529
- @expected_docs = ([ "/index.html",
530
- "/SiteMap.html",
531
- "/Something.html",
532
- "/~ryand/index.html",
533
- "/~ryand/blah.html",
534
- "/~ryand/stuff/index.html"])
535
- end
536
-
537
- def test_documents
538
- docs = @doc.documents
539
-
540
- @expected_docs.each { | url |
541
- assert(docs.has_key?(url),
542
- "Sitemap's documents must include #{url}")
543
-
544
- assert_equal(url != "/SiteMap.html" ? ZenDocument : ZenSitemap,
545
- docs[url].class,
546
- "Document #{url} must be the correct class")
547
- }
548
- end
549
-
550
- def test_doc_order
551
- assert_equal(@expected_docs,
552
- @doc.doc_order,
553
- "Sitemap's document order must be correct")
554
- end
555
-
556
- # HACK: relocate to SitemapRenderer
557
- # def test_renderContent
558
- # expected = "<H2>There are 6 pages in this website.</H2>\n<HR CLASS=\"thick\">\n\n<UL>\n <LI><A HREF=\"/index.html\">My Website: Subtitle</A></LI>\n <LI><A HREF=\"/SiteMap.html\">Sitemap: There are 6 pages in this website.</A></LI>\n <LI><A HREF=\"/Something.html\">Something</A></LI>\n <LI><A HREF=\"/~ryand/index.html\">Ryan's Homepage: Version 2.0</A></LI>\n <UL>\n <LI><A HREF=\"/~ryand/blah.html\">blah</A></LI>\n <LI><A HREF=\"/~ryand/stuff/index.html\">my stuff</A></LI>\n </UL>\n</UL>"
559
- #
560
- # refute_nil(@content.index(expected) > 0,
561
- # "Must render some form of HTML")
562
- # end
563
- end
564
-
565
- ############################################################
566
- # Metadata
567
-
568
- class TestMetadata < ZenTestCase
569
-
570
- def setup
571
- @hash = Metadata.new("test/ryand")
572
- end
573
-
574
- def teardown
575
- end
576
-
577
- def test_initialize_good
578
- begin
579
- @hash = Metadata.new("test/ryand", "/")
580
- rescue
581
- assert_fail("Good init shall not throw an exception")
582
- else
583
- # this is good
584
- end
585
- end
586
-
587
- def test_initialize_bad_path
588
- assert_raises(ArgumentError, "bad path shall throw an ArgumentError") {
589
- @hash = Metadata.new("bad_path", "/")
590
- }
591
- end
592
-
593
- def test_initialize_bad_top
594
- assert_raises(ArgumentError, "bad top shall throw an ArgumentError") {
595
- @hash = Metadata.new("test/ryand", "somewhereelse")
596
- }
597
- end
598
-
599
- def test_initialize_too_deep_top
600
- assert_raises(ArgumentError, "deeper top shall throw an ArgumentError") {
601
- @hash = Metadata.new("test/ryand", "test/ryand/stuff")
602
- }
603
- end
604
-
605
- def test_loadFromDirectory
606
- @hash = Metadata.new("test")
607
- assert_equal(24, @hash["key1"])
608
- @hash.loadFromDirectory("test/ryand", '.')
609
- assert_equal(42, @hash["key1"])
610
- end
611
-
612
- def test_load
613
- # initial load should be
614
- @hash = Metadata.new("test")
615
- assert_equal(24, @hash["key1"])
616
- @hash.load("test/ryand/metadata.txt")
617
- assert_equal(42, @hash["key1"])
618
- end
619
-
620
- def test_index_child
621
- # this asserts that the values in the child are correct.
622
- assert_equal(42, @hash["key1"])
623
- assert_equal("some string", @hash["key2"])
624
- assert_equal("another string", @hash["key3"])
625
- end
626
-
627
- def test_index_parent
628
- # this is defined in the parent, but not the child
629
- assert_equal([ 'StandardRenderer', 'RelativeRenderer' ],
630
- @hash["renderers"])
631
- end
632
-
633
- end
634
-
635
- ############################################################
636
- # All Renderer Tests:
637
-
638
- class ZenRendererTest < ZenTestCase
639
-
640
- def setup
641
- super
642
-
643
- if self.class.name =~ /Test(\w+Renderer)$/ then
644
- rendererclass = $1
645
- require "ZenWeb/#{rendererclass}"
646
- theClass = Module.const_get(rendererclass)
647
- @renderer = theClass.new(@doc)
648
- end
649
- end
650
-
651
- def util_render(expected, input, message="")
652
- assert_equal(expected, @renderer.render(input), message)
653
- end
654
- end
655
-
656
- class TestGenericRenderer < ZenRendererTest
657
-
658
- def test_push
659
- assert_equal('', @renderer.result)
660
- @renderer.push("something")
661
- assert_equal('something', @renderer.result(false))
662
- @renderer.push(["completely", "different"])
663
- assert_equal('somethingcompletelydifferent', @renderer.result)
664
- end
665
-
666
- def test_unshift
667
- assert_equal('', @renderer.result)
668
- @renderer.unshift("something")
669
- assert_equal('something', @renderer.result(false))
670
- @renderer.unshift(["completely", "different"])
671
- assert_equal('completelydifferentsomething', @renderer.result)
672
- end
673
-
674
- def test_render
675
- assert_equal('', @renderer.result)
676
- assert_equal('something', @renderer.render('something'))
677
- assert_equal('', @renderer.result)
678
- end
679
-
680
- def test_result
681
- @renderer.push('this is some text')
682
- assert_equal('this is some text', @renderer.result)
683
- end
684
-
685
- def util_scan_region(expected, input, &block)
686
- @renderer.scan_region(input, /<start>/, /<end>/, &block)
687
- assert_equal expected, @renderer.result
688
- end
689
-
690
- def test_scan_region_miss
691
- s = "this is some text\n"
692
- util_scan_region(s, s) do |region, context|
693
- flunk "There is no region"
694
- end
695
- end
696
-
697
- def test_scan_region_one_line
698
- s = 'text <start>region<end> text'
699
-
700
- util_scan_region('', s) do |region, context|
701
- assert_equal s, region, "Region must match entire line"
702
- end
703
- end
704
-
705
- def test_scan_region_single
706
- s = "text\n<start>\nregion\n<end>\ntext"
707
- e = "text\nfound\ntext"
708
- util_scan_region(e, s) do |region, context|
709
- @renderer.push "found\n" unless context == :START or context == :END
710
- end
711
- end
712
-
713
- def ztest_scan_region_multiple
714
- end
715
-
716
- end
717
-
718
- class TestCompositeRenderer < ZenRendererTest
719
- def test_renderers
720
- newrenderer = StupidRenderer.new(@doc)
721
- assert_equal([], @renderer.renderers)
722
- @renderer.addRenderer(newrenderer)
723
- assert_equal([newrenderer], @renderer.renderers)
724
- end
725
-
726
- def test_addRenderer
727
- @content = @doc.renderContent # HACK!!! Quells NameError: uninitialized constant TestCompositeRenderer::FooterRenderer (no idea how)
728
- renderer = CompositeRenderer.new(@doc)
729
- originalRenderers = renderer.renderers.clone
730
- assert_raises(ArgumentError, "Must throw an ArgumentError if passed non-renderer") {
731
- renderer.addRenderer([])
732
- }
733
- assert_raises(ArgumentError, "Must throw an ArgumentError if passed nil") {
734
- renderer.addRenderer(nil)
735
- }
736
-
737
- newRenderer = FooterRenderer.new(@doc)
738
- renderer.addRenderer(newRenderer)
739
- newRenderers = renderer.renderers
740
-
741
- assert(originalRenderers.size + 1 == newRenderers.size,
742
- "Renderer addition must have grown array")
743
- assert_equal(newRenderer, newRenderers.last,
744
- "Renderer must be in array")
745
- end
746
-
747
- def test_render_empty
748
- text = "this is some text"
749
- assert_equal(text, @renderer.render(text))
750
- end
751
-
752
- def test_render_one
753
- @doc['stupidmethod'] = 'strip'
754
- @renderer.addRenderer(StupidRenderer.new(@doc))
755
- text = "this is some text"
756
- assert_equal('ths s sm txt', @renderer.render(text))
757
- end
758
-
759
- def test_render_many
760
- @doc['stupidmethod'] = 'strip'
761
- @doc['footer'] = 'footer'
762
- @renderer.addRenderer(StupidRenderer.new(@doc))
763
- @renderer.addRenderer(FooterRenderer.new(@doc))
764
- text = "this is some text"
765
- assert_equal('ths s sm txtfooter', @renderer.render(text))
766
- end
767
- end
768
-
769
- class TestStandardRenderer < ZenRendererTest
770
- def test_initialize
771
- renderers = @renderer.renderers
772
- assert_equal(5, renderers.size)
773
- # TODO: AAAAAAHHHHHHHH!
774
- assert_instance_of(SubpageRenderer, renderers[0])
775
- assert_instance_of(MetadataRenderer, renderers[1])
776
- assert_instance_of(TextToHtmlRenderer, renderers[2])
777
- assert_instance_of(HtmlTemplateRenderer, renderers[3])
778
- assert_instance_of(FooterRenderer, renderers[4])
779
- end
780
- end
781
-
782
- class TestFileAttachmentRenderer < ZenRendererTest
783
-
784
- def setup
785
- super
786
- path = @doc.htmlpath
787
- dir = File.dirname(path)
788
-
789
- unless (test(?d, dir)) then
790
- FileUtils.mkdir_p dir
791
- end
792
- end
793
-
794
- # TODO: push this as far up as possible
795
- def test_nothing
796
- s = "blah blah\n\nblah blah\n\nblah blah\n\nblah blah"
797
- util_render s, s, "FAR must not modify text that doesn't contain file tags"
798
- end
799
-
800
- # TODO: refactor
801
- def test_simple
802
- f = "line 1\nline 2\nline 3\n"
803
- f2 = " line 1\n line 2\n line 3"
804
- s = "blah blah\n\n<file name=\"something.txt\">\n#{f}</file>\n\nblah blah"
805
- e = "blah blah\n\n#{f2}\n\n<A HREF=\"something.txt\">Download something.txt</A>\n\nblah blah"
806
- util_render e, s, "FAR must render the content correctly"
807
- assert test(?f, 'testhtml/ryand/something.txt'), "File must exist or you suck"
808
- assert_equal f, File.new('testhtml/ryand/something.txt').read
809
- end
810
-
811
- def test_eric_is_a_fucktard
812
- f = "line 1\n\nline 2\nline 3\n"
813
- f2 = " line 1\n \n line 2\n line 3"
814
- s = "blah blah\n\n<file name=\"something.txt\">\n#{f}</file>\n\nblah blah"
815
- e = "blah blah\n\n#{f2}\n\n<A HREF=\"something.txt\">Download something.txt</A>\n\nblah blah"
816
- util_render e, s, "FAR must render the content correctly, even if eric is a fucktard"
817
- assert test(?f, 'testhtml/ryand/something.txt'), "File must exist or you suck"
818
- assert_equal f, File.new('testhtml/ryand/something.txt').read
819
- end
820
-
821
- end
822
-
823
- class TestHtmlRenderer < ZenRendererTest
824
-
825
- def test_array2html_one_level
826
- assert_equal("<UL>\n <LI>line 1</LI>\n <LI>line 2</LI>\n</UL>\n",
827
- @renderer.array2html(["line 1", "line 2"]))
828
- end
829
-
830
- def test_array2html_multi_level
831
- assert_equal($html_list_data.uberstrip,
832
- @renderer.array2html($array_list_data).uberstrip)
833
- end
834
-
835
- def test_array2html_one_level_ordered
836
- assert_equal("<OL>\n <LI>line 1</LI>\n <LI>line 2</LI>\n</OL>\n",
837
- @renderer.array2html(["line 1", "line 2"], true))
838
- end
839
-
840
- def test_array2html_multi_level_ordered
841
- assert_equal($html_list_data.gsub("UL", "OL").uberstrip,
842
- @renderer.array2html($array_list_data, true).uberstrip)
843
- end
844
-
845
- def test_hash2html
846
- assert_equal("<DL>\n <DT>key3</DT>\n <DD>val3</DD>\n\n <DT>key2</DT>\n <DD>val2</DD>\n\n <DT>key1</DT>\n <DD>val1</DD>\n\n</DL>\n",
847
- @renderer.hash2html({ 'key3' => 'val3',
848
- 'key2' => 'val2',
849
- 'key1' => 'val1' },
850
- [ 'key3', 'key2', 'key1' ]))
851
- end
852
-
853
- def test_render
854
- assert_raises(RuntimeError, "should raise a subclass responsibity error") {
855
- @renderer.render("anything")
856
- }
857
- end
858
-
859
- end
860
-
861
- class TestHtmlTemplateRenderer < ZenRendererTest
862
-
863
- # TODO: need to test the following: html element conversions, url
864
- # conversions, headers, rules, pre blocks, paragraphs
865
-
866
- def test_render_html_and_head
867
- @content = @doc.renderContent
868
- refute_nil(@content.index("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">
869
- <HTML>
870
- <HEAD>
871
- <TITLE>Ryan\'s Homepage: Version 2.0</TITLE>
872
- <LINK REV=\"MADE\" HREF=\"mailto:ryand-web@zenspider.com\">
873
- <META NAME=\"rating\" CONTENT=\"general\">
874
- <META NAME=\"GENERATOR\" CONTENT=\"#{ZenWebsite.banner}\">
875
- <META NAME=\"author\" CONTENT=\"Ryan Davis\">
876
- <META NAME=\"copyright\" CONTENT=\"1996-2001, Zen Spider Software\">
877
- <link rel=\"up\" href=\"../index.html\" title=\"My Website\">
878
- <link rel=\"contents\" href=\"../SiteMap.html\" title=\"Sitemap\">
879
- <link rel=\"top\" href=\"../index.html\" title=\"My Website\">
880
- </HEAD>
881
- <BODY>
882
- <P class=\"navbar\">
883
- <A HREF=\"../SiteMap.html\">Sitemap</A> || <A HREF=\"../index.html\">My Website</A>
884
- / Ryan\'s Homepage</P>
885
- <H1>Ryan\'s Homepage</H1>
886
- <H2>Version 2.0</H2>
887
- <HR CLASS=\"thick\""),
888
- "Must render the HTML header and all appropriate metadata")
889
- end
890
-
891
- def test_render_foot
892
- @content = @doc.renderContent
893
- expected = "\n<HR CLASS=\"thick\">\n\n<P class=\"navbar\">\n<A HREF=\"../SiteMap.html\">Sitemap</A> || <A HREF=\"../index.html\">My Website</A>\n / Ryan's Homepage</P>\n\n<P>This is my footer, jive turkey</P></BODY>\n</HTML>\n"
894
-
895
- refute_nil(@content.index(expected),
896
- "Must render the HTML footer")
897
- end
898
-
899
- def test_navbar
900
- @content = @doc.renderContent
901
- assert(@content =~ %r%<A HREF=\"../SiteMap.html\">Sitemap</A> || <A HREF=\"../index.html\">My Website</A>\n / Ryan\'s Homepage</P>\n%,
902
- "Must render navbar correctly")
903
- end
904
-
905
- end
906
-
907
- class TestSubpageRenderer < ZenRendererTest
908
-
909
- def test_render
910
-
911
- result = @renderer.render('')
912
-
913
- assert_equal([ "\n\n",
914
- "** Subpages:\n\n",
915
- "+ <A HREF=\"/~ryand/blah.html\">blah</A>\n",
916
- "+ <A HREF=\"/~ryand/stuff/index.html\">my stuff</A>\n",
917
- "\n" ].join(''),
918
- result)
919
- end
920
-
921
- end
922
-
923
- class TestTextToHtmlRenderer < ZenRendererTest
924
-
925
- def test_render_table
926
- util_render("<table><tr><td>\n\n<P>blah</P>\n\n</td></tr></table>\n\n",
927
- "%%\n\nblah\n\n%%",
928
- "unadorned div sections should render")
929
- end
930
-
931
- def test_render_table_with_div
932
- util_render("<table><tr><td>\n\n<div class=\"blah1\"><div>\n\n<P>blah</P>\n\n</div></div>\n</td></tr></table>\n\n",
933
- "%%\n\n%%% class=\"blah1\"\n\nblah\n\n%%",
934
- "unadorned div sections should render")
935
- end
936
-
937
- def test_render_table_with_2_divs
938
- util_render("<table><tr><td>\n\n<div class=\"blah1\"><div>\n\n<P>blah1</P>\n\n</div></div>\n</td><td>\n<div class=\"blah2\"><div>\n\n<P>blah2</P>\n\n</div></div>\n</td></tr></table>\n\n",
939
- "%%\n\n%%% class=\"blah1\"\n\nblah1\n\n%%% class=\"blah2\"\n\nblah2\n\n%%",
940
- "unadorned div sections should render")
941
- end
942
-
943
- def test_render_div
944
- util_render("<div class=\"blah\"><div>\n\n<P>blah</P>\n\n</div></div>\n\n",
945
- "%%% class=\"blah\"\n\nblah\n\n%%%",
946
- "styled div sections should render")
947
- end
948
-
949
- def test_render_headers
950
- util_render("<H2>Head 2</H2>\n\n", "** Head 2",
951
- "Must render H2 from **")
952
-
953
- util_render("<H3>Head 3</H3>\n\n", "*** Head 3",
954
- "Must render H3 from ***")
955
-
956
- util_render("<H4>Head 4</H4>\n\n", "**** Head 4",
957
- "Must render H4 from ****")
958
-
959
- util_render("<H5>Head 5</H5>\n\n", "***** Head 5",
960
- "Must render H5 from *****")
961
-
962
- util_render("<H6>Head 6</H6>\n\n", "****** Head 6",
963
- "Must render H6 from ******")
964
-
965
- end
966
-
967
- def test_render_ul1
968
-
969
- # TODO: test like this:
970
- # r = TextToHtmlRenderer.new(@doc)
971
- # result = r.render("+ blah1\n+ blah2")
972
-
973
- util_render("<UL>\n <LI>Lists (should have two items).</LI>\n <LI>Continuted Lists.</LI>\n</UL>\n",
974
- "+ Lists (should have two items).\n+ Continuted Lists.\n",
975
- "Must render normal list from +")
976
- end
977
-
978
- def test_render_ul2
979
- util_render("<UL>\n <LI>Another List \(should have a sub list\).\n <UL>\n <LI>With a sub-list</LI>\n <LI>another item</LI>\n </UL>\n </LI>\n</UL>\n",
980
- "+ Another List (should have a sub list).\n\t+ With a sub-list\n\t+ another item\n",
981
- "Must render compound list from indented +'s")
982
- end
983
-
984
- def test_render_ol1
985
- util_render("<OL>\n <LI>Ordered lists</LI>\n <LI>are cool\n <OL>\n <LI>Especially when you make ordered sublists</LI>\n </OL>\n </LI>\n</OL>\n", "= Ordered lists\n= are cool\n\t= Especially when you make ordered sublists\n",
986
- "Must render compound list from indented ='s")
987
- end
988
-
989
- def test_render_dict1
990
- util_render("<DL>\n <DT>Term 1</DT>\n <DD>Def 1</DD>\n\n <DT>Term 2</DT>\n <DD>Def 2</DD>\n\n</DL>\n\n",
991
- "%- Term 1\n%= Def 1\n%- Term 2\n%= Def 2",
992
- "Must render simple dictionary list")
993
- end
994
-
995
- def test_render_metadata_eval
996
- r = MetadataRenderer.new(@doc)
997
- result = r.render("blah #\{1+1\} blah")
998
- assert_equal("blah 2 blah", result,
999
- "MetadataRenderer must evaluate ruby expressions")
1000
- end
1001
-
1002
- def test_render_rule_small
1003
- util_render("<HR>\n\n", "---",
1004
- "Must render small rule from ---")
1005
- end
1006
-
1007
- def test_render_rule_big
1008
- util_render(%Q(<HR CLASS="thick">\n\n), "===",
1009
- "Must render big rule from ===")
1010
- end
1011
-
1012
- def test_render_paragraph
1013
- util_render("<P>Paragraphs can contain <A HREF=\"http://www.ZenSpider.com/ZSS/ZenWeb/\">www.ZenSpider.com /ZSS /ZenWeb</A> and <A HREF=\"mailto:zss@ZenSpider.com\">zss@ZenSpider.com</A> and they will automatically be converted. Don't forget less-than \"&lt;\" &amp; greater-than \"&gt;\", but only if backslashed.</P>\n\n",
1014
- "Paragraphs can contain http://www.ZenSpider.com/ZSS/ZenWeb/ and mailto:zss@ZenSpider.com and they will automatically be converted. Don't forget less-than \"\\<\" \\& greater-than \"\\>\", but only if backslashed.\n",
1015
- "Must render paragraph from a single line")
1016
- end
1017
-
1018
- def test_render_paragraph_2_lines_and_embedded
1019
- util_render("<P>Likewise, two lines side by side\nare considered one paragraph. Supports <I>Embedded HTML</I>.</P>\n\n",
1020
- "Likewise, two lines side by side\nare considered one paragraph. Supports <I>Embedded HTML</I>.
1021
- ",
1022
- "Must render paragraph from multiple lines")
1023
- end
1024
-
1025
- def test_render_paragraph_urls
1026
- util_render(%Q%<P>Supports <A HREF=\"http://www.yahoo.com\">Unaltered urls</A> as well\.</P>\n\n%,
1027
- %Q%Supports <A HREF="http://www.yahoo.com">Unaltered urls</A> as well.%,
1028
- "Must render full urls without conversion")
1029
- end
1030
-
1031
- def test_render_paragraph_tag_normal
1032
- util_render("<P>blah</P>\n\n", "blah")
1033
- end
1034
-
1035
- def test_render_paragraph_tag_div
1036
- util_render("<DIV>blah</DIV>\n\n", "<DIV>blah</DIV>")
1037
- end
1038
-
1039
- def test_render_paragraph_tag_p
1040
- util_render("<P>blah</P>\n\n", "<P>blah</P>")
1041
- end
1042
-
1043
- def test_render_paragraph_tag_unknown
1044
- util_render("<P><XXX>blah</XXX></P>\n\n", "<XXX>blah</XXX>")
1045
- end
1046
-
1047
- def test_render_paragraph_tag_h1
1048
- util_render("<H1>blah</H1>\n\n", "<H1>blah</H1>")
1049
- end
1050
-
1051
- def test_render_pre
1052
- util_render("<PRE>PRE blocks are paragraphs that are indented two spaces on each line.\nThe two spaces will be stripped, and all other indentation will be left\nalone.\n this allows me to put things like code examples in and retain\n their formatting.</PRE>\n\n",
1053
- " PRE blocks are paragraphs that are indented two spaces on each line.\n The two spaces will be stripped, and all other indentation will be left\n alone.\n this allows me to put things like code examples in and retain\n their formatting.\n",
1054
- "Must render PRE blocks from indented paragraphs")
1055
- end
1056
-
1057
- def test_createList_flat
1058
- assert_equal(["line 1", "line 2"],
1059
- @renderer.createList("line 1\nline 2\n"))
1060
- end
1061
-
1062
- def test_createList_deep
1063
- assert_equal($array_list_data,
1064
- @renderer.createList($text_list_data),
1065
- "createList must create the correct array from the text")
1066
- end
1067
-
1068
- def test_createHash_simple
1069
- hash, order = @renderer.createHash("%- term 2\n%= def 2\n%-term 1\n%=def 1")
1070
-
1071
- assert_equal({"term 2" => "def 2", "term 1" => "def 1"}, hash)
1072
- assert_equal(["term 2", "term 1"], order)
1073
- end
1074
- end
1075
-
1076
- class TestFooterRenderer < ZenRendererTest
1077
- def test_render
1078
- # must create own web so we do not attach to a pregenerated index.html
1079
- web = ZenWebsite.new(@sitemapUrl, "test", "testhtml")
1080
- @doc = ZenDocument.new("/index.html", web)
1081
-
1082
- @doc['footer'] = "footer 1\n";
1083
- @doc['renderers'] = [ 'FooterRenderer' ]
1084
-
1085
- # TODO: need to test content w/ close HTML tag
1086
- @doc.content = "line 1\nline 2\nline 3\n"
1087
-
1088
- content = @doc.renderContent
1089
-
1090
- assert_equal("line 1\nline 2\nline 3\nfooter 1\n", content)
1091
- end
1092
- end
1093
-
1094
- class TestHeaderRenderer < ZenRendererTest
1095
- def test_render
1096
- @doc = ZenDocument.new("/index.html", @web)
1097
- @doc['header'] = "header 1\n";
1098
- @doc['renderers'] = [ 'HeaderRenderer' ]
1099
- @doc.content = "line 1\nline 2\nline 3\n"
1100
-
1101
- content = @doc.renderContent
1102
-
1103
- assert_equal("header 1\nline 1\nline 2\nline 3\n", content)
1104
- end
1105
- end
1106
-
1107
- class TestMetadataRenderer < ZenRendererTest
1108
-
1109
- def test_render
1110
- @doc['nothing'] = 'you'
1111
- util_render 'I hate you', 'I hate #{nothing}', 'metadata must be accessed from @doc'
1112
- end
1113
-
1114
- def test_include
1115
- util_render "TEXT\n#metadata = false\nThis is some 42\ncommon text.\nTEXT",
1116
- "TEXT\n\#{include '../include.txt'}\nTEXT",
1117
- "Include should inject text from files"
1118
- end
1119
-
1120
- def test_unknown
1121
- @doc["key1"] = 42
1122
- @doc["key2"] = "some string"
1123
-
1124
- util_render("Glossary lookups for 42 and some string but key99 should not look up.",
1125
- "Glossary lookups for #\{key1} and #\{key2} but #\{key99} should not look up.",
1126
- "Must render metadata lookups from \#\{key\}")
1127
- end
1128
-
1129
-
1130
-
1131
- def test_include_strip
1132
- util_render("TEXT\nThis is some 42\ncommon text.\nTEXT",
1133
- "TEXT\n\#{include '../include.txt', true}\nTEXT",
1134
- "Include should inject text from files")
1135
- end
1136
-
1137
- def test_link
1138
- util_render("TEXT\n<A HREF=\"/index.html\">Go Away</A>\nTEXT",
1139
- "TEXT\n\#{link '/index.html', 'Go Away'}\nTEXT",
1140
- "link should create appropriate href")
1141
- end
1142
-
1143
- def test_img
1144
- util_render("TEXT\n<IMG SRC=\"/goaway.png\" ALT=\"Go Away\">\nTEXT",
1145
- "TEXT\n\#{img '/goaway.png', 'Go Away'}\nTEXT",
1146
- "img should create appropriate img")
1147
- end
1148
-
1149
- end
1150
-
1151
- class TestSitemapRenderer < ZenRendererTest
1152
-
1153
- def setup
1154
- super
1155
- end
1156
-
1157
- def test_render_normal
1158
- @doc = @web.sitemap
1159
- @content = @doc.content
1160
- @renderer = SitemapRenderer.new(@doc)
1161
-
1162
- result = @renderer.render(@content)
1163
-
1164
- expected = [
1165
- "+ <A HREF=\"/index.html\">My Website: Subtitle</A>\n",
1166
- "+ <A HREF=\"/SiteMap.html\">Sitemap: There are 6 pages in this website.</A>\n",
1167
- "+ <A HREF=\"/Something.html\">Something</A>\n",
1168
- "+ <A HREF=\"/~ryand/index.html\">Ryan's Homepage: Version 2.0</A>\n",
1169
- "\t+ <A HREF=\"/~ryand/blah.html\">blah</A>\n",
1170
- "\t+ <A HREF=\"/~ryand/stuff/index.html\">my stuff</A>\n"
1171
- ].join('')
1172
-
1173
- assert_equal(expected, result, "Must properly convert the urls to a list")
1174
- end
1175
-
1176
- def test_render_subsite
1177
- # this is a weird one... if my sitemap is something like:
1178
- # /~ryand/index.html
1179
- # /~ryand/SiteMap.html
1180
- # then ZenWeb somehow thinks that sitemap is a subdirectory to index.
1181
-
1182
- @web = ZenWebsite.new('/~ryand/SiteMap.html', "test", "testhtml")
1183
- @doc = @web['/~ryand/SiteMap.html']
1184
- @content = @doc.content
1185
- @renderer = SitemapRenderer.new(@doc)
1186
-
1187
- result = @renderer.render(@content)
1188
-
1189
- expected = [
1190
- "+ <A HREF=\"/~ryand/index.html\">Ryan's Homepage: Version 2.0</A>\n",
1191
- "+ <A HREF=\"/~ryand/SiteMap.html\">Sitemap: There are 4 pages in this website.</A>\n",
1192
- "+ <A HREF=\"/~ryand/blah.html\">blah</A>\n",
1193
- "+ <A HREF=\"/~ryand/stuff/index.html\">my stuff</A>\n"
1194
- ].join('')
1195
-
1196
- # FIX: need a sub-sub-page to test indention at that level
1197
-
1198
- assert_equal(expected, result, "Must properly convert the urls to a list")
1199
- end
1200
-
1201
- end
1202
-
1203
- class TestRelativeRenderer < ZenRendererTest
1204
-
1205
- def test_render
1206
-
1207
- content = [
1208
- '<A HREF="http://www.yahoo.com/blah/blah.html">stuff</A>',
1209
- '<a href="/something.html">something</A>',
1210
- '<a href="/subdir/">other dir</A>',
1211
- '<a href="/~ryand/blah.html">same dir</A>',
1212
- '<a href="#location">same page</A>',
1213
- '<A HREF="http://www.yahoo.com/blah/blah.html#location">stuff</A>',
1214
- '<a href="/something.html#location">something</A>',
1215
- '<a href="/subdir/#location">other dir</A>',
1216
- '<a href="/~ryand/blah.html#location">same dir</A>',
1217
- ].join('')
1218
-
1219
- expect = [
1220
- '<A HREF="http://www.yahoo.com/blah/blah.html">stuff</A>',
1221
- '<a href="../something.html">something</A>',
1222
- '<a href="../subdir/">other dir</A>',
1223
- '<a href="blah.html">same dir</A>',
1224
- '<a href="#location">same page</A>',
1225
- '<A HREF="http://www.yahoo.com/blah/blah.html#location">stuff</A>',
1226
- '<a href="../something.html#location">something</A>',
1227
- '<a href="../subdir/#location">other dir</A>',
1228
- '<a href="blah.html#location">same dir</A>',
1229
- ].join('')
1230
-
1231
- result = @renderer.render(content)
1232
-
1233
- assert_equal(expect, result)
1234
- end
1235
-
1236
- def test_convert
1237
-
1238
- assert_equal('http://www.yahoo.com/blah/blah.html',
1239
- @renderer.convert('http://www.yahoo.com/blah/blah.html'))
1240
-
1241
- assert_equal('../something.html',
1242
- @renderer.convert('/something.html'))
1243
-
1244
- assert_equal('../subdir/',
1245
- @renderer.convert('/subdir/'))
1246
-
1247
- assert_equal('blah.html',
1248
- @renderer.convert('/~ryand/blah.html'))
1249
- end
1250
- end
1251
-
1252
- class TestRubyCodeRenderer < ZenRendererTest
1253
- def test_render()
1254
- # XMP is a POS, so this is as much as I'm willing to test right
1255
- # now until I can pinpoint the bug and go though xmp properly or
1256
- # bypass it altogether...
1257
-
1258
- shutupwhile {
1259
- result = @renderer.render("! 2+2")
1260
- assert_equal ">> 2+2\n=><EM> 4</EM>\n", result
1261
- }
1262
- end
1263
- end
1264
-
1265
- class TestTocRenderer < ZenRendererTest
1266
-
1267
- def test_render
1268
-
1269
- content = [
1270
- "This is some content, probably the intro...\n",
1271
- "\n",
1272
- "** Section 1\n",
1273
- "\n",
1274
- "This is more content 1\n",
1275
- "\n",
1276
- "*** Section 1.1\n",
1277
- "\n",
1278
- "This is more content 2\n",
1279
- "\n",
1280
- "** Section 2:\n",
1281
- "\n",
1282
- "This is more content 3\n",
1283
- "\n",
1284
- ].join('')
1285
-
1286
- expected = [
1287
-
1288
- "** <A NAME=\"0\">Contents:</A>\n",
1289
- "\n",
1290
- "+ <A HREF=\"#0\">Contents</A>\n",
1291
- "+ <A HREF=\"#1\">Section 1</A>\n",
1292
- "\t+ <A HREF=\"#2\">Section 1.1</A>\n",
1293
- "+ <A HREF=\"#3\">Section 2</A>\n",
1294
-
1295
- "This is some content, probably the intro...\n",
1296
- "\n",
1297
- "** <A NAME=\"1\">Section 1</A>\n",
1298
- "\n",
1299
- "This is more content 1\n",
1300
- "\n",
1301
- "*** <A NAME=\"2\">Section 1.1</A>\n",
1302
- "\n",
1303
- "This is more content 2\n",
1304
- "\n",
1305
- "** <A NAME=\"3\">Section 2</A>\n", # note the lack of colon at the end
1306
- "\n",
1307
- "This is more content 3\n",
1308
- "\n",
1309
- ].join('')
1310
-
1311
- result = @renderer.render(content)
1312
-
1313
- assert_equal(expected, result, "Must properly generate TOC")
1314
- end
1315
- end
1316
-
1317
- class TestCalendarRenderer < ZenRendererTest
1318
- def setup
1319
- super
1320
- @oct = "<table class=\"calendar\"><tr><td valign=\"top\"><table class=\"view y2004 m10\">
1321
- <tr class=\"title\">
1322
- <th colspan=7>October 2004</th>
1323
- </tr>
1324
- <tr class=\"weektitle\"
1325
- <th class=\"sun\">Sun</th>
1326
- <th class=\"mon\">Mon</th>
1327
- <th class=\"tue\">Tue</th>
1328
- <th class=\"wed\">Wed</th>
1329
- <th class=\"thu\">Thu</th>
1330
- <th class=\"fri\">Fri</th>
1331
- <th class=\"sat\">Sat</th></tr>
1332
- <tr class=\"days firstweek\">
1333
- <td colspan=5>&nbsp;</td>
1334
- <td class=\"d01 fri\">1</td>
1335
- <td class=\"d02 sat\">2</td>
1336
- </tr>
1337
- <tr class=\"days\">
1338
- <td class=\"d03 sun\">3</td>
1339
- <td class=\"d04 mon\">4</td>
1340
- <td class=\"d05 tue\">5</td>
1341
- <td class=\"d06 wed\">6</td>
1342
- <td class=\"d07 thu\">7</td>
1343
- <td class=\"d08 fri\">8</td>
1344
- <td class=\"d09 sat\">9</td>
1345
- </tr>
1346
- <tr class=\"days\">
1347
- <td class=\"d10 sun\">10</td>
1348
- <td class=\"d11 mon\">11</td>
1349
- <td class=\"d12 tue\">12</td>
1350
- <td class=\"d13 wed\">13</td>
1351
- <td class=\"d14 thu\">14</td>
1352
- <td class=\"d15 fri\">15</td>
1353
- <td class=\"d16 sat\">16</td>
1354
- </tr>
1355
- <tr class=\"days\">
1356
- <td class=\"d17 sun\">17</td>
1357
- <td class=\"d18 mon\">18</td>
1358
- <td class=\"d19 tue\">19</td>
1359
- <td class=\"d20 wed\">20</td>
1360
- <td class=\"d21 thu\">21</td>
1361
- <td class=\"d22 fri\">22</td>
1362
- <td class=\"d23 sat\">23</td>
1363
- </tr>
1364
- <tr class=\"days\">
1365
- <td class=\"d24 sun\">24</td>
1366
- <td class=\"d25 mon\">25</td>
1367
- <td class=\"d26 tue\">26</td>
1368
- <td class=\"d27 wed event\">27</td>
1369
- <td class=\"d28 thu\">28</td>
1370
- <td class=\"d29 fri\">29</td>
1371
- <td class=\"d30 sat\">30</td>
1372
- </tr>
1373
- <tr class=\"days\">
1374
- <td class=\"d31 sun\">31</td>
1375
- <td colspan=6>&nbsp;</td>
1376
- </tr>
1377
- </table>
1378
- </td>
1379
- <td class=\"eventlist\">
1380
- <ul>
1381
- <li>2004-10-27:
1382
- <ul>
1383
- <li>Ryan's birfday!
1384
- </ul>
1385
- </ul>
1386
- </td>
1387
- </tr>
1388
- </table>
1389
- "
1390
-
1391
- @may = "<table class=\"calendar\"><tr><td valign=\"top\"><table class=\"view y2004 m05\">
1392
- <tr class=\"title\">
1393
- <th colspan=7>May 2004</th>
1394
- </tr>
1395
- <tr class=\"weektitle\"
1396
- <th class=\"sun\">Sun</th>
1397
- <th class=\"mon\">Mon</th>
1398
- <th class=\"tue\">Tue</th>
1399
- <th class=\"wed\">Wed</th>
1400
- <th class=\"thu\">Thu</th>
1401
- <th class=\"fri\">Fri</th>
1402
- <th class=\"sat\">Sat</th></tr>
1403
- <tr class=\"days firstweek\">
1404
- <td colspan=6>&nbsp;</td>
1405
- <td class=\"d01 sat\">1</td>
1406
- </tr>
1407
- <tr class=\"days\">
1408
- <td class=\"d02 sun\">2</td>
1409
- <td class=\"d03 mon\">3</td>
1410
- <td class=\"d04 tue\">4</td>
1411
- <td class=\"d05 wed\">5</td>
1412
- <td class=\"d06 thu\">6</td>
1413
- <td class=\"d07 fri\">7</td>
1414
- <td class=\"d08 sat\">8</td>
1415
- </tr>
1416
- <tr class=\"days\">
1417
- <td class=\"d09 sun\">9</td>
1418
- <td class=\"d10 mon\">10</td>
1419
- <td class=\"d11 tue\">11</td>
1420
- <td class=\"d12 wed\">12</td>
1421
- <td class=\"d13 thu\">13</td>
1422
- <td class=\"d14 fri\">14</td>
1423
- <td class=\"d15 sat\">15</td>
1424
- </tr>
1425
- <tr class=\"days\">
1426
- <td class=\"d16 sun\">16</td>
1427
- <td class=\"d17 mon\">17</td>
1428
- <td class=\"d18 tue\">18</td>
1429
- <td class=\"d19 wed\">19</td>
1430
- <td class=\"d20 thu\">20</td>
1431
- <td class=\"d21 fri\">21</td>
1432
- <td class=\"d22 sat\">22</td>
1433
- </tr>
1434
- <tr class=\"days\">
1435
- <td class=\"d23 sun\">23</td>
1436
- <td class=\"d24 mon\">24</td>
1437
- <td class=\"d25 tue\">25</td>
1438
- <td class=\"d26 wed event\">26</td>
1439
- <td class=\"d27 thu\">27</td>
1440
- <td class=\"d28 fri\">28</td>
1441
- <td class=\"d29 sat\">29</td>
1442
- </tr>
1443
- <tr class=\"days\">
1444
- <td class=\"d30 sun\">30</td>
1445
- <td class=\"d31 mon\">31</td>
1446
- <td colspan=5>&nbsp;</td>
1447
- </tr>
1448
- </table>
1449
- </td>
1450
- <td class=\"eventlist\">
1451
- <ul>
1452
- <li>2004-05-26:
1453
- <ul>
1454
- <li>Eric's bifday!
1455
- </ul>
1456
- </ul>
1457
- </td>
1458
- </tr>
1459
- </table>
1460
- "
1461
- end
1462
-
1463
- def test_render_forward
1464
- expect = @may + @oct
1465
- input = "<cal>
1466
- 2004-05-26: Eric's bifday!
1467
- 2004-10-27: Ryan's birfday!
1468
- </cal>"
1469
- util_render(expect, input)
1470
- end
1471
-
1472
- def test_render_empty_last_week
1473
- expect = "<table class=\"calendar\"><tr><td valign=\"top\"><table class=\"view y2004 m07\">\n<tr class=\"title\">\n<th colspan=7>July 2004</th>\n</tr>\n<tr class=\"weektitle\"\n<th class=\"sun\">Sun</th>\n<th class=\"mon\">Mon</th>\n<th class=\"tue\">Tue</th>\n<th class=\"wed\">Wed</th>\n<th class=\"thu\">Thu</th>\n<th class=\"fri\">Fri</th>\n<th class=\"sat\">Sat</th></tr>\n<tr class=\"days firstweek\">\n<td colspan=4>&nbsp;</td>\n<td class=\"d01 thu event\">1</td>\n<td class=\"d02 fri\">2</td>\n<td class=\"d03 sat\">3</td>\n</tr>\n<tr class=\"days\">\n<td class=\"d04 sun\">4</td>\n<td class=\"d05 mon\">5</td>\n<td class=\"d06 tue\">6</td>\n<td class=\"d07 wed\">7</td>\n<td class=\"d08 thu\">8</td>\n<td class=\"d09 fri\">9</td>\n<td class=\"d10 sat\">10</td>\n</tr>\n<tr class=\"days\">\n<td class=\"d11 sun\">11</td>\n<td class=\"d12 mon\">12</td>\n<td class=\"d13 tue\">13</td>\n<td class=\"d14 wed\">14</td>\n<td class=\"d15 thu\">15</td>\n<td class=\"d16 fri\">16</td>\n<td class=\"d17 sat\">17</td>\n</tr>\n<tr class=\"days\">\n<td class=\"d18 sun\">18</td>\n<td class=\"d19 mon\">19</td>\n<td class=\"d20 tue\">20</td>\n<td class=\"d21 wed\">21</td>\n<td class=\"d22 thu\">22</td>\n<td class=\"d23 fri\">23</td>\n<td class=\"d24 sat\">24</td>\n</tr>\n<tr class=\"days\">\n<td class=\"d25 sun\">25</td>\n<td class=\"d26 mon\">26</td>\n<td class=\"d27 tue\">27</td>\n<td class=\"d28 wed\">28</td>\n<td class=\"d29 thu\">29</td>\n<td class=\"d30 fri\">30</td>\n<td class=\"d31 sat\">31</td>\n</tr>\n</table>\n</td>\n<td class=\"eventlist\">\n<ul>\n<li>2004-07-01:\n<ul>\n<li>blah\n</ul>\n</ul>\n</td>\n</tr>\n</table>\n"
1474
- input = "<cal>
1475
- 2004-07-01: blah
1476
- </cal>"
1477
- util_render(expect, input)
1478
- end
1479
-
1480
- def test_render_reverse
1481
- expect = @oct + @may
1482
- input = "<cal reverse>
1483
- 2004-05-26: Eric's bifday!
1484
- 2004-10-27: Ryan's birfday!
1485
- </cal>"
1486
- util_render(expect, input)
1487
- end
1488
- end
1489
-
1490
- class TestStupidRenderer < ZenRendererTest
1491
- def test_render_undefined
1492
- util_render("This is some text", "This is some text")
1493
- end
1494
-
1495
- def test_render_leet
1496
- @doc['stupidmethod'] = 'leet'
1497
- util_render('+]-[|$ |$ $0/\/\3 +3><+', "This is some text")
1498
- end
1499
-
1500
- def test_render_strip
1501
- @doc['stupidmethod'] = 'strip'
1502
- util_render("Ths s sm txt", "This is some text")
1503
- end
1504
-
1505
- def test_render_unknown
1506
- @doc['stupidmethod'] = 'dunno'
1507
- assert_raises(NameError) {
1508
- @renderer.render("anything")
1509
- }
1510
- end
1511
-
1512
- def test_leet
1513
- result = @renderer.leet("This is some text")
1514
- assert_equal('+]-[|$ |$ $0/\/\3 +3><+', result)
1515
- end
1516
-
1517
- def test_strip
1518
- result = @renderer.strip("This is some text")
1519
- assert_equal("Ths s sm txt", result)
1520
- end
1521
- end
1522
-
1523
- class TestCompactRenderer < ZenRendererTest
1524
- def test_render
1525
-
1526
- input = "
1527
- <!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
1528
- <html>
1529
- <head>
1530
- <title>Title</title>
1531
- </head>
1532
- <body>
1533
-
1534
- <h1>Title</h1>
1535
-
1536
- <p>blah blah</p>
1537
- <pre>line 1
1538
- line 2
1539
- line 3</pre>
1540
-
1541
- </body>
1542
- </html>
1543
- "
1544
-
1545
- expected = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\"><html><head><title>Title</title></head><body><h1>Title</h1><p>blah blah</p><pre>line 1
1546
- line 2
1547
- line 3</pre></body></html>"
1548
-
1549
- assert_equal(expected, @renderer.render(input))
1550
- end
1551
- end
1552
-
1553
- class TestHtmlTableRenderer < ZenRendererTest
1554
- def test_render_plain
1555
- input = "<tabs>
1556
- a\tb\tc
1557
- d\te\tf
1558
- </tabs>
1559
- "
1560
-
1561
- expected = "<table border=\"0\">
1562
- <tr><th>a</th><th>b</th><th>c</th></tr>
1563
- <tr><td>d</td><td>e</td><td>f</td></tr>
1564
- </table>
1565
- "
1566
-
1567
- assert_equal(expected, @renderer.render(input))
1568
- end
1569
-
1570
- def test_render_multitabs
1571
- input = "<tabs>
1572
- a\tb\t\t\tc
1573
- d\t\t\te\tf
1574
- </tabs>
1575
- "
1576
-
1577
- expected = "<table border=\"0\">
1578
- <tr><th>a</th><th>b</th><th>c</th></tr>
1579
- <tr><td>d</td><td>e</td><td>f</td></tr>
1580
- </table>
1581
- "
1582
-
1583
- assert_equal(expected, @renderer.render(input))
1584
- end
1585
-
1586
-
1587
- def test_render_paragraphs
1588
- input = "something
1589
-
1590
- <tabs>
1591
- a\tb\t\t\tc
1592
- d\t\t\te\tf
1593
- </tabs>
1594
-
1595
- something else
1596
- "
1597
-
1598
- expected = "something
1599
-
1600
- <table border=\"0\">
1601
- <tr><th>a</th><th>b</th><th>c</th></tr>
1602
- <tr><td>d</td><td>e</td><td>f</td></tr>
1603
- </table>
1604
-
1605
- something else
1606
- "
1607
-
1608
- assert_equal(expected, @renderer.render(input))
1609
- end
1610
- end
1611
-
1612
- # this is more here to shut up ZenTest than anything else.
1613
- class TestXXXRenderer < ZenRendererTest
1614
- def test_render
1615
- assert_equal("This is a test", @renderer.render("This is a test"))
1616
- end
1617
- end
1618
-
1619
- require 'test/unit' if $0 == __FILE__