zenweb 2.18.0

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