Use new view helper method in /pages. Add /deleteFile route to helpers. Fix bug in breadcrumb of /Home.

This commit is contained in:
Bart Kamphorst
2018-10-17 14:47:35 +02:00
parent a6167d88cd
commit 6475394133
3 changed files with 5 additions and 4 deletions
+1
View File
@@ -10,6 +10,7 @@ module Precious
upload_file: 'uploadFile', upload_file: 'uploadFile',
create: 'create', create: 'create',
delete: 'delete', delete: 'delete',
delete_file: 'deleteFile',
edit: 'edit', edit: 'edit',
pages: 'pages', pages: 'pages',
history: 'history', history: 'history',
+3 -3
View File
@@ -12,14 +12,14 @@ module Precious
def breadcrumb def breadcrumb
if @path if @path
path = Pathname.new(@path) path = Pathname.new(@path)
breadcrumb = [%{<a href="#{@base_url}/pages/">Home</a>}] breadcrumb = [%{<a href="#{pages_path}">Home</a>}]
path.descend do |crumb| path.descend do |crumb|
title = crumb.basename title = crumb.basename
if title == path.basename if title == path.basename
breadcrumb << title breadcrumb << title
else else
breadcrumb << %{<a href="#{@base_url}/pages/#{crumb}/">#{title}</a>} breadcrumb << %{<a href="#{pages_path}/#{crumb}/">#{title}</a>}
end end
end end
@@ -31,7 +31,7 @@ module Precious
def delete_file(url) def delete_file(url)
%Q(<form method="POST" action="/deleteFile/#{url}" onsubmit="return confirm('Do you really want to delete the file #{URI.decode(url)}?');"><button type="submit" name="delete" value="true">Delete</button></form>) %Q(<form method="POST" action="#{delete_file_path}#{url}" onsubmit="return confirm('Do you really want to delete the file #{URI.decode(url)}?');"><button type="submit" name="delete" value="true">Delete</button></form>)
end end
def files_folders def files_folders
+1 -1
View File
@@ -35,7 +35,7 @@ context "Precious::Views::Pages" do
test "breadcrumb" do test "breadcrumb" do
@page.instance_variable_set("@path", "Mordor/Eye-Of-Sauron/Saruman") @page.instance_variable_set("@path", "Mordor/Eye-Of-Sauron/Saruman")
@page.instance_variable_set("@base_url", "") @page.instance_variable_set("@base_url", "")
assert_equal '<a href="/pages/">Home</a> / <a href="/pages/Mordor/">Mordor</a> / <a href="/pages/Mordor/Eye-Of-Sauron/">Eye-Of-Sauron</a> / Saruman', @page.breadcrumb assert_equal '<a href="/gollum/pages">Home</a> / <a href="/gollum/pages/Mordor/">Mordor</a> / <a href="/gollum/pages/Mordor/Eye-Of-Sauron/">Eye-Of-Sauron</a> / Saruman', @page.breadcrumb
end end
test "breadcrumb with no path" do test "breadcrumb with no path" do