Links From Published Webs
Damn, but it's hard to get this right. I think I've finally done it, though. We'll see ...
This commit is contained in:
parent
97a35e280b
commit
761f8bbb51
|
@ -98,19 +98,13 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
end
|
end
|
||||||
when :publish
|
when :publish
|
||||||
if known_page
|
if known_page
|
||||||
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'published',
|
wikilink_for(mode, name, text, web_address)
|
||||||
:id => name, :only_path => true
|
|
||||||
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
|
|
||||||
else
|
else
|
||||||
%{<span class="newWikiWord">#{text}</span>}
|
%{<span class="newWikiWord">#{text}</span>}
|
||||||
end
|
end
|
||||||
when :show
|
when :show
|
||||||
if known_page
|
if known_page
|
||||||
web = Web.find_by_address(web_address)
|
wikilink_for(mode, name, text, web_address)
|
||||||
action = web.published? && web != @web ? 'published' : 'show'
|
|
||||||
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action,
|
|
||||||
:id => name, :only_path => true
|
|
||||||
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
|
|
||||||
else
|
else
|
||||||
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'new',
|
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'new',
|
||||||
:id => name, :only_path => true
|
:id => name, :only_path => true
|
||||||
|
@ -118,11 +112,7 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if known_page
|
if known_page
|
||||||
web = Web.find_by_address(web_address)
|
wikilink_for(mode, name, text, web_address)
|
||||||
action = web.published? ? 'published' : 'show'
|
|
||||||
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action,
|
|
||||||
:id => name, :only_path => true
|
|
||||||
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
|
|
||||||
else
|
else
|
||||||
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'new',
|
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'new',
|
||||||
:id => name, :only_path => true
|
:id => name, :only_path => true
|
||||||
|
@ -190,5 +180,14 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
%{<span class="deleteWikiWord">[[#{name}:delete]]</span>}
|
%{<span class="deleteWikiWord">[[#{name}:delete]]</span>}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def wikilink_for(mode, name, text, web_address)
|
||||||
|
web = Web.find_by_address(web_address)
|
||||||
|
action = web.published? && !(web == @web && mode != :publish) ? 'published' : 'show'
|
||||||
|
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action,
|
||||||
|
:id => name, :only_path => true
|
||||||
|
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
4
test/fixtures/revisions.yml
vendored
4
test/fixtures/revisions.yml
vendored
|
@ -88,6 +88,6 @@ liquor_first_revision:
|
||||||
updated_at: <%= 40.minutes.ago.to_formatted_s(:db) %>
|
updated_at: <%= 40.minutes.ago.to_formatted_s(:db) %>
|
||||||
revised_at: <%= 40.minutes.ago.to_formatted_s(:db) %>
|
revised_at: <%= 40.minutes.ago.to_formatted_s(:db) %>
|
||||||
page_id: 9
|
page_id: 9
|
||||||
content: "[[!redirects booze]]\n Drinky-poo."
|
content: "[[!redirects booze]]\n Drinky-poo. [[Instiki:HomePage|go there]]"
|
||||||
author: Guest
|
author: Guest
|
||||||
ip: 127.0.0.2
|
ip: 127.0.0.2
|
|
@ -329,6 +329,52 @@ class WikiControllerTest < ActionController::TestCase
|
||||||
assert_response(:success)
|
assert_response(:success)
|
||||||
assert_equal @home, r.template_objects['page']
|
assert_equal @home, r.template_objects['page']
|
||||||
assert_match /<a class='existingWikiWord' href='\/wiki1\/show\/ThatWay'>That Way<\/a>/, r.body
|
assert_match /<a class='existingWikiWord' href='\/wiki1\/show\/ThatWay'>That Way<\/a>/, r.body
|
||||||
|
|
||||||
|
r = process 'save', 'web' => 'instiki', 'id' => 'HomePage', 'content' => 'Contents of a new page',
|
||||||
|
'author' => 'AuthorOfNewPage'
|
||||||
|
assert_equal Web.find_by_address('instiki').has_page?('HomePage'), true
|
||||||
|
|
||||||
|
r = process('published', 'web' => 'wiki1', 'id' => 'liquor')
|
||||||
|
|
||||||
|
assert_response(:success)
|
||||||
|
assert_equal @liquor, r.template_objects['page']
|
||||||
|
assert_match /<a class='existingWikiWord' href='\/instiki\/show\/HomePage'>go there<\/a>/, r.body
|
||||||
|
|
||||||
|
r = process('show', 'web' => 'wiki1', 'id' => 'liquor')
|
||||||
|
|
||||||
|
assert_response(:success)
|
||||||
|
assert_equal @liquor, r.template_objects['page']
|
||||||
|
assert_match /<a class='existingWikiWord' href='\/instiki\/show\/HomePage'>go there<\/a>/, r.body
|
||||||
|
|
||||||
|
Web.find_by_address('instiki').update_attribute(:published, true)
|
||||||
|
|
||||||
|
r = process('published', 'web' => 'wiki1', 'id' => 'liquor')
|
||||||
|
|
||||||
|
assert_response(:success)
|
||||||
|
assert_equal @liquor, r.template_objects['page']
|
||||||
|
assert_match /<a class='existingWikiWord' href='\/instiki\/published\/HomePage'>go there<\/a>/, r.body
|
||||||
|
|
||||||
|
r = process('show', 'web' => 'wiki1', 'id' => 'liquor')
|
||||||
|
|
||||||
|
assert_response(:success)
|
||||||
|
assert_equal @liquor, r.template_objects['page']
|
||||||
|
assert_match /<a class='existingWikiWord' href='\/instiki\/published\/HomePage'>go there<\/a>/, r.body
|
||||||
|
|
||||||
|
set_web_property :published, false
|
||||||
|
|
||||||
|
r = process('show', 'web' => 'wiki1', 'id' => 'liquor')
|
||||||
|
|
||||||
|
assert_response(:success)
|
||||||
|
assert_equal @liquor, r.template_objects['page']
|
||||||
|
assert_match /<a class='existingWikiWord' href='\/instiki\/published\/HomePage'>go there<\/a>/, r.body
|
||||||
|
|
||||||
|
Web.find_by_address('instiki').update_attribute(:published, false)
|
||||||
|
|
||||||
|
r = process('show', 'web' => 'wiki1', 'id' => 'liquor')
|
||||||
|
|
||||||
|
assert_response(:success)
|
||||||
|
assert_equal @liquor, r.template_objects['page']
|
||||||
|
assert_match /<a class='existingWikiWord' href='\/instiki\/show\/HomePage'>go there<\/a>/, r.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue