gollum-bibanon 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/Gemfile +4 -0
  2. data/HISTORY.md +93 -0
  3. data/Home.md +3 -0
  4. data/LICENSE +21 -0
  5. data/README.md +483 -0
  6. data/Rakefile +138 -0
  7. data/bin/gollum +126 -0
  8. data/docs/sanitization.md +32 -0
  9. data/gollum.gemspec +212 -0
  10. data/lib/gollum.rb +40 -0
  11. data/lib/gollum/blob_entry.rb +78 -0
  12. data/lib/gollum/committer.rb +218 -0
  13. data/lib/gollum/file.rb +64 -0
  14. data/lib/gollum/frontend/app.rb +234 -0
  15. data/lib/gollum/frontend/public/css/dialog.css +141 -0
  16. data/lib/gollum/frontend/public/css/editor.css +537 -0
  17. data/lib/gollum/frontend/public/css/gollum.css +660 -0
  18. data/lib/gollum/frontend/public/css/ie7.css +69 -0
  19. data/lib/gollum/frontend/public/css/template.css +381 -0
  20. data/lib/gollum/frontend/public/images/icon-sprite.png +0 -0
  21. data/lib/gollum/frontend/public/javascript/editor/gollum.editor.js +1073 -0
  22. data/lib/gollum/frontend/public/javascript/editor/langs/asciidoc.js +167 -0
  23. data/lib/gollum/frontend/public/javascript/editor/langs/creole.js +104 -0
  24. data/lib/gollum/frontend/public/javascript/editor/langs/markdown.js +211 -0
  25. data/lib/gollum/frontend/public/javascript/editor/langs/org.js +173 -0
  26. data/lib/gollum/frontend/public/javascript/editor/langs/pod.js +111 -0
  27. data/lib/gollum/frontend/public/javascript/editor/langs/rdoc.js +74 -0
  28. data/lib/gollum/frontend/public/javascript/editor/langs/textile.js +175 -0
  29. data/lib/gollum/frontend/public/javascript/gollum.dialog.js +263 -0
  30. data/lib/gollum/frontend/public/javascript/gollum.js +161 -0
  31. data/lib/gollum/frontend/public/javascript/gollum.placeholder.js +54 -0
  32. data/lib/gollum/frontend/public/javascript/jquery.color.js +123 -0
  33. data/lib/gollum/frontend/public/javascript/jquery.js +7179 -0
  34. data/lib/gollum/frontend/templates/compare.mustache +53 -0
  35. data/lib/gollum/frontend/templates/create.mustache +15 -0
  36. data/lib/gollum/frontend/templates/edit.mustache +17 -0
  37. data/lib/gollum/frontend/templates/editor.mustache +116 -0
  38. data/lib/gollum/frontend/templates/error.mustache +8 -0
  39. data/lib/gollum/frontend/templates/history.mustache +60 -0
  40. data/lib/gollum/frontend/templates/layout.mustache +28 -0
  41. data/lib/gollum/frontend/templates/page.mustache +45 -0
  42. data/lib/gollum/frontend/templates/pages.mustache +35 -0
  43. data/lib/gollum/frontend/templates/search.mustache +36 -0
  44. data/lib/gollum/frontend/templates/searchbar.mustache +10 -0
  45. data/lib/gollum/frontend/views/compare.rb +94 -0
  46. data/lib/gollum/frontend/views/create.rb +44 -0
  47. data/lib/gollum/frontend/views/edit.rb +52 -0
  48. data/lib/gollum/frontend/views/editable.rb +13 -0
  49. data/lib/gollum/frontend/views/error.rb +7 -0
  50. data/lib/gollum/frontend/views/history.rb +44 -0
  51. data/lib/gollum/frontend/views/layout.rb +20 -0
  52. data/lib/gollum/frontend/views/page.rb +57 -0
  53. data/lib/gollum/frontend/views/pages.rb +19 -0
  54. data/lib/gollum/frontend/views/search.rb +20 -0
  55. data/lib/gollum/git_access.rb +248 -0
  56. data/lib/gollum/markup.rb +432 -0
  57. data/lib/gollum/page.rb +428 -0
  58. data/lib/gollum/pagination.rb +61 -0
  59. data/lib/gollum/sanitization.rb +161 -0
  60. data/lib/gollum/wiki.rb +636 -0
  61. data/templates/formatting.html +92 -0
  62. data/test/examples/empty.git/HEAD +1 -0
  63. data/test/examples/empty.git/config +5 -0
  64. data/test/examples/empty.git/description +1 -0
  65. data/test/examples/empty.git/hooks/applypatch-msg.sample +15 -0
  66. data/test/examples/empty.git/hooks/commit-msg.sample +24 -0
  67. data/test/examples/empty.git/hooks/post-commit.sample +8 -0
  68. data/test/examples/empty.git/hooks/post-receive.sample +15 -0
  69. data/test/examples/empty.git/hooks/post-update.sample +8 -0
  70. data/test/examples/empty.git/hooks/pre-applypatch.sample +14 -0
  71. data/test/examples/empty.git/hooks/pre-commit.sample +46 -0
  72. data/test/examples/empty.git/hooks/pre-rebase.sample +169 -0
  73. data/test/examples/empty.git/hooks/prepare-commit-msg.sample +36 -0
  74. data/test/examples/empty.git/hooks/update.sample +128 -0
  75. data/test/examples/empty.git/info/exclude +6 -0
  76. data/test/examples/lotr.git/COMMIT_EDITMSG +1 -0
  77. data/test/examples/lotr.git/HEAD +1 -0
  78. data/test/examples/lotr.git/config +12 -0
  79. data/test/examples/lotr.git/description +1 -0
  80. data/test/examples/lotr.git/index +0 -0
  81. data/test/examples/lotr.git/info/exclude +6 -0
  82. data/test/examples/lotr.git/logs/HEAD +3 -0
  83. data/test/examples/lotr.git/logs/refs/heads/master +3 -0
  84. data/test/examples/lotr.git/objects/06/131480411710c92a82fe2d1e76932c70feb2e5 +0 -0
  85. data/test/examples/lotr.git/objects/0a/de1e2916346d4c1f2fb63b863fd3c16808fe44 +0 -0
  86. data/test/examples/lotr.git/objects/0e/d8cbe0a25235bd867e65193c7d837c66b328ef +3 -0
  87. data/test/examples/lotr.git/objects/24/49c2681badfd3c189e8ed658dacffe8ba48fe5 +0 -0
  88. data/test/examples/lotr.git/objects/2c/b9156ad383914561a8502fc70f5a1d887e48ad +4 -0
  89. data/test/examples/lotr.git/objects/5d/cac289a8603188d2c5caf481dcba2985126aaa +0 -0
  90. data/test/examples/lotr.git/objects/60/f12f4254f58801b9ee7db7bca5fa8aeefaa56b +0 -0
  91. data/test/examples/lotr.git/objects/71/4323c104239440a5c66ab12a67ed07a83c404f +0 -0
  92. data/test/examples/lotr.git/objects/84/0ec5b1ba1320e8ec443f28f99566f615d5af10 +0 -0
  93. data/test/examples/lotr.git/objects/93/6b83ee0dd8837adb82511e40d5e4ebe59bb675 +0 -0
  94. data/test/examples/lotr.git/objects/94/523d7ae48aeba575099dd12926420d8fd0425d +2 -0
  95. data/test/examples/lotr.git/objects/96/97dc65e095658bbd1b8e8678e08881e86d32f1 +0 -0
  96. data/test/examples/lotr.git/objects/a3/1ca2a7c352c92531a8b99815d15843b259e814 +0 -0
  97. data/test/examples/lotr.git/objects/a8/ad3c09dd842a3517085bfadd37718856dee813 +0 -0
  98. data/test/examples/lotr.git/objects/aa/b61fe89d56f8614c0a8151da34f939dcedfa68 +0 -0
  99. data/test/examples/lotr.git/objects/c3/b43e9f08966b088e7a0192e436b7a884542e05 +0 -0
  100. data/test/examples/lotr.git/objects/dc/596d6b2dd89ab05c66f4abd7d5eb706bc17f19 +0 -0
  101. data/test/examples/lotr.git/objects/ec/da3205bee14520aab5a7bb307392064b938e83 +0 -0
  102. data/test/examples/lotr.git/objects/fa/e7ef5344202bba4129abdc13060d9297d99465 +3 -0
  103. data/test/examples/lotr.git/objects/info/packs +2 -0
  104. data/test/examples/lotr.git/objects/pack/pack-dcbeaf3f6ff6c5eb08ea2b0a2d83626e8763546b.idx +0 -0
  105. data/test/examples/lotr.git/objects/pack/pack-dcbeaf3f6ff6c5eb08ea2b0a2d83626e8763546b.pack +0 -0
  106. data/test/examples/lotr.git/packed-refs +2 -0
  107. data/test/examples/lotr.git/refs/heads/master +1 -0
  108. data/test/examples/lotr.git/refs/remotes/origin/HEAD +1 -0
  109. data/test/examples/page_file_dir.git/COMMIT_EDITMSG +1 -0
  110. data/test/examples/page_file_dir.git/HEAD +1 -0
  111. data/test/examples/page_file_dir.git/config +6 -0
  112. data/test/examples/page_file_dir.git/description +1 -0
  113. data/test/examples/page_file_dir.git/index +0 -0
  114. data/test/examples/page_file_dir.git/info/exclude +6 -0
  115. data/test/examples/page_file_dir.git/logs/HEAD +1 -0
  116. data/test/examples/page_file_dir.git/logs/refs/heads/master +1 -0
  117. data/test/examples/page_file_dir.git/objects/0c/7d27db1f575263efdcab3dc650f4502a2dbcbf +0 -0
  118. data/test/examples/page_file_dir.git/objects/22/b404803c966dd92865614d86ff22ca12e50c1e +0 -0
  119. data/test/examples/page_file_dir.git/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 +0 -0
  120. data/test/examples/page_file_dir.git/objects/57/16ca5987cbf97d6bb54920bea6adde242d87e6 +0 -0
  121. data/test/examples/page_file_dir.git/objects/5b/43e14e0a15fb6f08feab1773d1c0991e9f71e2 +0 -0
  122. data/test/examples/page_file_dir.git/refs/heads/master +1 -0
  123. data/test/examples/revert.git/COMMIT_EDITMSG +1 -0
  124. data/test/examples/revert.git/HEAD +1 -0
  125. data/test/examples/revert.git/config +12 -0
  126. data/test/examples/revert.git/description +1 -0
  127. data/test/examples/revert.git/index +0 -0
  128. data/test/examples/revert.git/info/exclude +6 -0
  129. data/test/examples/revert.git/logs/HEAD +2 -0
  130. data/test/examples/revert.git/logs/refs/heads/master +2 -0
  131. data/test/examples/revert.git/objects/20/2ced67cea93c7b6bd2928aa1daef8d1d55a20d +0 -0
  132. data/test/examples/revert.git/objects/41/76394bfa11222363c66ce7e84b5f154095b6d9 +0 -0
  133. data/test/examples/revert.git/objects/6a/69f92020f5df77af6e8813ff1232493383b708 +0 -0
  134. data/test/examples/revert.git/objects/b4/785957bc986dc39c629de9fac9df46972c00fc +0 -0
  135. data/test/examples/revert.git/objects/f4/03b791119f8232b7cb0ba455c624ac6435f433 +0 -0
  136. data/test/examples/revert.git/objects/info/packs +2 -0
  137. data/test/examples/revert.git/objects/pack/pack-a561f8437234f74d0bacb9e0eebe52d207f5770d.idx +0 -0
  138. data/test/examples/revert.git/objects/pack/pack-a561f8437234f74d0bacb9e0eebe52d207f5770d.pack +0 -0
  139. data/test/examples/revert.git/packed-refs +2 -0
  140. data/test/examples/revert.git/refs/heads/master +1 -0
  141. data/test/examples/revert.git/refs/remotes/origin/HEAD +1 -0
  142. data/test/examples/yubiwa.git/HEAD +1 -0
  143. data/test/examples/yubiwa.git/config +5 -0
  144. data/test/examples/yubiwa.git/description +1 -0
  145. data/test/examples/yubiwa.git/info/exclude +6 -0
  146. data/test/examples/yubiwa.git/objects/10/fa2ddc4e3b4009d8a453aace10bd6148c1ad00 +0 -0
  147. data/test/examples/yubiwa.git/objects/52/4b82874327ea7cbf730389964ba7cb3de966de +0 -0
  148. data/test/examples/yubiwa.git/objects/58/3fc201cb457fb3f1480f3e1e5999b119633835 +0 -0
  149. data/test/examples/yubiwa.git/objects/87/bc1dd46ab3d3874d4e898d45dd512cc20a7cc8 +1 -0
  150. data/test/examples/yubiwa.git/objects/89/64ed1b4e21aa90e831763bbce9034bfda81b70 +0 -0
  151. data/test/examples/yubiwa.git/objects/9f/f6dd0660da5fba2d3374adb2b84fa653bb538b +0 -0
  152. data/test/examples/yubiwa.git/objects/ac/e97abf2b177815a1972d7db22f229f58c83309 +0 -0
  153. data/test/examples/yubiwa.git/objects/b1/f443863a4816628807fbf86141ebef055dda34 +0 -0
  154. data/test/examples/yubiwa.git/refs/heads/master +1 -0
  155. data/test/helper.rb +66 -0
  156. data/test/test_app.rb +179 -0
  157. data/test/test_committer.rb +64 -0
  158. data/test/test_file.rb +27 -0
  159. data/test/test_git_access.rb +52 -0
  160. data/test/test_markup.rb +580 -0
  161. data/test/test_page.rb +166 -0
  162. data/test/test_page_revert.rb +45 -0
  163. data/test/test_wiki.rb +462 -0
  164. metadata +493 -0
data/test/test_app.rb ADDED
@@ -0,0 +1,179 @@
1
+ # ~*~ encoding: utf-8 ~*~
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
3
+
4
+ context "Frontend" do
5
+ include Rack::Test::Methods
6
+
7
+ setup do
8
+ @path = cloned_testpath("examples/revert.git")
9
+ @wiki = Gollum::Wiki.new(@path)
10
+ Precious::App.set(:gollum_path, @path)
11
+ Precious::App.set(:wiki_options, {})
12
+ end
13
+
14
+ teardown do
15
+ FileUtils.rm_rf(@path)
16
+ end
17
+
18
+ test "edits page" do
19
+ page_1 = @wiki.page('A')
20
+ post "/edit/A", :content => 'abc',
21
+ :format => page_1.format, :message => 'def'
22
+ follow_redirect!
23
+ assert last_response.ok?
24
+
25
+ @wiki.clear_cache
26
+ page_2 = @wiki.page(page_1.name)
27
+ assert_equal 'abc', page_2.raw_data
28
+ assert_equal 'def', page_2.version.message
29
+ assert_not_equal page_1.version.sha, page_2.version.sha
30
+ end
31
+
32
+ test "edits page footer and sidebar" do
33
+ commits = @wiki.repo.commits('master').size
34
+ page_1 = @wiki.page('A')
35
+ foot_1 = page_1.footer
36
+ side_1 = page_1.sidebar
37
+
38
+ post "/edit/A",
39
+ :footer => 'footer', :page => "A", :sidebar => 'sidebar', :message => 'def'
40
+ follow_redirect!
41
+ assert_equal "/A", last_request.fullpath
42
+ assert last_response.ok?
43
+
44
+ @wiki.clear_cache
45
+ page_2 = @wiki.page(page_1.name)
46
+ foot_2 = page_2.footer
47
+ side_2 = page_2.sidebar
48
+ assert_equal page_1.raw_data, page_2.raw_data
49
+
50
+ assert_equal 'footer', foot_2.raw_data
51
+ assert_equal 'def', foot_2.version.message
52
+ assert_not_equal foot_1.version.sha, foot_2.version.sha
53
+
54
+ assert_equal 'sidebar', side_2.raw_data
55
+ assert_equal 'def', side_2.version.message
56
+ assert_not_equal side_1.version.sha, side_2.version.sha
57
+ assert_equal commits+1, @wiki.repo.commits('master').size
58
+ end
59
+
60
+ test "renames page" do
61
+ page_1 = @wiki.page('B')
62
+ post "/edit/B", :content => 'abc',
63
+ :rename => "C",
64
+ :format => page_1.format, :message => 'def'
65
+ follow_redirect!
66
+ assert_equal "/C", last_request.fullpath
67
+ assert last_response.ok?
68
+
69
+ @wiki.clear_cache
70
+ assert_nil @wiki.page("B")
71
+ page_2 = @wiki.page('C')
72
+ assert_equal 'abc', page_2.raw_data
73
+ assert_equal 'def', page_2.version.message
74
+ assert_not_equal page_1.version.sha, page_2.version.sha
75
+ end
76
+
77
+ test "creates page" do
78
+ post "/create", :content => 'abc', :page => "D",
79
+ :format => 'markdown', :message => 'def'
80
+ follow_redirect!
81
+ assert last_response.ok?
82
+
83
+ page = @wiki.page('D')
84
+ assert_equal 'abc', page.raw_data
85
+ assert_equal 'def', page.version.message
86
+ end
87
+
88
+ test "redirects to create on non-existant page" do
89
+ name = "E"
90
+ get "/#{name}"
91
+ follow_redirect!
92
+ assert_equal "/create/#{name}", last_request.fullpath
93
+ assert last_response.ok?
94
+ end
95
+
96
+ test "edit redirects to create on non-existant page" do
97
+ name = "E"
98
+ get "/edit/#{name}"
99
+ follow_redirect!
100
+ assert_equal "/create/#{name}", last_request.fullpath
101
+ assert last_response.ok?
102
+ end
103
+
104
+ test "create redirects to page if already exists" do
105
+ name = "A"
106
+ get "/create/#{name}"
107
+ follow_redirect!
108
+ assert_equal "/#{name}", last_request.fullpath
109
+ assert last_response.ok?
110
+ end
111
+
112
+ test "guards against creation of existing page" do
113
+ name = "A"
114
+ post "/create", :content => 'abc', :page => name,
115
+ :format => 'markdown', :message => 'def'
116
+ assert last_response.ok?
117
+
118
+ @wiki.clear_cache
119
+ page = @wiki.page(name)
120
+ assert_not_equal 'abc', page.raw_data
121
+ end
122
+
123
+ test "previews content" do
124
+ post "/preview", :content => 'abc', :format => 'markdown'
125
+ assert last_response.ok?
126
+ end
127
+
128
+ test "previews content on the first page of an empty wiki" do
129
+ @path = cloned_testpath("examples/empty.git")
130
+ @wiki = Gollum::Wiki.new(@path)
131
+ Precious::App.set(:gollum_path, @path)
132
+ Precious::App.set(:wiki_options, {})
133
+
134
+ post "/preview", :content => 'abc', :format => 'markdown'
135
+ assert last_response.ok?
136
+ end
137
+
138
+
139
+ test "reverts single commit" do
140
+ page1 = @wiki.page('B')
141
+
142
+ post "/revert/B/7c45b5f16ff3bae2a0063191ef832701214d4df5"
143
+ follow_redirect!
144
+ assert last_response.ok?
145
+
146
+ @wiki.clear_cache
147
+ page2 = @wiki.page('B')
148
+ assert_not_equal page1.version.sha, page2.version.sha
149
+ assert_equal "INITIAL", page2.raw_data.strip
150
+ end
151
+
152
+ test "reverts multiple commits" do
153
+ page1 = @wiki.page('A')
154
+
155
+ post "/revert/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac/b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f"
156
+ follow_redirect!
157
+ assert last_response.ok?
158
+
159
+ @wiki.clear_cache
160
+ page2 = @wiki.page('A')
161
+ assert_not_equal page1.version.sha, page2.version.sha
162
+ assert_equal "INITIAL", page2.raw_data.strip
163
+ end
164
+
165
+ test "cannot revert conflicting commit" do
166
+ page1 = @wiki.page('A')
167
+
168
+ post "/revert/A/302a5491a9a5ba12c7652ac831a44961afa312d2"
169
+ assert last_response.ok?
170
+
171
+ @wiki.clear_cache
172
+ page2 = @wiki.page('A')
173
+ assert_equal page1.version.sha, page2.version.sha
174
+ end
175
+
176
+ def app
177
+ Precious::App
178
+ end
179
+ end
@@ -0,0 +1,64 @@
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']
12
+ email = @wiki.repo.config['user.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 = '1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3'
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 ADDED
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,52 @@
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"=>"1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3"}, @access.ref_map)
22
+
23
+ map = @access.tree_map['1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3']
24
+ assert_equal 'Bilbo-Baggins.md', map[0].path
25
+ assert_equal '', map[0].dir
26
+ assert_equal map[0].path, map[0].name
27
+ assert_equal 'Mordor/Eye-Of-Sauron.md', map[3].path
28
+ assert_equal '/Mordor', map[3].dir
29
+ assert_equal 'Eye-Of-Sauron.md', map[3].name
30
+ end
31
+
32
+ test "#tree_map_for only caches tree for commit" do
33
+ assert @access.tree_map.empty?
34
+ @access.tree '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
35
+ assert @access.ref_map.empty?
36
+
37
+ entry = @access.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0]
38
+ assert_equal 'Bilbo-Baggins.md', entry.path
39
+ end
40
+
41
+ test "cannot access commit from invalid ref" do
42
+ assert_nil @access.commit('foo')
43
+ end
44
+
45
+ test "cannot access sha from invalid ref" do
46
+ assert_nil @access.ref_to_sha('foo')
47
+ end
48
+
49
+ test "cannot access tree from invalid ref" do
50
+ assert_equal [], @access.tree('foo')
51
+ end
52
+ end
@@ -0,0 +1,580 @@
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
+ @wiki = Gollum::Wiki.new(@path)
10
+ end
11
+
12
+ teardown do
13
+ FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
14
+ end
15
+
16
+ test "formats page from Wiki#pages" do
17
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details)
18
+ assert @wiki.pages[0].formatted_data
19
+ end
20
+
21
+ # This test is to assume that Sanitize.clean doesn't raise Encoding::CompatibilityError on ruby 1.9
22
+ test "formats non ASCII-7 character page from Wiki#pages" do
23
+ wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git"))
24
+ assert_nothing_raised(defined?(Encoding) && Encoding::CompatibilityError) do
25
+ assert wiki.page("strider").formatted_data
26
+ end
27
+ end
28
+
29
+ test "Gollum::Markup#render yields a DocumentFragment" do
30
+ yielded = false
31
+ @wiki.write_page("Yielded", :markdown, "abc", commit_details)
32
+
33
+ page = @wiki.page("Yielded")
34
+ markup = Gollum::Markup.new(page)
35
+ markup.render do |doc|
36
+ assert_kind_of Nokogiri::HTML::DocumentFragment, doc
37
+ yielded = true
38
+ end
39
+ assert yielded
40
+ end
41
+
42
+ test "Gollum::Page#formatted_data yields a DocumentFragment" do
43
+ yielded = false
44
+ @wiki.write_page("Yielded", :markdown, "abc", commit_details)
45
+
46
+ page = @wiki.page("Yielded")
47
+ page.formatted_data do |doc|
48
+ assert_kind_of Nokogiri::HTML::DocumentFragment, doc
49
+ yielded = true
50
+ end
51
+ assert yielded
52
+ end
53
+
54
+ #########################################################################
55
+ #
56
+ # Links
57
+ #
58
+ #########################################################################
59
+
60
+ test "double page links no space" do
61
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]][[Bar]] b", commit_details)
62
+
63
+ # "<p>a <a class=\"internal absent\" href=\"/Foo\">Foo</a><a class=\"internal absent\" href=\"/Bar\">Bar</a> b</p>"
64
+ page = @wiki.page("Bilbo Baggins")
65
+ doc = Nokogiri::HTML page.formatted_data
66
+ paras = doc / :p
67
+ para = paras.first
68
+ anchors = para / :a
69
+ assert_equal 1, paras.size
70
+ assert_equal 2, anchors.size
71
+ assert_equal 'internal absent', anchors[0]['class']
72
+ assert_equal 'internal absent', anchors[1]['class']
73
+ assert_equal '/Foo', anchors[0]['href']
74
+ assert_equal '/Bar', anchors[1]['href']
75
+ assert_equal 'Foo', anchors[0].text
76
+ assert_equal 'Bar', anchors[1].text
77
+ end
78
+
79
+ test "double page links with space" do
80
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Foo]] [[Bar]] b", commit_details)
81
+
82
+ # "<p>a <a class=\"internal absent\" href=\"/Foo\">Foo</a> <a class=\"internal absent\" href=\"/Bar\">Bar</a> b</p>"
83
+ page = @wiki.page("Bilbo Baggins")
84
+ doc = Nokogiri::HTML page.formatted_data
85
+ paras = doc / :p
86
+ para = paras.first
87
+ anchors = para / :a
88
+ assert_equal 1, paras.size
89
+ assert_equal 2, anchors.size
90
+ assert_equal 'internal absent', anchors[0]['class']
91
+ assert_equal 'internal absent', anchors[1]['class']
92
+ assert_equal '/Foo', anchors[0]['href']
93
+ assert_equal '/Bar', anchors[1]['href']
94
+ assert_equal 'Foo', anchors[0].text
95
+ assert_equal 'Bar', anchors[1].text
96
+ end
97
+
98
+ test "page link" do
99
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", commit_details)
100
+
101
+ page = @wiki.page("Bilbo Baggins")
102
+ output = page.formatted_data
103
+ assert_match /class="internal present"/, output
104
+ assert_match /href="\/Bilbo-Baggins"/, output
105
+ assert_match /\>Bilbo Baggins\</, output
106
+ end
107
+
108
+ test "adds nofollow to links on historical pages" do
109
+ sha1 = @wiki.write_page("Sauron", :markdown, "a [[b]] c", commit_details)
110
+ page = @wiki.page("Sauron")
111
+ sha2 = @wiki.update_page(page, page.name, :markdown, "c [[b]] a", commit_details)
112
+ regx = /rel="nofollow"/
113
+ assert_no_match regx, page.formatted_data
114
+ assert_match regx, @wiki.page(page.name, sha1).formatted_data
115
+ assert_match regx, @wiki.page(page.name, sha2).formatted_data
116
+ end
117
+
118
+ test "absent page link" do
119
+ @wiki.write_page("Tolkien", :markdown, "a [[J. R. R. Tolkien]]'s b", commit_details)
120
+
121
+ page = @wiki.page("Tolkien")
122
+ output = page.formatted_data
123
+ assert_match /class="internal absent"/, output
124
+ assert_match /href="\/J\.\-R\.\-R\.\-Tolkien"/, output
125
+ assert_match /\>J\. R\. R\. Tolkien\</, output
126
+ end
127
+
128
+ test "page link with custom base path" do
129
+ ["/wiki", "/wiki/"].each_with_index do |path, i|
130
+ name = "Bilbo Baggins #{i}"
131
+ @wiki = Gollum::Wiki.new(@path, :base_path => path)
132
+ @wiki.write_page(name, :markdown, "a [[#{name}]] b", commit_details)
133
+
134
+ page = @wiki.page(name)
135
+ output = page.formatted_data
136
+ assert_match /class="internal present"/, output
137
+ assert_match /href="\/wiki\/Bilbo-Baggins-\d"/, output
138
+ assert_match /\>Bilbo Baggins \d\</, output
139
+ end
140
+ end
141
+
142
+ test "page link with included #" do
143
+ @wiki.write_page("Precious #1", :markdown, "a [[Precious #1]] b", commit_details)
144
+ page = @wiki.page('Precious #1')
145
+ output = page.formatted_data
146
+ assert_match /class="internal present"/, output
147
+ assert_match /href="\/Precious-%231"/, output
148
+ end
149
+
150
+ test "page link with extra #" do
151
+ @wiki.write_page("Potato", :markdown, "a [[Potato#1]] b", commit_details)
152
+ page = @wiki.page('Potato')
153
+ output = page.formatted_data
154
+ assert_match /class="internal present"/, output
155
+ assert_match /href="\/Potato#1"/, output
156
+ end
157
+
158
+ test "external page link" do
159
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", commit_details)
160
+
161
+ page = @wiki.page("Bilbo Baggins")
162
+ assert_equal "<p>a <a href=\"http://example.com\">http://example.com</a> b</p>", page.formatted_data
163
+ end
164
+
165
+ test "page link with different text" do
166
+ @wiki.write_page("Potato", :markdown, "a [[Potato Heaad|Potato]] ", commit_details)
167
+ page = @wiki.page("Potato")
168
+ output = page.formatted_data
169
+ assert_equal "<p>a<aclass=\"internalpresent\"href=\"/Potato\">PotatoHeaad</a></p>", normal(output)
170
+ end
171
+
172
+ test "page link with different text on mediawiki" do
173
+ @wiki.write_page("Potato", :mediawiki, "a [[Potato|Potato Heaad]] ", commit_details)
174
+ page = @wiki.page("Potato")
175
+ output = page.formatted_data
176
+ assert_equal normal("<p>\na <a class=\"internal present\" href=\"/Potato\">Potato Heaad</a> </p>"), normal(output)
177
+ end
178
+
179
+ #########################################################################
180
+ #
181
+ # Images
182
+ #
183
+ #########################################################################
184
+
185
+ test "image with http url" do
186
+ ['http', 'https'].each do |scheme|
187
+ name = "Bilbo Baggins #{scheme}"
188
+ @wiki.write_page(name, :markdown, "a [[#{scheme}://example.com/bilbo.jpg]] b", commit_details)
189
+
190
+ page = @wiki.page(name)
191
+ output = page.formatted_data
192
+ assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.jpg"> b</p>}, output
193
+ end
194
+ end
195
+
196
+ test "image with extension in caps with http url" do
197
+ ['http', 'https'].each do |scheme|
198
+ name = "Bilbo Baggins #{scheme}"
199
+ @wiki.write_page(name, :markdown, "a [[#{scheme}://example.com/bilbo.JPG]] b", commit_details)
200
+
201
+ page = @wiki.page(name)
202
+ output = page.formatted_data
203
+ assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.JPG"> b</p>}, output
204
+ end
205
+ end
206
+
207
+ test "image with absolute path" do
208
+ @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
209
+ index = @wiki.repo.index
210
+ index.add("alpha.jpg", "hi")
211
+ index.commit("Add alpha.jpg")
212
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[/alpha.jpg]] [[a | /alpha.jpg]] b", commit_details)
213
+
214
+ page = @wiki.page("Bilbo Baggins")
215
+ assert_equal %{<p>a <img src="/wiki/alpha.jpg"><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data
216
+ end
217
+
218
+ test "image with relative path on root" do
219
+ @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
220
+ index = @wiki.repo.index
221
+ index.add("alpha.jpg", "hi")
222
+ index.add("Bilbo-Baggins.md", "a [[alpha.jpg]] [[a | alpha.jpg]] b")
223
+ index.commit("Add alpha.jpg")
224
+
225
+ page = @wiki.page("Bilbo Baggins")
226
+ assert_equal %{<p>a <img src="/wiki/alpha.jpg"><a href="/wiki/alpha.jpg">a</a> b</p>}, page.formatted_data
227
+ end
228
+
229
+ test "image with relative path" do
230
+ @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
231
+ index = @wiki.repo.index
232
+ index.add("greek/alpha.jpg", "hi")
233
+ index.add("greek/Bilbo-Baggins.md", "a [[alpha.jpg]] [[a | alpha.jpg]] b")
234
+ index.commit("Add alpha.jpg")
235
+
236
+ page = @wiki.page("Bilbo Baggins")
237
+ output = page.formatted_data
238
+ assert_equal %{<p>a <img src="/wiki/greek/alpha.jpg"><a href="/wiki/greek/alpha.jpg">a</a> b</p>}, output
239
+ end
240
+
241
+ test "image with absolute path on a preview" do
242
+ @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
243
+ index = @wiki.repo.index
244
+ index.add("alpha.jpg", "hi")
245
+ index.commit("Add alpha.jpg")
246
+
247
+ page = @wiki.preview_page("Test", "a [[/alpha.jpg]] b", :markdown)
248
+ assert_equal %{<p>a <img src="/wiki/alpha.jpg"> b</p>}, page.formatted_data
249
+ end
250
+
251
+ test "image with relative path on a preview" do
252
+ @wiki = Gollum::Wiki.new(@path, :base_path => '/wiki')
253
+ index = @wiki.repo.index
254
+ index.add("alpha.jpg", "hi")
255
+ index.add("greek/alpha.jpg", "hi")
256
+ index.commit("Add alpha.jpg")
257
+
258
+ page = @wiki.preview_page("Test", "a [[alpha.jpg]] [[greek/alpha.jpg]] b", :markdown)
259
+ assert_equal %{<p>a <img src="/wiki/alpha.jpg"><img src="/wiki/greek/alpha.jpg"> b</p>}, page.formatted_data
260
+ end
261
+
262
+ test "image with alt" do
263
+ content = "a [[alpha.jpg|alt=Alpha Dog]] b"
264
+ output = %{<p>a <img src="/greek/alpha.jpg" alt="Alpha Dog"> b</p>}
265
+ relative_image(content, output)
266
+ end
267
+
268
+ test "image with em or px dimension" do
269
+ %w{em px}.each do |unit|
270
+ %w{width height}.each do |dim|
271
+ content = "a [[alpha.jpg|#{dim}=100#{unit}]] b"
272
+ output = "<p>a <img src=\"/greek/alpha.jpg\" #{dim}=\"100#{unit}\"> b</p>"
273
+ relative_image(content, output)
274
+ end
275
+ end
276
+ end
277
+
278
+ test "image with bogus dimension" do
279
+ %w{width height}.each do |dim|
280
+ content = "a [[alpha.jpg|#{dim}=100]] b"
281
+ output = "<p>a <img src=\"/greek/alpha.jpg\"> b</p>"
282
+ relative_image(content, output)
283
+ end
284
+ end
285
+
286
+ test "image with vertical align" do
287
+ %w{top texttop middle absmiddle bottom absbottom baseline}.each do |align|
288
+ content = "a [[alpha.jpg|align=#{align}]] b"
289
+ output = "<p>a <img src=\"/greek/alpha.jpg\" align=\"#{align}\"> b</p>"
290
+ relative_image(content, output)
291
+ end
292
+ end
293
+
294
+ test "image with horizontal align" do
295
+ %w{left center right}.each do |align|
296
+ content = "a [[alpha.jpg|align=#{align}]] b"
297
+ output = "<p>a <span class=\"align-#{align}\"><span><img src=\"/greek/alpha.jpg\"></span></span> b</p>"
298
+ relative_image(content, output)
299
+ end
300
+ end
301
+
302
+ test "image with float" do
303
+ content = "a\n\n[[alpha.jpg|float]]\n\nb"
304
+ 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>"
305
+ relative_image(content, output)
306
+ end
307
+
308
+ test "image with float and align" do
309
+ %w{left right}.each do |align|
310
+ content = "a\n\n[[alpha.jpg|float|align=#{align}]]\n\nb"
311
+ 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>"
312
+ relative_image(content, output)
313
+ end
314
+ end
315
+
316
+ test "image with frame" do
317
+ content = "a\n\n[[alpha.jpg|frame]]\n\nb"
318
+ output = "<p>a</p>\n\n<p><span class=\"frame\"><span><img src=\"/greek/alpha.jpg\"></span></span></p>\n\n<p>b</p>"
319
+ relative_image(content, output)
320
+ end
321
+
322
+ test "absolute image with frame" do
323
+ content = "a\n\n[[http://example.com/bilbo.jpg|frame]]\n\nb"
324
+ 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>"
325
+ relative_image(content, output)
326
+ end
327
+
328
+ test "image with frame and alt" do
329
+ content = "a\n\n[[alpha.jpg|frame|alt=Alpha]]\n\nb"
330
+ 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>"
331
+ relative_image(content, output)
332
+ end
333
+
334
+ #########################################################################
335
+ #
336
+ # File links
337
+ #
338
+ #########################################################################
339
+
340
+ test "file link with absolute path" do
341
+ index = @wiki.repo.index
342
+ index.add("alpha.jpg", "hi")
343
+ index.commit("Add alpha.jpg")
344
+ @wiki.write_page("Bilbo Baggins", :markdown, "a [[Alpha|/alpha.jpg]] b", commit_details)
345
+
346
+ page = @wiki.page("Bilbo Baggins")
347
+ output = Gollum::Markup.new(page).render
348
+ assert_equal %{<p>a <a href="/alpha.jpg">Alpha</a> b</p>}, output
349
+ end
350
+
351
+ test "file link with relative path" do
352
+ index = @wiki.repo.index
353
+ index.add("greek/alpha.jpg", "hi")
354
+ index.add("greek/Bilbo-Baggins.md", "a [[Alpha|alpha.jpg]] b")
355
+ index.commit("Add alpha.jpg")
356
+
357
+ page = @wiki.page("Bilbo Baggins")
358
+ output = Gollum::Markup.new(page).render
359
+ assert_equal %{<p>a <a href="/greek/alpha.jpg">Alpha</a> b</p>}, output
360
+ end
361
+
362
+ test "file link with external path" do
363
+ index = @wiki.repo.index
364
+ index.add("greek/Bilbo-Baggins.md", "a [[Alpha|http://example.com/alpha.jpg]] b")
365
+ index.commit("Add alpha.jpg")
366
+
367
+ page = @wiki.page("Bilbo Baggins")
368
+ assert_equal %{<p>a <a href="http://example.com/alpha.jpg">Alpha</a> b</p>}, page.formatted_data
369
+ end
370
+
371
+ #########################################################################
372
+ #
373
+ # Code
374
+ #
375
+ #########################################################################
376
+
377
+ test "code blocks" do
378
+ content = "a\n\n```ruby\nx = 1\n```\n\nb"
379
+ output = "<p>a</p>\n\n<div class=\"highlight\">\n<pre>" +
380
+ "<span class=\"n\">x</span> <span class=\"o\">=</span> " +
381
+ "<span class=\"mi\">1</span>\n</pre>\n</div>\n\n\n<p>b</p>"
382
+
383
+ index = @wiki.repo.index
384
+ index.add("Bilbo-Baggins.md", content)
385
+ index.commit("Add alpha.jpg")
386
+
387
+ page = @wiki.page("Bilbo Baggins")
388
+ rendered = Gollum::Markup.new(page).render
389
+ assert_equal output, rendered
390
+ end
391
+
392
+ test "code blocks with carriage returns" do
393
+ content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb"
394
+ output = "<p>a</p>\n\n<div class=\"highlight\">\n<pre>" +
395
+ "<span class=\"n\">x</span> <span class=\"o\">=</span> " +
396
+ "<span class=\"mi\">1</span>\n</pre>\n</div>\n\n\n<p>b</p>"
397
+
398
+ index = @wiki.repo.index
399
+ index.add("Bilbo-Baggins.md", content)
400
+ index.commit("Add alpha.jpg")
401
+
402
+ page = @wiki.page("Bilbo Baggins")
403
+ rendered = Gollum::Markup.new(page).render
404
+ assert_equal output, rendered
405
+ end
406
+
407
+ test "code blocks with two-space indent" do
408
+ content = "a\n\n```ruby\n x = 1\n\n y = 2\n```\n\nb"
409
+ output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
410
+ "x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
411
+ "</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
412
+ "</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
413
+ compare(content, output)
414
+ end
415
+
416
+ test "code blocks with one-tab indent" do
417
+ content = "a\n\n```ruby\n\tx = 1\n\n\ty = 2\n```\n\nb"
418
+ output = "<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"n\">" +
419
+ "x</span> <span class=\"o\">=</span> <span class=\"mi\">1" +
420
+ "</span>\n\n<span class=\"n\">y</span> <span class=\"o\">=" +
421
+ "</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
422
+ compare(content, output)
423
+ end
424
+
425
+ test "code with wiki links" do
426
+ content = <<-END
427
+ booya
428
+
429
+ ``` python
430
+ np.array([[2,2],[1,3]],np.float)
431
+ ```
432
+ END
433
+
434
+ # rendered with Gollum::Markup
435
+ page, rendered = render_page(content)
436
+ assert_markup_highlights_code Gollum::Markup, rendered
437
+
438
+ if Gollum.const_defined?(:MarkupGFM)
439
+ rendered_gfm = Gollum::MarkupGFM.new(page).render
440
+ assert_markup_highlights_code Gollum::MarkupGFM, rendered_gfm
441
+ end
442
+ end
443
+
444
+ def assert_markup_highlights_code(markup_class, rendered)
445
+ assert_match /div class="highlight"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
446
+ assert_match /span class="n"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
447
+ assert_match /\(\[\[/, rendered, "#{markup_class} parses out wiki links\n#{rendered}"
448
+ end
449
+
450
+ #########################################################################
451
+ #
452
+ # Various
453
+ #
454
+ #########################################################################
455
+
456
+ test "strips javscript protocol urls" do
457
+ content = "[Hack me](javascript:hacked=true)"
458
+ output = "<p><a>Hackme</a></p>"
459
+ compare(content, output)
460
+ end
461
+
462
+ test "escaped wiki link" do
463
+ content = "a '[[Foo]], b"
464
+ output = "<p>a [[Foo]], b</p>"
465
+ compare(content, output)
466
+ end
467
+
468
+ test "quoted wiki link" do
469
+ content = "a '[[Foo]]', b"
470
+ output = "<p>a '<a class=\"internal absent\" href=\"/Foo\">Foo</a>', b</p>"
471
+ compare(content, output, 'md', [
472
+ /class="internal absent"/,
473
+ /href="\/Foo"/,
474
+ /\>Foo\</])
475
+ end
476
+
477
+ test "org mode style double links" do
478
+ content = "a [[http://google.com][Google]] b"
479
+ output = "<p class=\"title\">a <a href=\"http://google.com\">Google</a> b</p>"
480
+ compare(content, output, 'org')
481
+ end
482
+
483
+ test "org mode style double file links" do
484
+ content = "a [[file:f.org][Google]] b"
485
+ output = "<p class=\"title\">a <a class=\"internal absent\" href=\"/f\">Google</a> b</p>"
486
+ compare(content, output, 'org')
487
+ end
488
+
489
+ test "short double links" do
490
+ content = "a [[b]] c"
491
+ output = %(<p class="title">a <a class="internal absent" href="/b">b</a> c</p>)
492
+ compare(content, output, 'org')
493
+ end
494
+
495
+ test "double linked pipe" do
496
+ content = "a [[|]] b"
497
+ output = %(<p class="title">a <a class="internal absent" href="/"></a> b</p>)
498
+ compare(content, output, 'org')
499
+ end
500
+
501
+ # test "id with prefix ok" do
502
+ # content = "h2(example#wiki-foo). xxxx"
503
+ # output = %(<h2 class="example" id="wiki-foo">xxxx</h2>)
504
+ # compare(content, output, :textile)
505
+ # end
506
+
507
+ # test "id prefix added" do
508
+ # content = "h2(#foo). xxxx[1]\n\nfn1.footnote"
509
+ # output = "<h2 id=\"wiki-foo\">xxxx" +
510
+ # "<sup class=\"footnote\" id=\"wiki-fnr1\"><a href=\"#wiki-fn1\">1</a></sup></h2>" +
511
+ # "\n<p class=\"footnote\" id=\"wiki-fn1\"><a href=\"#wiki-fnr1\"><sup>1</sup></a> footnote</p>"
512
+ # compare(content, output, :textile)
513
+ # end
514
+
515
+ # test "name prefix added" do
516
+ # content = "abc\n\n__TOC__\n\n==Header==\n\nblah"
517
+ # compare content, '', :mediawiki, [
518
+ # /id="wiki-toc"/,
519
+ # /href="#wiki-Header"/,
520
+ # /id="wiki-Header"/,
521
+ # /name="wiki-Header"/
522
+ # ]
523
+ # end
524
+
525
+ #########################################################################
526
+ #
527
+ # TeX
528
+ #
529
+ #########################################################################
530
+
531
+ test "TeX block syntax" do
532
+ content = 'a \[ a^2 \] b'
533
+ output = "<p>a<imgsrc=\"/_tex.png?type=block&data=YV4y\"alt=\"a^2\">b</p>"
534
+ compare(content, output, 'md')
535
+ end
536
+
537
+ test "TeX inline syntax" do
538
+ content = 'a \( a^2 \) b'
539
+ output = "<p>a<imgsrc=\"/_tex.png?type=inline&data=YV4y\"alt=\"a^2\">b</p>"
540
+ compare(content, output, 'md')
541
+ end
542
+
543
+ #########################################################################
544
+ #
545
+ # Helpers
546
+ #
547
+ #########################################################################
548
+
549
+ def render_page(content, ext = "md")
550
+ index = @wiki.repo.index
551
+ index.add("Bilbo-Baggins.#{ext}", content)
552
+ index.commit("Add baggins")
553
+
554
+ page = @wiki.page("Bilbo Baggins")
555
+ [page, Gollum::Markup.new(page).render]
556
+ end
557
+
558
+ def compare(content, output, ext = "md", regexes = [])
559
+ page, rendered = render_page(content, ext)
560
+
561
+ if regexes.empty?
562
+ assert_equal normal(output), normal(rendered)
563
+ else
564
+ output = page.formatted_data
565
+ regexes.each { |r| assert_match r, output }
566
+ end
567
+ end
568
+
569
+ def relative_image(content, output)
570
+ index = @wiki.repo.index
571
+ index.add("greek/alpha.jpg", "hi")
572
+ index.add("greek/Bilbo-Baggins.md", content)
573
+ index.commit("Add alpha.jpg")
574
+
575
+ @wiki.clear_cache
576
+ page = @wiki.page("Bilbo Baggins")
577
+ rendered = Gollum::Markup.new(page).render
578
+ assert_equal normal(output), normal(rendered)
579
+ end
580
+ end