wikiwah 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,422 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wikiwah/flow'
4
+ require 'test/unit'
5
+
6
+ # Tests follow. The structure is
7
+ #
8
+ # ====
9
+ # #{input}
10
+ # ----
11
+ # #{expected_output}
12
+ #
13
+ # This script will complain if the actual output doesn't match.
14
+
15
+ TESTS = <<END_OF_TESTS
16
+
17
+ ==== # Paragraph
18
+ Simple paragraph
19
+ ----
20
+ <p>
21
+ Simple paragraph
22
+ </p>
23
+
24
+ ==== # Two paragraphs
25
+ P1
26
+
27
+ P2
28
+ ----
29
+ <p>
30
+ P1
31
+ </p>
32
+ <p>
33
+ P2
34
+ </p>
35
+
36
+ ==== # List: one item
37
+ * List
38
+ ----
39
+ <ul class="sparse">
40
+ <li>
41
+ List
42
+ </li>
43
+ </ul>
44
+
45
+ ==== # List: two items
46
+ * item 1
47
+ * item 2
48
+ ----
49
+ <ul class="sparse">
50
+ <li>
51
+ item 1
52
+ </li>
53
+ <li>
54
+ item 2
55
+ </li>
56
+ </ul>
57
+
58
+ ==== # Nested lists
59
+ * item 1
60
+ - item 1.1
61
+ * item 2
62
+ ----
63
+ <ul class="sparse">
64
+ <li>
65
+ item 1
66
+ </li>
67
+ <ul>
68
+ <li>
69
+ item 1.1
70
+ </li>
71
+ </ul>
72
+ <li>
73
+ item 2
74
+ </li>
75
+ </ul>
76
+
77
+ ==== # Numbered list
78
+ # item 1
79
+ # item 2
80
+ ----
81
+ <ol>
82
+ <li>
83
+ item 1
84
+ </li>
85
+ <li>
86
+ item 2
87
+ </li>
88
+ </ol>
89
+
90
+ ==== # Numbered list followed by un-numbered list
91
+ # item 1
92
+ * item 2
93
+ ----
94
+ <ol>
95
+ <li>
96
+ item 1
97
+ </li>
98
+ </ol>
99
+ <ul class="sparse">
100
+ <li>
101
+ item 2
102
+ </li>
103
+ </ul>
104
+
105
+ ==== # Paragraph/list
106
+ P1
107
+
108
+ - item 1
109
+ ----
110
+ <p>
111
+ P1
112
+ </p>
113
+ <ul>
114
+ <li>
115
+ item 1
116
+ </li>
117
+ </ul>
118
+
119
+ ==== # Paragraph/nested-list
120
+ P1
121
+
122
+ - item 1
123
+ ----
124
+ <p>
125
+ P1
126
+ <ul>
127
+ <li>
128
+ item 1
129
+ </li>
130
+ </ul>
131
+ </p>
132
+
133
+ ==== # List/paragraph
134
+ - item 1
135
+
136
+ P1
137
+ ----
138
+ <ul>
139
+ <li>
140
+ item 1
141
+ </li>
142
+ </ul>
143
+ <p>
144
+ P1
145
+ </p>
146
+
147
+ ==== # Paragraph/list/paragraph
148
+ P1
149
+
150
+ - item 1
151
+
152
+ P2
153
+ ----
154
+ <p>
155
+ P1
156
+ </p>
157
+ <ul>
158
+ <li>
159
+ item 1
160
+ </li>
161
+ </ul>
162
+ <p>
163
+ P2
164
+ </p>
165
+
166
+ ==== # Code
167
+ | code
168
+ |
169
+ | more code
170
+ ----
171
+ <pre>
172
+ code
173
+
174
+ more code
175
+ </pre>
176
+
177
+ ==== # Blockquote
178
+ > block
179
+ > quote
180
+ ----
181
+ <blockquote>
182
+ block
183
+ quote
184
+ </blockquote>
185
+
186
+ ==== # Blockquote with space
187
+ > block
188
+ >
189
+ > quote
190
+ ----
191
+ <blockquote>
192
+ block
193
+
194
+ quote
195
+ </blockquote>
196
+
197
+ ====
198
+ > q1
199
+
200
+ - item
201
+
202
+ > q2
203
+ ----
204
+ <blockquote>
205
+ q1
206
+ <ul>
207
+ <li>
208
+ item
209
+ </li>
210
+ </ul>
211
+ q2
212
+ </blockquote>
213
+
214
+ ====
215
+ - item
216
+
217
+ | code
218
+ ----
219
+ <ul>
220
+ <li>
221
+ item
222
+ </li>
223
+ </ul>
224
+ <pre>
225
+ code
226
+ </pre>
227
+
228
+ ====
229
+ * item
230
+
231
+ | code
232
+ ----
233
+ <ul class="sparse">
234
+ <li>
235
+ item
236
+ </li>
237
+ <pre>
238
+ code
239
+ </pre>
240
+ </ul>
241
+
242
+ ====
243
+ Text with <tags> in
244
+ ----
245
+ <p>
246
+ Text with <tags> in
247
+ </p>
248
+
249
+ ====
250
+ drink XXXX
251
+ ----
252
+ <p>
253
+ drink BEER
254
+ </p>
255
+
256
+ ====
257
+ = HEAD
258
+ - blah
259
+ ----
260
+ <h1>
261
+ HEAD
262
+ </h1>
263
+ <ul>
264
+ <li>
265
+ blah
266
+ </li>
267
+ </ul>
268
+
269
+ ====
270
+ P1
271
+
272
+ quote
273
+
274
+ P2
275
+ ----
276
+ <p>
277
+ P1
278
+ <blockquote>
279
+ quote
280
+ </blockquote>
281
+ </p>
282
+ <p>
283
+ P2
284
+ </p>
285
+
286
+ ====
287
+ P1
288
+
289
+ quote
290
+ - xxx
291
+ ----
292
+ <p>
293
+ P1
294
+ <blockquote>
295
+ quote
296
+ <ul>
297
+ <li>
298
+ xxx
299
+ </li>
300
+ </ul>
301
+ </blockquote>
302
+ </p>
303
+
304
+ ====
305
+ 1. juan
306
+ 2. two
307
+ ----
308
+ <ol>
309
+ <li>
310
+ juan
311
+ </li>
312
+ <li>
313
+ two
314
+ </li>
315
+ </ol>
316
+
317
+ ====
318
+ (1) juan
319
+ (2) two
320
+ ----
321
+ <ol>
322
+ <li>
323
+ juan
324
+ </li>
325
+ <li>
326
+ two
327
+ </li>
328
+ </ol>
329
+
330
+ ====
331
+ | x
332
+ | |y|
333
+ | z
334
+ ----
335
+ <pre>
336
+ x
337
+ |y|
338
+ z
339
+ </pre>
340
+
341
+ ====
342
+ - list item
343
+
344
+ == header
345
+ ----
346
+ <ul>
347
+ <li>
348
+ list item
349
+ </li>
350
+ </ul>
351
+ <h2>
352
+ header
353
+ </h2>
354
+
355
+ ====
356
+ % term1
357
+
358
+ definition1
359
+
360
+ % term2
361
+
362
+ definition2
363
+ ----
364
+ <dl>
365
+ <dt>
366
+ term1
367
+ </dt>
368
+ <dd>
369
+ definition1
370
+ </dd>
371
+ <dt>
372
+ term2
373
+ </dt>
374
+ <dd>
375
+ definition2
376
+ </dd>
377
+ </dl>
378
+
379
+ ====
380
+ b4
381
+
382
+ % term1
383
+
384
+ def1
385
+
386
+ after
387
+ ----
388
+ <p>
389
+ b4
390
+ </p>
391
+ <dl>
392
+ <dt>
393
+ term1
394
+ </dt>
395
+ <dd>
396
+ def1
397
+ </dd>
398
+ </dl>
399
+ <p>
400
+ after
401
+ </p>
402
+ END_OF_TESTS
403
+
404
+ class Wikiwah
405
+ class FlowTests < Test::Unit::TestCase
406
+
407
+ TESTS.split(/\n====.*\n/).each_with_index do |test, i|
408
+ (input, expected) = test.split(/----\n/)
409
+ next unless expected
410
+ define_method("test_#{i}") do
411
+ actual = WikiWah::Flow.convert(input) do |s|
412
+ s.gsub(/XXXX/, "BEER")
413
+ end
414
+ expected[/\s*\z/] = ''
415
+ actual[/\s*\z/] = ''
416
+ assert_equal(expected, actual)
417
+ end
418
+ end
419
+
420
+ end
421
+ end
422
+
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wikiwah/subst'
4
+ require 'test/unit'
5
+
6
+ class WikiWah
7
+
8
+ class Subst_Tests < Test::Unit::TestCase
9
+
10
+ def test_do_nothing
11
+ subst = Subst.new
12
+ assert_equal("xxx", subst.transform("xxx"))
13
+ end
14
+
15
+ def test_simple
16
+ subst = Subst.new
17
+ subst.add_transformation(/y/) { "Y" }
18
+ assert_equal("xYz", subst.transform("xyz"))
19
+ end
20
+
21
+ def test_store
22
+ subst = Subst.new
23
+ subst.add_transformation(/x/) { "y" }
24
+ subst.add_transformation(/y/) { "z" }
25
+ assert_equal("yz", subst.transform("xy"))
26
+ end
27
+
28
+ def test_bold
29
+ subst = Subst.new
30
+ subst.add_transformation(/\*(\w+)\*/) { |match| "<b>#{match[1]}</b>" }
31
+ assert_equal("a <b>b</b> c", subst.transform("a *b* c"))
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wikiwah/subst'
4
+ require 'test/unit'
5
+
6
+ class WikiWah
7
+
8
+ class Subst_Tests < Test::Unit::TestCase
9
+
10
+ def test_do_nothing
11
+ subst = Subst.new
12
+ assert_equal("xxx", subst.transform("xxx"))
13
+ end
14
+
15
+ def test_simple
16
+ subst = Subst.new
17
+ subst.add_transformation(/y/) { "Y" }
18
+ assert_equal("xYz", subst.transform("xyz"))
19
+ end
20
+
21
+ def test_store
22
+ subst = Subst.new
23
+ subst.add_transformation(/x/) { "y" }
24
+ subst.add_transformation(/y/) { "z" }
25
+ assert_equal("yz", subst.transform("xy"))
26
+ end
27
+
28
+ def test_bold
29
+ subst = Subst.new
30
+ subst.add_transformation(/\*(\w+)\*/) { |match| "<b>#{match[1]}</b>" }
31
+ assert_equal("a <b>b</b> c", subst.transform("a *b* c"))
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wikiwah'
4
+ require 'test/unit'
5
+
6
+ class WikiWahTests < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @wikiwah = WikiWah.new
10
+ end
11
+
12
+ def assert_wikiwah(expected, input)
13
+ assert_equal(expected, @wikiwah.to_html(input))
14
+ end
15
+
16
+ def test_empty
17
+ assert_wikiwah("", "")
18
+ end
19
+
20
+ def test_paragraph
21
+ assert_wikiwah("<p>\nxyz\n</p>\n", "xyz\n")
22
+ end
23
+
24
+ def test_strong
25
+ assert_wikiwah("<p>\n<strong>xyz</strong>\n</p>\n", "*xyz*\n")
26
+ end
27
+
28
+ def test_em
29
+ assert_wikiwah("<p>\n<em>xyz</em>\n</p>\n", "/xyz/\n")
30
+ end
31
+
32
+ def test_strong_em
33
+ assert_wikiwah("<p>\n<strong><em>xyz</em></strong>\n</p>\n", "*/xyz/*\n")
34
+ end
35
+
36
+ def test_strong_then_em
37
+ assert_wikiwah("<p>\n<strong>abc</strong>=<em>xyz</em>\n</p>\n", "*abc*=/xyz/\n")
38
+ end
39
+
40
+ def test_link
41
+ assert_wikiwah(%{<p>\n<a href='/yyy'>xxx</a>\n</p>\n},
42
+ "{xxx}@/yyy\n")
43
+ end
44
+
45
+ def test_bold_link
46
+ assert_wikiwah(%{<p>\n<a href='/yyy'><strong>xxx</strong></a>\n</p>\n},
47
+ "{*xxx*}@/yyy\n")
48
+ end
49
+
50
+ def assert_wikiwah_unchanged(input)
51
+ expected = "<p>\n" + input + "</p>\n"
52
+ assert_wikiwah(expected, input)
53
+ end
54
+
55
+ def test_inline_html
56
+ assert_wikiwah_unchanged(%{<b>blah</b><img src="xxx" />})
57
+ end
58
+
59
+ def test_inline_html_with_link
60
+ assert_wikiwah_unchanged(%{<b>blah</b><img src="http://blah.com" />})
61
+ end
62
+
63
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wikiwah'
4
+ require 'test/unit'
5
+
6
+ class WikiWahTests < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @wikiwah = WikiWah.new
10
+ end
11
+
12
+ def assert_wikiwah(expected, input)
13
+ assert_equal(expected, @wikiwah.to_html(input))
14
+ end
15
+
16
+ def test_empty
17
+ assert_wikiwah("", "")
18
+ end
19
+
20
+ def test_paragraph
21
+ assert_wikiwah("<p>\nxyz\n</p>\n", "xyz\n")
22
+ end
23
+
24
+ def test_strong
25
+ assert_wikiwah("<p>\n<strong>xyz</strong>\n</p>\n", "*xyz*\n")
26
+ end
27
+
28
+ def test_em
29
+ assert_wikiwah("<p>\n<em>xyz</em>\n</p>\n", "/xyz/\n")
30
+ end
31
+
32
+ def test_strong_em
33
+ assert_wikiwah("<p>\n<strong><em>xyz</em></strong>\n</p>\n", "*/xyz/*\n")
34
+ end
35
+
36
+ def test_strong_then_em
37
+ assert_wikiwah("<p>\n<strong>abc</strong>=<em>xyz</em>\n</p>\n", "*abc*=/xyz/\n")
38
+ end
39
+
40
+ def test_link
41
+ assert_wikiwah(%{<p>\n<a href='/yyy'>xxx</a>\n</p>\n},
42
+ "{xxx}@/yyy\n")
43
+ end
44
+
45
+ def test_bold_link
46
+ assert_wikiwah(%{<p>\n<a href='/yyy'><strong>xxx</strong></a>\n</p>\n},
47
+ "{*xxx*}@/yyy\n")
48
+ end
49
+
50
+ def assert_wikiwah_unchanged(input)
51
+ expected = "<p>\n" + input + "</p>\n"
52
+ assert_wikiwah(expected, input)
53
+ end
54
+
55
+ def test_inline_html
56
+ assert_wikiwah_unchanged(%{<b>blah</b><img src="xxx" />})
57
+ end
58
+
59
+ def test_inline_html_with_link
60
+ assert_wikiwah_unchanged(%{<b>blah</b><img src="http://blah.com" />})
61
+ end
62
+
63
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wikiwah
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Mike Williams
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-30 00:00:00 +10:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: |
23
+ Wikiwah is a text-to-HTML converter, along the lines of Markdown.
24
+
25
+ This isn't the markup language you're looking for.
26
+ It offers no improvements on Markdown, Textile, etc.
27
+ I'm packaging it as a gem only because I still have some legacy content in this format.
28
+
29
+ email: mdub@dogbiscuit.org
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - lib/wikiwah/flow.rb
38
+ - lib/wikiwah/flow.rb~
39
+ - lib/wikiwah/subst.rb
40
+ - lib/wikiwah/subst.rb~
41
+ - lib/wikiwah/version.rb
42
+ - lib/wikiwah/version.rb~
43
+ - lib/wikiwah.rb
44
+ - lib/wikiwah.rb~
45
+ - test/wikiwah/flow_tests.rb
46
+ - test/wikiwah/flow_tests.rb~
47
+ - test/wikiwah/subst_tests.rb
48
+ - test/wikiwah/subst_tests.rb~
49
+ - test/wikiwah_tests.rb
50
+ - test/wikiwah_tests.rb~
51
+ - Rakefile
52
+ has_rdoc: true
53
+ homepage: http://github.com/mdub/wikiwah
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: WikiWah turns text into HTML
86
+ test_files:
87
+ - test/wikiwah/flow_tests.rb
88
+ - test/wikiwah/flow_tests.rb~
89
+ - test/wikiwah/subst_tests.rb
90
+ - test/wikiwah/subst_tests.rb~
91
+ - test/wikiwah_tests.rb
92
+ - test/wikiwah_tests.rb~
93
+ - Rakefile