gollum 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gollum might be problematic. Click here for more details.

Files changed (166) hide show
  1. data/Gemfile +1 -1
  2. data/README.md +24 -1
  3. data/Rakefile +2 -2
  4. data/bin/gollum +1 -1
  5. data/gollum.gemspec +24 -169
  6. data/lib/gollum.rb +1 -1
  7. data/lib/gollum/frontend/app.rb +12 -7
  8. data/lib/gollum/frontend/helpers.rb +6 -0
  9. data/lib/gollum/frontend/public/gollum/livepreview/images/lr_24.png +0 -0
  10. data/lib/gollum/frontend/public/gollum/livepreview/index.html +0 -6
  11. data/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js +0 -2
  12. data/lib/gollum/frontend/public/gollum/livepreview/licenses/licenses.txt +7 -0
  13. data/lib/gollum/frontend/public/gollum/livepreview/licenses/templarian_windowsicons/license.txt +40 -0
  14. data/lib/gollum/gitcode.rb +47 -0
  15. data/lib/gollum/markup.rb +58 -8
  16. data/lib/gollum/wiki.rb +7 -2
  17. data/templates/helper_wiki.rb +9 -0
  18. metadata +261 -429
  19. data/test/examples/empty.git/HEAD +0 -1
  20. data/test/examples/empty.git/config +0 -5
  21. data/test/examples/empty.git/description +0 -1
  22. data/test/examples/empty.git/hooks/applypatch-msg.sample +0 -15
  23. data/test/examples/empty.git/hooks/commit-msg.sample +0 -24
  24. data/test/examples/empty.git/hooks/post-commit.sample +0 -8
  25. data/test/examples/empty.git/hooks/post-receive.sample +0 -15
  26. data/test/examples/empty.git/hooks/post-update.sample +0 -8
  27. data/test/examples/empty.git/hooks/pre-applypatch.sample +0 -14
  28. data/test/examples/empty.git/hooks/pre-commit.sample +0 -46
  29. data/test/examples/empty.git/hooks/pre-rebase.sample +0 -169
  30. data/test/examples/empty.git/hooks/prepare-commit-msg.sample +0 -36
  31. data/test/examples/empty.git/hooks/update.sample +0 -128
  32. data/test/examples/empty.git/info/exclude +0 -6
  33. data/test/examples/empty.git/objects/info/.gitkeep +0 -0
  34. data/test/examples/empty.git/objects/pack/.gitkeep +0 -0
  35. data/test/examples/empty.git/refs/heads/.gitkeep +0 -0
  36. data/test/examples/lotr.git/COMMIT_EDITMSG +0 -1
  37. data/test/examples/lotr.git/HEAD +0 -1
  38. data/test/examples/lotr.git/ORIG_HEAD +0 -1
  39. data/test/examples/lotr.git/config +0 -12
  40. data/test/examples/lotr.git/description +0 -1
  41. data/test/examples/lotr.git/index +0 -0
  42. data/test/examples/lotr.git/info/exclude +0 -6
  43. data/test/examples/lotr.git/logs/HEAD +0 -7
  44. data/test/examples/lotr.git/logs/refs/heads/master +0 -7
  45. data/test/examples/lotr.git/objects/06/131480411710c92a82fe2d1e76932c70feb2e5 +0 -0
  46. data/test/examples/lotr.git/objects/0a/de1e2916346d4c1f2fb63b863fd3c16808fe44 +0 -0
  47. data/test/examples/lotr.git/objects/0d/c9016ca928c78d5421a99a53b379b53929221e +0 -0
  48. data/test/examples/lotr.git/objects/0e/d8cbe0a25235bd867e65193c7d837c66b328ef +0 -3
  49. data/test/examples/lotr.git/objects/12/629d666c5e3178f82f533f543d61b53dc78c0b +0 -0
  50. data/test/examples/lotr.git/objects/1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 +0 -0
  51. data/test/examples/lotr.git/objects/1d/b89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 +0 -2
  52. data/test/examples/lotr.git/objects/24/49c2681badfd3c189e8ed658dacffe8ba48fe5 +0 -0
  53. data/test/examples/lotr.git/objects/25/4bdc1ba27d8b8a794538a8522d9a2b56ec2dd9 +0 -0
  54. data/test/examples/lotr.git/objects/27/680b0fce1abfbc528e7aa53d92645852d52eb6 +0 -0
  55. data/test/examples/lotr.git/objects/2c/b9156ad383914561a8502fc70f5a1d887e48ad +0 -4
  56. data/test/examples/lotr.git/objects/45/3b250f979c7bd6dfb62640c944c982ae6721ee +0 -0
  57. data/test/examples/lotr.git/objects/45/f319ee12f2b551b901b22e72602963c366fff1 +0 -0
  58. data/test/examples/lotr.git/objects/46/a697caf435815bb07bbce947fc2d58be15f087 +0 -0
  59. data/test/examples/lotr.git/objects/4c/45c2b4e297a726c3d3f66886f35373e48fe1c5 +0 -2
  60. data/test/examples/lotr.git/objects/4e/023f460ce466e154ca09d8774c79ad5a53fc15 +0 -0
  61. data/test/examples/lotr.git/objects/5d/cac289a8603188d2c5caf481dcba2985126aaa +0 -0
  62. data/test/examples/lotr.git/objects/60/f12f4254f58801b9ee7db7bca5fa8aeefaa56b +0 -0
  63. data/test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 +0 -1
  64. data/test/examples/lotr.git/objects/6e/48abfc56565574859e081ee58eae655d48cf71 +0 -0
  65. data/test/examples/lotr.git/objects/71/4323c104239440a5c66ab12a67ed07a83c404f +0 -0
  66. data/test/examples/lotr.git/objects/7b/60c5a20a501a70f2317fa0ef763e1e2ce22d6b +0 -0
  67. data/test/examples/lotr.git/objects/7d/981cd984ad589e3cf00d8122170c6f7d685979 +0 -0
  68. data/test/examples/lotr.git/objects/84/0ec5b1ba1320e8ec443f28f99566f615d5af10 +0 -0
  69. data/test/examples/lotr.git/objects/93/6b83ee0dd8837adb82511e40d5e4ebe59bb675 +0 -0
  70. data/test/examples/lotr.git/objects/94/523d7ae48aeba575099dd12926420d8fd0425d +0 -2
  71. data/test/examples/lotr.git/objects/94/9a9cc3119b9c98817f375e976d2bb5e2a42809 +0 -0
  72. data/test/examples/lotr.git/objects/96/97dc65e095658bbd1b8e8678e08881e86d32f1 +0 -0
  73. data/test/examples/lotr.git/objects/9b/e95b960ac388d4e7db55f610f828e9c31344e6 +0 -0
  74. data/test/examples/lotr.git/objects/a3/1ca2a7c352c92531a8b99815d15843b259e814 +0 -0
  75. data/test/examples/lotr.git/objects/a6/59b3763b822dd97544621fd0beef162ea37b14 +0 -4
  76. data/test/examples/lotr.git/objects/a8/ad3c09dd842a3517085bfadd37718856dee813 +0 -0
  77. data/test/examples/lotr.git/objects/aa/b61fe89d56f8614c0a8151da34f939dcedfa68 +0 -0
  78. data/test/examples/lotr.git/objects/b0/de6e794dfdc7ef3400e894225bfe23308aae5c +0 -0
  79. data/test/examples/lotr.git/objects/b1/6b3d9fad9d78e5a669e7f33d94c96da374eccd +0 -0
  80. data/test/examples/lotr.git/objects/bc/4b5fc0ce2c2ba3acef6647e4f67256ee45ab60 +0 -0
  81. data/test/examples/lotr.git/objects/c3/b43e9f08966b088e7a0192e436b7a884542e05 +0 -0
  82. data/test/examples/lotr.git/objects/c9/6a7645db5d4c76389e77cd103ef3ed77d81e4c +0 -0
  83. data/test/examples/lotr.git/objects/ca/7355dc497e9729fbaf0c0e3f424b86afef5614 +0 -0
  84. data/test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd +0 -2
  85. data/test/examples/lotr.git/objects/d5/29304506d37f544675244c335d85cab5d29966 +0 -0
  86. data/test/examples/lotr.git/objects/dc/596d6b2dd89ab05c66f4abd7d5eb706bc17f19 +0 -0
  87. data/test/examples/lotr.git/objects/ec/da3205bee14520aab5a7bb307392064b938e83 +0 -0
  88. data/test/examples/lotr.git/objects/f4/84ebb1f40f8eb20d1bcd8d1d71934d2b8ae961 +0 -0
  89. data/test/examples/lotr.git/objects/fa/e7ef5344202bba4129abdc13060d9297d99465 +0 -3
  90. data/test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df +0 -1
  91. data/test/examples/lotr.git/objects/fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 +0 -0
  92. data/test/examples/lotr.git/objects/ff/6f7de62644369380ba73b4e4297c1a2d6f0b66 +0 -0
  93. data/test/examples/lotr.git/objects/info/packs +0 -2
  94. data/test/examples/lotr.git/objects/pack/pack-dcbeaf3f6ff6c5eb08ea2b0a2d83626e8763546b.idx +0 -0
  95. data/test/examples/lotr.git/objects/pack/pack-dcbeaf3f6ff6c5eb08ea2b0a2d83626e8763546b.pack +0 -0
  96. data/test/examples/lotr.git/packed-refs +0 -2
  97. data/test/examples/lotr.git/refs/heads/master +0 -1
  98. data/test/examples/lotr.git/refs/remotes/origin/HEAD +0 -1
  99. data/test/examples/page_file_dir.git/COMMIT_EDITMSG +0 -1
  100. data/test/examples/page_file_dir.git/HEAD +0 -1
  101. data/test/examples/page_file_dir.git/config +0 -6
  102. data/test/examples/page_file_dir.git/description +0 -1
  103. data/test/examples/page_file_dir.git/index +0 -0
  104. data/test/examples/page_file_dir.git/info/exclude +0 -6
  105. data/test/examples/page_file_dir.git/logs/HEAD +0 -1
  106. data/test/examples/page_file_dir.git/logs/refs/heads/master +0 -1
  107. data/test/examples/page_file_dir.git/objects/0c/7d27db1f575263efdcab3dc650f4502a2dbcbf +0 -0
  108. data/test/examples/page_file_dir.git/objects/22/b404803c966dd92865614d86ff22ca12e50c1e +0 -0
  109. data/test/examples/page_file_dir.git/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 +0 -0
  110. data/test/examples/page_file_dir.git/objects/57/16ca5987cbf97d6bb54920bea6adde242d87e6 +0 -0
  111. data/test/examples/page_file_dir.git/objects/5b/43e14e0a15fb6f08feab1773d1c0991e9f71e2 +0 -0
  112. data/test/examples/page_file_dir.git/refs/heads/master +0 -1
  113. data/test/examples/revert.git/COMMIT_EDITMSG +0 -1
  114. data/test/examples/revert.git/HEAD +0 -1
  115. data/test/examples/revert.git/config +0 -12
  116. data/test/examples/revert.git/description +0 -1
  117. data/test/examples/revert.git/index +0 -0
  118. data/test/examples/revert.git/info/exclude +0 -6
  119. data/test/examples/revert.git/logs/HEAD +0 -3
  120. data/test/examples/revert.git/logs/refs/heads/master +0 -3
  121. data/test/examples/revert.git/objects/10/2685c42018f802557f05db171f44443e8dacab +0 -0
  122. data/test/examples/revert.git/objects/20/2ced67cea93c7b6bd2928aa1daef8d1d55a20d +0 -0
  123. data/test/examples/revert.git/objects/41/76394bfa11222363c66ce7e84b5f154095b6d9 +0 -0
  124. data/test/examples/revert.git/objects/6a/69f92020f5df77af6e8813ff1232493383b708 +0 -0
  125. data/test/examples/revert.git/objects/8e/83f898e5e16ae400db59dda1017acad540f3aa +0 -0
  126. data/test/examples/revert.git/objects/b4/785957bc986dc39c629de9fac9df46972c00fc +0 -0
  127. data/test/examples/revert.git/objects/ed/6c9f63b98acf73c25b5ffbb38da557d3682023 +0 -3
  128. data/test/examples/revert.git/objects/f4/03b791119f8232b7cb0ba455c624ac6435f433 +0 -0
  129. data/test/examples/revert.git/objects/info/packs +0 -2
  130. data/test/examples/revert.git/objects/pack/pack-a561f8437234f74d0bacb9e0eebe52d207f5770d.idx +0 -0
  131. data/test/examples/revert.git/objects/pack/pack-a561f8437234f74d0bacb9e0eebe52d207f5770d.pack +0 -0
  132. data/test/examples/revert.git/packed-refs +0 -2
  133. data/test/examples/revert.git/refs/heads/master +0 -1
  134. data/test/examples/revert.git/refs/remotes/origin/HEAD +0 -1
  135. data/test/examples/yubiwa.git/HEAD +0 -1
  136. data/test/examples/yubiwa.git/config +0 -5
  137. data/test/examples/yubiwa.git/description +0 -1
  138. data/test/examples/yubiwa.git/info/exclude +0 -6
  139. data/test/examples/yubiwa.git/objects/10/fa2ddc4e3b4009d8a453aace10bd6148c1ad00 +0 -0
  140. data/test/examples/yubiwa.git/objects/52/4b82874327ea7cbf730389964ba7cb3de966de +0 -0
  141. data/test/examples/yubiwa.git/objects/58/3fc201cb457fb3f1480f3e1e5999b119633835 +0 -0
  142. data/test/examples/yubiwa.git/objects/87/bc1dd46ab3d3874d4e898d45dd512cc20a7cc8 +0 -1
  143. data/test/examples/yubiwa.git/objects/89/64ed1b4e21aa90e831763bbce9034bfda81b70 +0 -0
  144. data/test/examples/yubiwa.git/objects/9f/f6dd0660da5fba2d3374adb2b84fa653bb538b +0 -0
  145. data/test/examples/yubiwa.git/objects/ac/e97abf2b177815a1972d7db22f229f58c83309 +0 -0
  146. data/test/examples/yubiwa.git/objects/b1/f443863a4816628807fbf86141ebef055dda34 +0 -0
  147. data/test/examples/yubiwa.git/refs/heads/master +0 -1
  148. data/test/file_view/1_file.txt +0 -3
  149. data/test/file_view/1_file_1_folder.txt +0 -8
  150. data/test/file_view/1_folder.txt +0 -8
  151. data/test/file_view/2_files_2_folders.txt +0 -12
  152. data/test/file_view/2_files_2_folders_1_root.txt +0 -13
  153. data/test/file_view/nested_folders.txt +0 -28
  154. data/test/helper.rb +0 -66
  155. data/test/test_app.rb +0 -375
  156. data/test/test_app_helpers.rb +0 -13
  157. data/test/test_committer.rb +0 -64
  158. data/test/test_file.rb +0 -27
  159. data/test/test_file_view.rb +0 -102
  160. data/test/test_git_access.rb +0 -53
  161. data/test/test_markup.rb +0 -732
  162. data/test/test_page.rb +0 -231
  163. data/test/test_page_revert.rb +0 -57
  164. data/test/test_pages_view.rb +0 -46
  165. data/test/test_unicode.rb +0 -131
  166. data/test/test_wiki.rb +0 -509
@@ -1,13 +0,0 @@
1
- # ~*~ encoding: utf-8 ~*~
2
- require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
3
-
4
- context "Precious::Helpers" do
5
- include Precious::Helpers
6
-
7
- test "extracting paths from URLs" do
8
- assert_nil extract_path('Eye-Of-Sauron')
9
- assert_equal 'Mordor', extract_path('Mordor/Sauron')
10
- assert_equal 'Mordor/Sauron', extract_path('Mordor/Sauron/Evil')
11
- end
12
- end
13
-
@@ -1,64 +0,0 @@
1
- # ~*~ encoding: utf-8 ~*~
2
- require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
3
-
4
- context "Wiki" do
5
- setup do
6
- @wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
7
- end
8
-
9
- test "normalizes commit hash" do
10
- commit = {:message => 'abc'}
11
- name = @wiki.repo.config['user.name'] || @wiki.default_committer_name
12
- email = @wiki.repo.config['user.email'] || @wiki.default_committer_email
13
- committer = Gollum::Committer.new(@wiki, commit)
14
- assert_equal name, committer.actor.name
15
- assert_equal email, committer.actor.email
16
-
17
- commit[:name] = 'bob'
18
- commit[:email] = ''
19
- committer = Gollum::Committer.new(@wiki, commit)
20
- assert_equal 'bob', committer.actor.name
21
- assert_equal email, committer.actor.email
22
-
23
- commit[:email] = 'foo@bar.com'
24
- committer = Gollum::Committer.new(@wiki, commit)
25
- assert_equal 'bob', committer.actor.name
26
- assert_equal 'foo@bar.com', committer.actor.email
27
- end
28
-
29
- test "yield after_commit callback" do
30
- @path = cloned_testpath('examples/lotr.git')
31
- yielded = nil
32
- begin
33
- wiki = Gollum::Wiki.new(@path)
34
- committer = Gollum::Committer.new(wiki)
35
- committer.after_commit do |index, sha1|
36
- yielded = sha1
37
- assert_equal committer, index
38
- end
39
-
40
- res = wiki.write_page("Gollum", :markdown, "# Gollum",
41
- :committer => committer)
42
-
43
- assert_equal committer, res
44
-
45
- sha1 = committer.commit
46
- assert_equal sha1, yielded
47
- ensure
48
- FileUtils.rm_rf(@path)
49
- end
50
- end
51
-
52
- test "parents with default master ref" do
53
- ref = '629aa678272b017a4d136d35e77ac94d80b08dc2'
54
- committer = Gollum::Committer.new(@wiki)
55
- assert_equal ref, committer.parents.first.sha
56
- end
57
-
58
- test "parents with custom ref" do
59
- ref = '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
60
- @wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), :ref => ref)
61
- committer = Gollum::Committer.new(@wiki)
62
- assert_equal ref, committer.parents.first.sha
63
- end
64
- end
data/test/test_file.rb DELETED
@@ -1,27 +0,0 @@
1
- # ~*~ encoding: utf-8 ~*~
2
- path = File.join(File.dirname(__FILE__), "helper")
3
- require File.expand_path(path)
4
-
5
- context "File" do
6
- setup do
7
- @wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
8
- end
9
-
10
- test "new file" do
11
- file = Gollum::File.new(@wiki)
12
- assert_nil file.raw_data
13
- end
14
-
15
- test "existing file" do
16
- commit = @wiki.repo.commits.first
17
- file = @wiki.file("Mordor/todo.txt")
18
- assert_equal "[ ] Write section on Ents\n", file.raw_data
19
- assert_equal 'todo.txt', file.name
20
- assert_equal commit.id, file.version.id
21
- assert_equal commit.author.name, file.version.author.name
22
- end
23
-
24
- test "accessing tree" do
25
- assert_nil @wiki.file("Mordor")
26
- end
27
- end
@@ -1,102 +0,0 @@
1
- # ~*~ encoding: utf-8 ~*~
2
- require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
3
- require File.expand_path '../../lib/gollum/file_view', __FILE__
4
-
5
- class FakePage
6
- def initialize filepath
7
- @filepath = filepath
8
- end
9
-
10
- # From page.rb
11
- def filename_stripped
12
- ::File.basename(@filepath, ::File.extname(@filepath))
13
- end
14
-
15
- def path
16
- return @filepath
17
- end
18
-
19
- # From page.rb
20
- def name
21
- self.class.canonicalize_filename @filepath
22
- end
23
-
24
- # From page.rb
25
- def self.strip_filename filename
26
- ::File.basename( filename, ::File.extname( filename ))
27
- end
28
-
29
- # From page.rb
30
- def self.canonicalize_filename filename
31
- strip_filename(filename).gsub('-', ' ')
32
- end
33
- end
34
-
35
- class FakePages
36
- def initialize filepath_array
37
- @array = filepath_array.map { | filepath | FakePage.new filepath }
38
- end
39
-
40
- def size
41
- @array.size
42
- end
43
-
44
- def [] index
45
- @array[ index ]
46
- end
47
- end
48
-
49
- def view pages
50
- Gollum::FileView.new( pages ).render_files
51
- end
52
-
53
- @@test_path = File.expand_path( '../file_view/' , __FILE__ ) + '/'
54
-
55
- def read file
56
- File.read @@test_path + file + '.txt'
57
- end
58
-
59
- # For creating expected files.
60
- # write name, actual
61
- def write file, content
62
- File.open(@@test_path + file + '.txt', 'w') do | f |
63
- f.write content
64
- end
65
- end
66
-
67
- def check name, pages_array
68
- pages = FakePages.new pages_array
69
- expected = read name
70
- actual = view pages
71
- assert_equal expected, actual
72
- end
73
-
74
- # Test Notes
75
- # root files must be before any folders.
76
- # Home.md => file at root folder
77
- # docs/sanitization.md => file within folder
78
- context 'file_view' do
79
- test 'one file' do
80
- check '1_file', [ '0.md' ]
81
- end
82
-
83
- test 'one folder' do
84
- check '1_folder', [ 'folder0/' ]
85
- end
86
-
87
- test 'one file with one folder' do
88
- check '1_file_1_folder', [ 'folder0/0.md' ]
89
- end
90
-
91
- test 'two files with two folders' do
92
- check '2_files_2_folders', [ 'folder0/0.md', 'folder1/1.md' ]
93
- end
94
-
95
- test 'two files with two folders and one root file' do
96
- check '2_files_2_folders_1_root', [ 'root.md', 'folder0/0.md', 'folder1/1.md' ]
97
- end
98
-
99
- test 'nested folders' do
100
- check 'nested_folders', [ 'folder0/folder1/folder2/0.md', 'folder0/folder1/folder3/1.md', 'folder4/2.md' ]
101
- end
102
- end # context
@@ -1,53 +0,0 @@
1
- # ~*~ encoding: utf-8 ~*~
2
- require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
3
-
4
- context "GitAccess" do
5
- setup do
6
- @access = Gollum::GitAccess.new(testpath("examples/lotr.git"))
7
- end
8
-
9
- test "#commit fills commit_map cache" do
10
- assert @access.commit_map.empty?
11
- actual = @access.repo.commits.first
12
- expected = @access.commit(actual.id)
13
- assert_equal actual.message, expected.message
14
- assert_equal actual.message, @access.commit_map[actual.id].message
15
- end
16
-
17
- test "#tree_map_for caches ref and tree" do
18
- assert @access.ref_map.empty?
19
- assert @access.tree_map.empty?
20
- @access.tree 'master'
21
- assert_equal({"master"=>"629aa678272b017a4d136d35e77ac94d80b08dc2"}, @access.ref_map)
22
-
23
- @access.tree '1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3'
24
- map = @access.tree_map['1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3']
25
- assert_equal 'Bilbo-Baggins.md', map[0].path
26
- assert_equal '', map[0].dir
27
- assert_equal map[0].path, map[0].name
28
- assert_equal 'Mordor/Eye-Of-Sauron.md', map[3].path
29
- assert_equal '/Mordor', map[3].dir
30
- assert_equal 'Eye-Of-Sauron.md', map[3].name
31
- end
32
-
33
- test "#tree_map_for only caches tree for commit" do
34
- assert @access.tree_map.empty?
35
- @access.tree '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
36
- assert @access.ref_map.empty?
37
-
38
- entry = @access.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0]
39
- assert_equal 'Bilbo-Baggins.md', entry.path
40
- end
41
-
42
- test "cannot access commit from invalid ref" do
43
- assert_nil @access.commit('foo')
44
- end
45
-
46
- test "cannot access sha from invalid ref" do
47
- assert_nil @access.ref_to_sha('foo')
48
- end
49
-
50
- test "cannot access tree from invalid ref" do
51
- assert_equal [], @access.tree('foo')
52
- end
53
- end
data/test/test_markup.rb DELETED
@@ -1,732 +0,0 @@
1
- # ~*~ encoding: utf-8 ~*~
2
- require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
3
-
4
- context "Markup" do
5
- setup do
6
- @path = testpath("examples/test.git")
7
- FileUtils.rm_rf(@path)
8
- Grit::Repo.init_bare(@path)
9
- Gollum::Wiki.default_options = {:universal_toc => false}
10
- @wiki = Gollum::Wiki.new(@path)
11
- end
12
-
13
- teardown do
14
- FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
15
- end
16
-
17
- test "formats page from Wiki#pages" do
18
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details)
19
- assert @wiki.pages[0].formatted_data
20
- end
21
-
22
- # This test is to assume that Sanitize.clean doesn't raise Encoding::CompatibilityError on ruby 1.9
23
- test "formats non ASCII-7 character page from Wiki#pages" do
24
- wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git"))
25
- assert_nothing_raised(defined?(Encoding) && Encoding::CompatibilityError) do
26
- assert wiki.page("strider").formatted_data
27
- end
28
- end
29
-
30
- test "Gollum::Markup#render yields a DocumentFragment" do
31
- yielded = false
32
- @wiki.write_page("Yielded", :markdown, "abc", commit_details)
33
-
34
- page = @wiki.page("Yielded")
35
- markup = Gollum::Markup.new(page)
36
- markup.render do |doc|
37
- assert_kind_of Nokogiri::HTML::DocumentFragment, doc
38
- yielded = true
39
- end
40
- assert yielded
41
- end
42
-
43
- test "Gollum::Page#formatted_data yields a DocumentFragment" do
44
- yielded = false
45
- @wiki.write_page("Yielded", :markdown, "abc", commit_details)
46
-
47
- page = @wiki.page("Yielded")
48
- page.formatted_data do |doc|
49
- assert_kind_of Nokogiri::HTML::DocumentFragment, doc
50
- yielded = true
51
- end
52
- assert yielded
53
- end
54
-
55
- #########################################################################
56
- #
57
- # Links
58
- #
59
- #########################################################################
60
-
61
- test "double page links no space" do
62
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details)
63
-
64
- # "<p>a <a class=\"internal absent\" href=\"/Foo\">Foo</a><a class=\"internal absent\" href=\"/Bar\">Bar</a> b</p>"
65
- page = @wiki.page("Bilbo Baggins")
66
- doc = Nokogiri::HTML page.formatted_data
67
- paras = doc / :p
68
- para = paras.first
69
- anchors = para / :a
70
- assert_equal 1, paras.size
71
- assert_equal 2, anchors.size
72
- assert_equal 'internal absent', anchors[0]['class']
73
- assert_equal 'internal absent', anchors[1]['class']
74
- assert_equal '/Foo', anchors[0]['href']
75
- assert_equal '/Bar', anchors[1]['href']
76
- assert_equal 'Foo', anchors[0].text
77
- assert_equal 'Bar', anchors[1].text
78
- end
79
-
80
- test "double page links with space" do
81
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]] [[Bar]] b", commit_details)
82
-
83
- # "<p>a <a class=\"internal absent\" href=\"/Foo\">Foo</a> <a class=\"internal absent\" href=\"/Bar\">Bar</a> b</p>"
84
- page = @wiki.page("Bilbo Baggins")
85
- doc = Nokogiri::HTML page.formatted_data
86
- paras = doc / :p
87
- para = paras.first
88
- anchors = para / :a
89
- assert_equal 1, paras.size
90
- assert_equal 2, anchors.size
91
- assert_equal 'internal absent', anchors[0]['class']
92
- assert_equal 'internal absent', anchors[1]['class']
93
- assert_equal '/Foo', anchors[0]['href']
94
- assert_equal '/Bar', anchors[1]['href']
95
- assert_equal 'Foo', anchors[0].text
96
- assert_equal 'Bar', anchors[1].text
97
- end
98
-
99
- test "page link" do
100
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", commit_details)
101
-
102
- page = @wiki.page("Bilbo Baggins")
103
- output = page.formatted_data
104
- assert_match /class="internal present"/, output
105
- assert_match /href="\/Bilbo-Baggins"/, output
106
- assert_match /\>Bilbo Baggins\</, output
107
- end
108
-
109
- test "adds nofollow to links on historical pages" do
110
- sha1 = @wiki.write_page("Sauron", :markdown, "a [[b]] c", commit_details)
111
- page = @wiki.page("Sauron")
112
- sha2 = @wiki.update_page(page, page.name, :markdown, "c [[b]] a", commit_details)
113
- regx = /rel="nofollow"/
114
- assert_no_match regx, page.formatted_data
115
- assert_match regx, @wiki.page(page.name, sha1).formatted_data
116
- assert_match regx, @wiki.page(page.name, sha2).formatted_data
117
- end
118
-
119
- test "absent page link" do
120
- @wiki.write_page("Tolkien", :markdown, "a [[J. R. R. Tolkien]]'s b", commit_details)
121
-
122
- page = @wiki.page("Tolkien")
123
- output = page.formatted_data
124
- assert_match /class="internal absent"/, output
125
- assert_match /href="\/J\.\-R\.\-R\.\-Tolkien"/, output
126
- assert_match /\>J\. R\. R\. Tolkien\</, output
127
- end
128
-
129
- test "page link with custom base path" do
130
- ["/wiki", "/wiki/"].each_with_index do |path, i|
131
- name = "Bilbo Baggins #{i}"
132
- @wiki = Gollum::Wiki.new(@path, :base_path => path)
133
- @wiki.write_page(name, :markdown, "a [[#{name}]] b", commit_details)
134
-
135
- page = @wiki.page(name)
136
- output = page.formatted_data
137
- assert_match /class="internal present"/, output
138
- assert_match /href="\/wiki\/Bilbo-Baggins-\d"/, output
139
- assert_match /\>Bilbo Baggins \d\</, output
140
- end
141
- end
142
-
143
- test "page link with included #" do
144
- @wiki.write_page("Precious #1", :markdown, "a [[Precious #1]] b", commit_details)
145
- page = @wiki.page('Precious #1')
146
- output = page.formatted_data
147
- assert_match /class="internal present"/, output
148
- assert_match /href="\/Precious-%231"/, output
149
- end
150
-
151
- test "page link with extra #" do
152
- @wiki.write_page("Potato", :markdown, "a [[Potato#1]] b", commit_details)
153
- page = @wiki.page('Potato')
154
- output = page.formatted_data
155
- assert_match /class="internal present"/, output
156
- assert_match /href="\/Potato#1"/, output
157
- end
158
-
159
- test "external page link" do
160
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", commit_details)
161
-
162
- page = @wiki.page("Bilbo Baggins")
163
- assert_equal "<p>a <a href=\"http://example.com\">http://example.com</a> b</p>", page.formatted_data
164
- end
165
-
166
- test "page link with different text" do
167
- @wiki.write_page("Potato", :markdown, "a [[Potato Heaad|Potato]] ", commit_details)
168
- page = @wiki.page("Potato")
169
- output = page.formatted_data
170
- assert_equal "<p>a<aclass=\"internalpresent\"href=\"/Potato\">PotatoHeaad</a></p>", normal(output)
171
- end
172
-
173
- test "page link with different text on mediawiki" do
174
- @wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details)
175
- page = @wiki.page("Potato")
176
- output = page.formatted_data
177
- assert_equal normal("<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>
178
- "), normal(output)
179
- end
180
-
181
- test "wiki link within inline code block" do
182
- @wiki.write_page("Potato", :markdown, "`sed -i '' 's/[[:space:]]*$//'`", commit_details)
183
- page = @wiki.page("Potato")
184
- assert_equal "<p><code>sed -i '' 's/[[:space:]]*$//'</code></p>", page.formatted_data
185
- end
186
-
187
- test "wiki link within code block" do
188
- @wiki.write_page("Potato", :markdown, " sed -i '' 's/[[:space:]]*$//'", commit_details)
189
- page = @wiki.page("Potato")
190
- assert_equal "<pre><code>sed -i '' 's/[[:space:]]*$//'\n</code></pre>", page.formatted_data
191
- end
192
-
193
- test "piped wiki link within code block" do
194
- @wiki.write_page("Potato", :markdown, "`make a link [[home|sweet home]]`", commit_details)
195
- page = @wiki.page("Potato")
196
- assert_equal "<p><code>make a link [[home|sweet home]]</code></p>", page.formatted_data
197
- end
198
-
199
- #########################################################################
200
- #
201
- # Images
202
- #
203
- #########################################################################
204
-
205
- test "image with http url" do
206
- ['http', 'https'].each do |scheme|
207
- name = "Bilbo Baggins #{scheme}"
208
- @wiki.write_page(name, :markdown, "a [[#{scheme}://example.com/bilbo.jpg]] b", commit_details)
209
-
210
- page = @wiki.page(name)
211
- output = page.formatted_data
212
- assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.jpg"> b</p>}, output
213
- end
214
- end
215
-
216
- test "image with extension in caps with http url" do
217
- ['http', 'https'].each do |scheme|
218
- name = "Bilbo Baggins #{scheme}"
219
- @wiki.write_page(name, :markdown, "a [[#{scheme}://example.com/bilbo.JPG]] b", commit_details)
220
-
221
- page = @wiki.page(name)
222
- output = page.formatted_data
223
- assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.JPG"> b</p>}, output
224
- end
225
- end
226
-
227
- test "image with absolute path" do
228
- @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
229
- index = @wiki.repo.index
230
- index.add("alpha.jpg", "hi")
231
- index.commit("Add alpha.jpg")
232
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", commit_details)
233
-
234
- page = @wiki.page("Bilbo Baggins")
235
- assert_equal %{<p>a <img src="/wiki/alpha.jpg"><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data
236
- end
237
-
238
- test "image with relative path on root" do
239
- @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
240
- index = @wiki.repo.index
241
- index.add("alpha.jpg", "hi")
242
- index.add("Bilbo-Baggins.md", "a [[alpha.jpg]] [[a | alpha.jpg]] b")
243
- index.commit("Add alpha.jpg")
244
-
245
- page = @wiki.page("Bilbo Baggins")
246
- assert_equal %{<p>a <img src="/wiki/alpha.jpg"><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data
247
- end
248
-
249
- test "image with relative path" do
250
- @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
251
- index = @wiki.repo.index
252
- index.add("greek/alpha.jpg", "hi")
253
- index.add("greek/Bilbo-Baggins.md", "a [[alpha.jpg]] [[a | alpha.jpg]] b")
254
- index.commit("Add alpha.jpg")
255
-
256
- page = @wiki.page("Bilbo Baggins")
257
- output = page.formatted_data
258
- assert_equal %{<p>a <img src="/wiki/greek/alpha.jpg"><a href="/wiki/greek/alpha.jpg">a</a> b</p>}, output
259
- end
260
-
261
- test "image with absolute path on a preview" do
262
- @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
263
- index = @wiki.repo.index
264
- index.add("alpha.jpg", "hi")
265
- index.commit("Add alpha.jpg")
266
-
267
- page = @wiki.preview_page("Test", "a [[/alpha.jpg]] b", :markdown)
268
- assert_equal %{<p>a <img src="/wiki/alpha.jpg"> b</p>}, page.formatted_data
269
- end
270
-
271
- test "image with relative path on a preview" do
272
- @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
273
- index = @wiki.repo.index
274
- index.add("alpha.jpg", "hi")
275
- index.add("greek/alpha.jpg", "hi")
276
- index.commit("Add alpha.jpg")
277
-
278
- page = @wiki.preview_page("Test", "a [[alpha.jpg]] [[greek/alpha.jpg]] b", :markdown)
279
- assert_equal %{<p>a <img src="/wiki/alpha.jpg"><img src="/wiki/greek/alpha.jpg"> b</p>}, page.formatted_data
280
- end
281
-
282
- test "image with alt" do
283
- content = "a [[alpha.jpg|alt=Alpha Dog]] b"
284
- output = %{<p>a <img src="/greek/alpha.jpg" alt="Alpha Dog"> b</p>}
285
- relative_image(content, output)
286
- end
287
-
288
- test "image with em or px dimension" do
289
- %w{em px}.each do |unit|
290
- %w{width height}.each do |dim|
291
- content = "a [[alpha.jpg|#{dim}=100#{unit}]] b"
292
- output = "<p>a <img src=\"/greek/alpha.jpg\" #{dim}=\"100#{unit}\"> b</p>"
293
- relative_image(content, output)
294
- end
295
- end
296
- end
297
-
298
- test "image with bogus dimension" do
299
- %w{width height}.each do |dim|
300
- content = "a [[alpha.jpg|#{dim}=100]] b"
301
- output = "<p>a <img src=\"/greek/alpha.jpg\"> b</p>"
302
- relative_image(content, output)
303
- end
304
- end
305
-
306
- test "image with vertical align" do
307
- %w{top texttop middle absmiddle bottom absbottom baseline}.each do |align|
308
- content = "a [[alpha.jpg|align=#{align}]] b"
309
- output = "<p>a <img src=\"/greek/alpha.jpg\" align=\"#{align}\"> b</p>"
310
- relative_image(content, output)
311
- end
312
- end
313
-
314
- test "image with horizontal align" do
315
- %w{left center right}.each do |align|
316
- content = "a [[alpha.jpg|align=#{align}]] b"
317
- output = "<p>a <span class=\"align-#{align}\"><span><img src=\"/greek/alpha.jpg\"></span></span> b</p>"
318
- relative_image(content, output)
319
- end
320
- end
321
-
322
- test "image with float" do
323
- content = "a\n\n[[alpha.jpg|float]]\n\nb"
324
- output = "<p>a</p>\n\n<p><span class=\"float-left\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>"
325
- relative_image(content, output)
326
- end
327
-
328
- test "image with float and align" do
329
- %w{left right}.each do |align|
330
- content = "a\n\n[[alpha.jpg|float|align=#{align}]]\n\nb"
331
- output = "<p>a</p>\n\n<p><span class=\"float-#{align}\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>"
332
- relative_image(content, output)
333
- end
334
- end
335
-
336
- test "image with frame" do
337
- content = "a\n\n[[alpha.jpg|frame]]\n\nb"
338
- output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>"
339
- relative_image(content, output)
340
- end
341
-
342
- test "absolute image with frame" do
343
- content = "a\n\n[[http://example.com/bilbo.jpg|frame]]\n\nb"
344
- output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"http://example.com/bilbo.jpg\"></span></span></p>\n\n<p>b</p>"
345
- relative_image(content, output)
346
- end
347
-
348
- test "image with frame and alt" do
349
- content = "a\n\n[[alpha.jpg|frame|alt=Alpha]]\n\nb"
350
- output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"/greek/alpha.jpg\" alt=\"Alpha\"><span>Alpha</span></span></span></p>\n\n<p>b</p>"
351
- relative_image(content, output)
352
- end
353
-
354
- #########################################################################
355
- #
356
- # File links
357
- #
358
- #########################################################################
359
-
360
- test "file link with absolute path" do
361
- index = @wiki.repo.index
362
- index.add("alpha.jpg", "hi")
363
- index.commit("Add alpha.jpg")
364
- @wiki.write_page("Bilbo Baggins", :markdown, "a [[Alpha|/alpha.jpg]] b", commit_details)
365
-
366
- page = @wiki.page("Bilbo Baggins")
367
- output = Gollum::Markup.new(page).render
368
- assert_equal %{<p>a <a href="/alpha.jpg">Alpha</a> b</p>}, output
369
- end
370
-
371
- test "file link with relative path" do
372
- index = @wiki.repo.index
373
- index.add("greek/alpha.jpg", "hi")
374
- index.add("greek/Bilbo-Baggins.md", "a [[Alpha|alpha.jpg]] b")
375
- index.commit("Add alpha.jpg")
376
-
377
- page = @wiki.page("Bilbo Baggins")
378
- output = Gollum::Markup.new(page).render
379
- assert_equal %{<p>a <a href="/greek/alpha.jpg">Alpha</a> b</p>}, output
380
- end
381
-
382
- test "file link with external path" do
383
- index = @wiki.repo.index
384
- index.add("greek/Bilbo-Baggins.md", "a [[Alpha|http://example.com/alpha.jpg]] b")
385
- index.commit("Add alpha.jpg")
386
-
387
- page = @wiki.page("Bilbo Baggins")
388
- assert_equal %{<p>a <a href="http://example.com/alpha.jpg">Alpha</a> b</p>}, page.formatted_data
389
- end
390
-
391
- #########################################################################
392
- #
393
- # Code
394
- #
395
- #########################################################################
396
-
397
- test "code blocks" do
398
- content = "a\n\n```ruby\nx = 1\n```\n\nb"
399
- output = "<p>a</p>\n\n<div class=\"highlight\">\n<pre>" +
400
- "<span class=\"n\">x</span> <span class=\"o\">=</span> " +
401
- "<span class=\"mi\">1</span>\n</pre>\n</div>\n\n\n<p>b</p>"
402
-
403
- index = @wiki.repo.index
404
- index.add("Bilbo-Baggins.md", content)
405
- index.commit("Add alpha.jpg")
406
-
407
- page = @wiki.page("Bilbo Baggins")
408
- rendered = Gollum::Markup.new(page).render
409
- assert_equal output, rendered
410
- end
411
-
412
- test "code blocks with carriage returns" do
413
- content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb"
414
- output = "<p>a</p>\n\n<div class=\"highlight\">\n<pre>" +
415
- "<span class=\"n\">x</span> <span class=\"o\">=</span> " +
416
- "<span class=\"mi\">1</span>\n</pre>\n</div>\n\n\n<p>b</p>"
417
-
418
- index = @wiki.repo.index
419
- index.add("Bilbo-Baggins.md", content)
420
- index.commit("Add alpha.jpg")
421
-
422
- page = @wiki.page("Bilbo Baggins")
423
- rendered = Gollum::Markup.new(page).render
424
- assert_equal output, rendered
425
- end
426
-
427
- test "code blocks with two-space indent" do
428
- content = "a\n\n```ruby\n x = 1\n\n y = 2\n```\n\nb"
429
- output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
430
- "x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
431
- "</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
432
- "</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
433
- compare(content, output)
434
- end
435
-
436
- test "code blocks with one-tab indent" do
437
- content = "a\n\n```ruby\n\tx = 1\n\n\ty = 2\n```\n\nb"
438
- output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
439
- "x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
440
- "</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
441
- "</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
442
- compare(content, output)
443
- end
444
-
445
- test "code blocks with multibyte caracters indent" do
446
- content = "a\n\n```ruby\ns = 'やくしまるえつこ'\n```\n\nb"
447
- output = "<p>a</p>\n\n<div class=\"highlight\">\n<pre><span class=\"n\">" +
448
- "s</span> <span class=\"o\">=</span> <span class=\"s1\">'やくしまるえつこ'" +
449
- "</span>\n</pre>\n</div>\n\n\n<p>b</p>"
450
- index = @wiki.repo.index
451
- index.add("Bilbo-Baggins.md", content)
452
- index.commit("Add alpha.jpg")
453
-
454
- page = @wiki.page("Bilbo Baggins")
455
- rendered = Gollum::Markup.new(page).render(false, 'utf-8')
456
- assert_equal output, rendered
457
- end
458
-
459
- test "code blocks with ascii characters" do
460
- content = "a\n\n```\n├─foo\n```\n\nb"
461
- output = "<p>a</p>\n\n<div class=\"highlight\"><pre>" +
462
- "├─<span class=\"n\">foo</span>" +
463
- "\n</pre>\n</div>\n\n<p>b</p>"
464
- compare(content, output)
465
- end
466
-
467
- test "code with wiki links" do
468
- content = <<-END
469
- booya
470
-
471
- ``` python
472
- np.array([[2,2],[1,3]],np.float)
473
- ```
474
- END
475
-
476
- # rendered with Gollum::Markup
477
- page, rendered = render_page(content)
478
- assert_markup_highlights_code Gollum::Markup, rendered
479
- end
480
-
481
- test "code with trailing whitespace" do
482
- content = <<-END
483
- shoop da woop
484
-
485
- ``` python
486
- np.array([[2,2],[1,3]],np.float)
487
- ```
488
- END
489
-
490
- # rendered with Gollum::Markup
491
- page, rendered = render_page(content)
492
- assert_markup_highlights_code Gollum::Markup, rendered
493
- end
494
-
495
- def assert_markup_highlights_code(markup_class, rendered)
496
- assert_match /div class="highlight"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
497
- assert_match /span class="n"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
498
- assert_match /\(\[\[/, rendered, "#{markup_class} parses out wiki links\n#{rendered}"
499
- end
500
-
501
- #########################################################################
502
- #
503
- # Web Sequence Diagrams
504
- #
505
- #########################################################################
506
-
507
- test "sequence diagram blocks" do
508
- content = "a\n\n{{{{{{default\nalice->bob: Test\n}}}}}}\n\nb"
509
- output = /.*<img src="http:\/\/www\.websequencediagrams\.com\/\?img=\w{9}" \/>.*/
510
-
511
- index = @wiki.repo.index
512
- index.add("Bilbo-Baggins.md", content)
513
- index.commit("Add sequence diagram")
514
-
515
- page = @wiki.page("Bilbo Baggins")
516
- rendered = Gollum::Markup.new(page).render
517
- assert_not_nil rendered.match(output)
518
- end
519
-
520
- #########################################################################
521
- #
522
- # Metadata Blocks
523
- #
524
- #########################################################################
525
-
526
- test "metadata blocks" do
527
- content = "a\n\n<!-- ---\ntags: [foo, bar]\n-->\n\nb"
528
- output = "<p>a</p>\n\n<p>b</p>"
529
- result = {'tags'=>['foo','bar']}
530
-
531
- index = @wiki.repo.index
532
- index.add("Bilbo-Baggins.md", content)
533
- index.commit("Add metadata")
534
-
535
- page = @wiki.page("Bilbo Baggins")
536
- rendered = Gollum::Markup.new(page).render
537
- assert_equal output, rendered
538
- assert_equal result, page.meta_data
539
- end
540
-
541
- test "metadata blocks with newline" do
542
- content = "a\n\n<!--\n---\ntags: [foo, bar]\n-->\n\nb"
543
- output = "<p>a</p>\n\n<p>b</p>"
544
- result = {'tags'=>['foo','bar']}
545
-
546
- index = @wiki.repo.index
547
- index.add("Bilbo-Baggins.md", content)
548
- index.commit("Add metadata")
549
-
550
- page = @wiki.page("Bilbo Baggins")
551
- rendered = Gollum::Markup.new(page).render
552
- assert_equal output, rendered
553
- assert_equal result, page.meta_data
554
- end
555
-
556
- test "metadata sanitation" do
557
- content = "a\n\n<!-- ---\nfoo: <script>alert('');</script>\n-->\n\nb"
558
- output = "<p>a</p>\n\n<p>b</p>"
559
- result = {'foo'=>nil}
560
-
561
- index = @wiki.repo.index
562
- index.add("Bilbo-Baggins.md", content)
563
- index.commit("Add metadata")
564
-
565
- page = @wiki.page("Bilbo Baggins")
566
- rendered = Gollum::Markup.new(page).render
567
- assert_equal output, rendered
568
- assert_equal result, page.meta_data
569
- end
570
-
571
- #########################################################################
572
- #
573
- # Various
574
- #
575
- #########################################################################
576
-
577
- test "strips javscript protocol urls" do
578
- content = "[Hack me](javascript:hacked=true)"
579
- output = "<p><a>Hackme</a></p>"
580
- compare(content, output)
581
- end
582
-
583
- test "allows apt uri schemes" do
584
- content = "[Hack me](apt:gettext)"
585
- output = "<p><a href=\"apt:gettext\">Hackme</a></p>"
586
- compare(content, output)
587
- end
588
-
589
- test "removes style blocks completely" do
590
- content = "<style>body { color: red }</style>foobar"
591
- output = "<p>foobar</p>"
592
- compare(content, output)
593
- end
594
-
595
- test "removes script blocks completely" do
596
- content = "<script>alert('hax');</script>foobar"
597
- output = "<p>foobar</p>"
598
- compare(content, output)
599
- end
600
-
601
- test "escaped wiki link" do
602
- content = "a '[[Foo]], b"
603
- output = "<p>a [[Foo]], b</p>"
604
- compare(content, output)
605
- end
606
-
607
- test "quoted wiki link" do
608
- content = "a '[[Foo]]', b"
609
- output = "<p>a '<a class=\"internal absent\" href=\"/Foo\">Foo</a>', b</p>"
610
- compare(content, output, 'md', [
611
- /class="internal absent"/,
612
- /href="\/Foo"/,
613
- /\>Foo\</])
614
- end
615
-
616
- test "org mode style double links" do
617
- content = "a [[http://google.com][Google]] b"
618
- output = "<p class=\"title\">a <a href=\"http://google.com\">Google</a> b</p>"
619
- compare(content, output, 'org')
620
- end
621
-
622
- test "org mode style double file links" do
623
- content = "a [[file:f.org][Google]] b"
624
- output = "<p class=\"title\">a <a class=\"internal absent\" href=\"/f\">Google</a> b</p>"
625
- compare(content, output, 'org')
626
- end
627
-
628
- test "short double links" do
629
- content = "a [[b]] c"
630
- output = %(<p class="title">a <a class="internal absent" href="/b">b</a> c</p>)
631
- compare(content, output, 'org')
632
- end
633
-
634
- test "double linked pipe" do
635
- content = "a [[|]] b"
636
- output = %(<p class="title">a <a class="internal absent" href="/"></a> b</p>)
637
- compare(content, output, 'org')
638
- end
639
-
640
- test "id with prefix ok" do
641
- content = "h2(example#wiki-foo). xxxx"
642
- output = %(<h2 class="example" id="wiki-foo">xxxx<a class=\"anchor\" id=\"xxxx\" href=\"#xxxx\"></a></h2>)
643
- compare(content, output, :textile)
644
- end
645
-
646
- test "id prefix added" do
647
- content = "h2(#foo). xxxx[1]\n\nfn1.footnote"
648
- output = "<h2 id=\"wiki-foo\">xxxx" +
649
- "<sup class=\"footnote\" id=\"wiki-fnr1\"><a href=\"#wiki-fn1\">1</a></sup>" +
650
- "<a class=\"anchor\" id=\"xxxx1\" href=\"#xxxx1\"></a></h2>" +
651
- "\n<p class=\"footnote\" id=\"wiki-fn1\"><a href=\"#wiki-fnr1\"><sup>1</sup></a> footnote</p>"
652
- compare(content, output, :textile)
653
- end
654
-
655
- test "name prefix added" do
656
- content = "abc\n\n__TOC__\n\n==Header==\n\nblah"
657
- compare content, '', :mediawiki, [
658
- /id="wiki-toc"/,
659
- /href="#wiki-Header"/,
660
- /id="wiki-Header"/,
661
- /name="wiki-Header"/
662
- ]
663
- end
664
-
665
- #########################################################################
666
- #
667
- # TeX
668
- #
669
- #########################################################################
670
-
671
- test "TeX block syntax" do
672
- content = 'a \[ a^2 \] b'
673
- output = "<p>a<imgsrc=\"http://www.mathtran.org/cgi-bin/toy/?D=4;tex=a^2\"alt=\"a^2\">b</p>"
674
- compare(content, output, 'md')
675
- end
676
-
677
- test "TeX inline syntax" do
678
- content = 'a \( a^2 \) b'
679
- output = "<p>a<imgsrc=\"http://www.mathtran.org/cgi-bin/toy/?D=2;tex=a^2\"alt=\"a^2\">b</p>"
680
- compare(content, output, 'md')
681
- end
682
-
683
- #########################################################################
684
- # Asciidoc
685
- #########################################################################
686
-
687
- test "asciidoc header" do
688
- compare("= Book Title\n\n== Heading", '<div class="sect1"><h2 id="wiki-_heading">Heading<a class="anchor" id="Heading" href="#Heading"></a></h2><div class="sectionbody"></div></div>', 'asciidoc')
689
- end
690
-
691
- test "internal links with asciidoc" do
692
- compare("= Book Title\n\n[[anid]]\n== Heading", '<div class="sect1"><h2 id="wiki-anid">Heading<a class="anchor" id="Heading" href="#Heading"></a></h2><div class="sectionbody"></div></div>', 'asciidoc')
693
- end
694
-
695
- #########################################################################
696
- #
697
- # Helpers
698
- #
699
- #########################################################################
700
-
701
- def render_page(content, ext = "md")
702
- index = @wiki.repo.index
703
- index.add("Bilbo-Baggins.#{ext}", content)
704
- index.commit("Add baggins")
705
-
706
- page = @wiki.page("Bilbo Baggins")
707
- [page, Gollum::Markup.new(page).render]
708
- end
709
-
710
- def compare(content, output, ext = "md", regexes = [])
711
- page, rendered = render_page(content, ext)
712
-
713
- if regexes.empty?
714
- assert_equal normal(output), normal(rendered)
715
- else
716
- output = page.formatted_data
717
- regexes.each { |r| assert_match r, output }
718
- end
719
- end
720
-
721
- def relative_image(content, output)
722
- index = @wiki.repo.index
723
- index.add("greek/alpha.jpg", "hi")
724
- index.add("greek/Bilbo-Baggins.md", content)
725
- index.commit("Add alpha.jpg")
726
-
727
- @wiki.clear_cache
728
- page = @wiki.page("Bilbo Baggins")
729
- rendered = Gollum::Markup.new(page).render
730
- assert_equal normal(output), normal(rendered)
731
- end
732
- end