Route /filename/[commit-sha] will display specific revision of a file. Resolves #892.
This commit is contained in:
+11
-4
@@ -402,6 +402,8 @@ module Precious
|
|||||||
@content = page.formatted_data
|
@content = page.formatted_data
|
||||||
@version = version
|
@version = version
|
||||||
mustache :page
|
mustache :page
|
||||||
|
elsif file = wikip.wiki.file("#{file_path}", version, true)
|
||||||
|
show_file(file)
|
||||||
else
|
else
|
||||||
halt 404
|
halt 404
|
||||||
end
|
end
|
||||||
@@ -472,16 +474,21 @@ module Precious
|
|||||||
|
|
||||||
mustache :page
|
mustache :page
|
||||||
elsif file = wiki.file(fullpath, wiki.ref, true)
|
elsif file = wiki.file(fullpath, wiki.ref, true)
|
||||||
|
show_file(file)
|
||||||
|
else
|
||||||
|
page_path = [path, name].compact.join('/')
|
||||||
|
redirect to("/create/#{clean_url(encodeURIComponent(page_path))}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_file(file)
|
||||||
|
return unless file
|
||||||
if file.on_disk?
|
if file.on_disk?
|
||||||
send_file file.on_disk_path, :disposition => 'inline'
|
send_file file.on_disk_path, :disposition => 'inline'
|
||||||
else
|
else
|
||||||
content_type file.mime_type
|
content_type file.mime_type
|
||||||
file.raw_data
|
file.raw_data
|
||||||
end
|
end
|
||||||
else
|
|
||||||
page_path = [path, name].compact.join('/')
|
|
||||||
redirect to("/create/#{clean_url(encodeURIComponent(page_path))}")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
|
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
|
||||||
|
|||||||
@@ -87,3 +87,14 @@ def context(*args, &block)
|
|||||||
end
|
end
|
||||||
|
|
||||||
$contexts = []
|
$contexts = []
|
||||||
|
|
||||||
|
# Commit file to wiki, overwriting previous versions of that file
|
||||||
|
def commit_test_file(wiki, dir, filename, ext, content)
|
||||||
|
committer = Gollum::Committer.new(wiki, :message => "Added testfile", :parent => wiki.repo.head.commit)
|
||||||
|
committer.add_to_index(dir, filename, ext, content, true)
|
||||||
|
committer.after_commit do |committer, sha|
|
||||||
|
wiki.clear_cache
|
||||||
|
committer.update_working_dir(dir, filename, ext)
|
||||||
|
end
|
||||||
|
committer.commit
|
||||||
|
end
|
||||||
|
|||||||
@@ -542,6 +542,19 @@ context "Frontend" do
|
|||||||
assert_match /meta name="robots" content="noindex, nofollow"/, last_response.body
|
assert_match /meta name="robots" content="noindex, nofollow"/, last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "show revision of specific file" do
|
||||||
|
shas = {}
|
||||||
|
["First revision of testfile", "Second revision of testfile"].each do |content|
|
||||||
|
new_commit = commit_test_file(@wiki, "revisions", "testfile", "log", content)
|
||||||
|
shas[new_commit] = content
|
||||||
|
end
|
||||||
|
shas.each do |sha, content|
|
||||||
|
get "revisions/testfile.log/#{sha}"
|
||||||
|
assert last_response.ok?
|
||||||
|
assert_match /#{content}/, last_response.body
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def app
|
def app
|
||||||
Precious::App
|
Precious::App
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user