Wiki#update_page takes a name parameter for renames
This commit is contained in:
@@ -406,7 +406,7 @@ Update an existing page. If the format is different than the page's current
|
||||
format, the file name will be changed to reflect the new format.
|
||||
|
||||
page = wiki.page('Page Name')
|
||||
wiki.update_page(page, page.format, 'Page contents', commit)
|
||||
wiki.update_page(page, page.name, page.format, 'Page contents', commit)
|
||||
|
||||
To delete a page and commit the change:
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ module Precious
|
||||
page = wiki.page(name)
|
||||
format = params[:format].intern
|
||||
|
||||
wiki.update_page(page, format, params[:content], commit_message)
|
||||
wiki.update_page(page, page.name, format, params[:content], commit_message)
|
||||
|
||||
redirect "/#{name}"
|
||||
end
|
||||
|
||||
+9
-8
@@ -95,7 +95,7 @@ module Gollum
|
||||
# Returns the in-memory Gollum::Page.
|
||||
def preview_page(name, data, format)
|
||||
page = @page_class.new(self)
|
||||
ext = @page_class.format_to_ext(format.to_sym)
|
||||
ext = @page_class.format_to_ext(format.to_sym)
|
||||
path = @page_class.cname(name) + '.' + ext
|
||||
blob = OpenStruct.new(:name => path, :data => data)
|
||||
page.populate(blob, path)
|
||||
@@ -134,6 +134,7 @@ module Gollum
|
||||
# changed to reflect the new format.
|
||||
#
|
||||
# page - The Gollum::Page to update.
|
||||
# name - The String extension-less name of the page.
|
||||
# format - The Symbol format of the page.
|
||||
# data - The new String contents of the page.
|
||||
# commit - The commit Hash details:
|
||||
@@ -142,19 +143,19 @@ module Gollum
|
||||
# :email - The String email address.
|
||||
#
|
||||
# Returns the String SHA1 of the newly written version.
|
||||
def update_page(page, format, data, commit = {})
|
||||
pcommit = @repo.commit('master')
|
||||
map = tree_map(pcommit.tree)
|
||||
def update_page(page, name, format, data, commit = {})
|
||||
pcommit = @repo.commit('master')
|
||||
map = tree_map(pcommit.tree)
|
||||
name ||= page.name
|
||||
format ||= page.format
|
||||
index = nil
|
||||
|
||||
index = nil
|
||||
|
||||
if page.format == format
|
||||
if page.name == name && page.format == format
|
||||
index = tree_map_to_index(map)
|
||||
index.add(page.path, normalize(data))
|
||||
else
|
||||
map = delete_from_tree_map(map, page.path)
|
||||
dir = ::File.dirname(page.path)
|
||||
name = page.name
|
||||
map = add_to_tree_map(map, dir, name, format, data)
|
||||
index = tree_map_to_index(map)
|
||||
end
|
||||
|
||||
+34
-3
@@ -87,7 +87,7 @@ context "Wiki page writing" do
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", commit)
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
@wiki.update_page(page, :markdown, "# Gollum2", commit)
|
||||
@wiki.update_page(page, page.name, :markdown, "# Gollum2", commit)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_equal "# Gollum2", @wiki.page("Gollum").raw_data
|
||||
@@ -105,13 +105,44 @@ context "Wiki page writing" do
|
||||
assert_equal :markdown, @wiki.page("Gollum").format
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
@wiki.update_page(page, :textile, "h1. Gollum", commit)
|
||||
@wiki.update_page(page, page.name, :textile, "h1. Gollum", commit)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_equal :textile, @wiki.page("Gollum").format
|
||||
assert_equal "h1. Gollum", @wiki.page("Gollum").raw_data
|
||||
end
|
||||
|
||||
test "update page with name change" do
|
||||
commit = { :message => "Gollum page",
|
||||
:name => "Tom Preston-Werner",
|
||||
:email => "tom@github.com" }
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", commit)
|
||||
|
||||
assert_equal :markdown, @wiki.page("Gollum").format
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
@wiki.update_page(page, 'Smeagol', :markdown, "h1. Gollum", commit)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
|
||||
end
|
||||
|
||||
test "update page with name and format change" do
|
||||
commit = { :message => "Gollum page",
|
||||
:name => "Tom Preston-Werner",
|
||||
:email => "tom@github.com" }
|
||||
@wiki.write_page("Gollum", :markdown, "# Gollum", commit)
|
||||
|
||||
assert_equal :markdown, @wiki.page("Gollum").format
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
@wiki.update_page(page, 'Smeagol', :textile, "h1. Gollum", commit)
|
||||
|
||||
assert_equal 2, @wiki.repo.commits.size
|
||||
assert_equal :textile, @wiki.page("Smeagol").format
|
||||
assert_equal "h1. Gollum", @wiki.page("Smeagol").raw_data
|
||||
end
|
||||
|
||||
test "update nested page with format change" do
|
||||
commit = { :message => "Gollum page",
|
||||
:name => "Tom Preston-Werner",
|
||||
@@ -123,7 +154,7 @@ context "Wiki page writing" do
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
assert_equal :markdown, @wiki.page("Gollum").format
|
||||
@wiki.update_page(page, :textile, "h1. Gollum", commit)
|
||||
@wiki.update_page(page, page.name, :textile, "h1. Gollum", commit)
|
||||
|
||||
page = @wiki.page("Gollum")
|
||||
assert_equal "lotr/Gollum.textile", page.path
|
||||
|
||||
Reference in New Issue
Block a user