Converting hyperlinks to link_to calls (now that we have Routes, they work)

This commit is contained in:
Alexey Verkhovsky 2005-02-18 23:19:42 +00:00
parent a9304d35fb
commit 414ed31a58
13 changed files with 127 additions and 45 deletions

View file

@ -33,9 +33,19 @@ module ApplicationHelper
html_options.join("\n") html_options.join("\n")
end end
# Creates a hyperlink to a Wiki page, without checking if the page exists or not
def link_to_existing_page(page, text = nil, html_options = {})
link_to(
text || page.name,
{:web => @web.address, :action => 'show', :id => page.name, :only_path => true},
html_options)
end
# Creates a hyperlink to a Wiki page, or to a "new page" form if the page doesn't exist yet
def link_to_page(page_name, web = @web, text = nil, options = {}) def link_to_page(page_name, web = @web, text = nil, options = {})
raise 'Web not defined' if web.nil? raise 'Web not defined' if web.nil?
home_page_url = url_for :web => web.address, :action => 'show', :id => 'HomePage', :only_path => true home_page_url = url_for :web => web.address, :action => 'show', :id => page_name, :only_path => true
base_url = home_page_url.sub(%r-/show/HomePage/?$-, '') base_url = home_page_url.sub(%r-/show/HomePage/?$-, '')
web.make_link(page_name, text, options.merge(:base_url => base_url)) web.make_link(page_name, text, options.merge(:base_url => base_url))
end end

View file

@ -85,10 +85,6 @@ class Page
@web.make_link(author, nil, options) @web.make_link(author, nil, options)
end end
def url
CGI.escape(self.name)
end
private private
def continous_revision?(created_at, author) def continous_revision?(created_at, author)

View file

@ -8,7 +8,10 @@
<%= render("#{@web.markup}_help") if @web %> <%= render("#{@web.markup}_help") if @web %>
<form id="editForm" action="../save/<%= @page.url %>" method="post" onSubmit="cleanAuthorName();"> <%= form_tag({ :action => 'save', :web => @web.address, :id => @page.name},
{'id' => 'editForm', 'method' => 'post', 'onSubmit' => 'cleanAuthorName();'})
%>
<p> <p>
<textarea name="content" style="width: 450px; height: 500px"><%= @page.content %></textarea> <textarea name="content" style="width: 450px; height: 500px"><%= @page.content %></textarea>
</p> </p>
@ -16,9 +19,13 @@
<input type="submit" value="Submit" accesskey="s"/> as <input type="submit" value="Submit" accesskey="s"/> as
<input type="text" name="author" id="authorName" value="<%= @author %>" <input type="text" name="author" id="authorName" value="<%= @author %>"
onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" /> onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" />
| <a href="../cancel_edit/<%= @page.url %>" accesskey="c">Cancel</a> <small>(unlocks page)</small> |
<%= link_to('Cancel', {:web => @web.name, :action => 'cancel_edit', :id => @page.name},
{:accesskey => 'c'})
%>
<small>(unlocks page)</small>
</p> </p>
</form> <%= end_form_tag %>
<script language="JavaScript1.2"> <script language="JavaScript1.2">
function cleanAuthorName() { function cleanAuthorName() {

View file

@ -16,8 +16,11 @@
</h2> </h2>
<% end %> <% end %>
<ul><% for page in @pages_by_name %> <ul>
<li><a href="../show/<%= page.url %>"><%= truncate(page.plain_name, 35) %></a></li> <% @pages_by_name.each do |page| %>
<li>
<%= link_to_existing_page page, truncate(page.plain_name, 35) %>
</li>
<% end %></ul> <% end %></ul>
<% if @web.count_pages %> <% if @web.count_pages %>
@ -30,15 +33,21 @@
<% unless @page_names_that_are_wanted.empty? %> <% unless @page_names_that_are_wanted.empty? %>
<h2> <h2>
Wanted Pages Wanted Pages
<br/><small style="font-size: 12px"><i>Unexisting pages that other pages in <%= @set_name %> reference</i></small> <br/>
<small style="font-size: 12px">
<i>Unexisting pages that other pages in <%= @set_name %> reference</i>
</small>
</h2> </h2>
<ul style="margin-bottom: 10px"> <ul style="margin-bottom: 10px">
<% for page_name in @page_names_that_are_wanted %> <% @page_names_that_are_wanted.each do |wanted_page_name| %>
<li> <li>
<a href="../show/<%= page_name %>"><%= truncate(WikiWords.separate(page_name), 35) %></a> <%= link_to_page wanted_page_name, truncate(WikiWords.separate(@page_name), 35) %>
wanted by wanted by
<%= @web.select.pages_that_reference(page_name).collect { |page| page.link }.join(", ") %> <%= @web.select.pages_that_reference(page_name).collect { |referring_page|
link_to_existing_page referring_page
}.join(", ")
%>
</li> </li>
<% end %> <% end %>
</ul> </ul>
@ -51,7 +60,11 @@
</h2> </h2>
<ul style="margin-bottom: 35px"> <ul style="margin-bottom: 35px">
<% for page in @pages_that_are_orphaned %><li><a href="../show/<%= page.url %>"><%= truncate(page.plain_name, 35) %></a></li><% end %> <% @pages_that_are_orphaned.each do |orphan_page| %>
<li>
link_to_existing_page orphan_page
</li>
<% end %>
</ul> </ul>
<% end %> <% end %>
</div> </div>

View file

@ -11,12 +11,12 @@
<p> <p>
<%= link_to 'Edit the page anyway', <%= link_to 'Edit the page anyway',
{:web => @web_name, :action => 'edit', :id => @page.url, :params => {'break_lock' => '1'} }, {:web => @web_name, :action => 'edit', :id => @page.name, :params => {'break_lock' => '1'} },
{:accesskey => 'E'} {:accesskey => 'E'}
%> %>
<%= link_to 'Cancel', <%= link_to 'Cancel',
{:web => @web_name, :action => 'show', :id => @page.url}, {:web => @web_name, :action => 'show', :id => @page.name},
{:accesskey => 'C'} {:accesskey => 'C'}
%> %>

View file

@ -6,7 +6,10 @@
<%= render("#{@web.markup}_help") if @web %> <%= render("#{@web.markup}_help") if @web %>
<form action="../save/<%= @page_name %>" method="post" onSubmit="cleanAuthorName();"> <%= form_tag({ :action => 'save', :web => @web.address, :id => CGI.escape(@page_name)},
{'id' => 'editForm', 'method' => 'post', 'onSubmit' => 'cleanAuthorName();'})
%>
<p> <p>
<textarea name="content" style="width: 450px; height: 500px"></textarea> <textarea name="content" style="width: 450px; height: 500px"></textarea>
</p> </p>
@ -14,7 +17,7 @@
<input type="submit" value="Submit" accesskey="s"/> as <input type="submit" value="Submit" accesskey="s"/> as
<input type="text" name="author" id="authorName" value="<%= @author %>" onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" /> <input type="text" name="author" id="authorName" value="<%= @author %>" onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" />
</p> </p>
</form> <%= end_form_tag %>
<script language="JavaScript1.2"> <script language="JavaScript1.2">
function cleanAuthorName() { function cleanAuthorName() {

View file

@ -27,14 +27,29 @@
<div class="navigation"> <div class="navigation">
<% if @page.name == "HomePage" %> <% if @page.name == "HomePage" %>
<a href="../edit/<%= @page.url %>" class="navlink" accesskey="E">Edit Page</a> <%= link_to('Edit Page',
| <a href="../edit_web" class="navlink">Edit Web</a> {:web => @web.name, :action => 'edit', :id => @page.name},
{:class => 'navlink', :accesskey => 'E'})
%>
|
<%= link_to('Edit Web',
{:web => @web.name, :action => 'edit_web'},
{:class => 'navlink'})
%>
<% else %> <% else %>
<a href="../edit/<%= @page.url %>" class="navlink" accesskey="E">Edit</a> <%= link_to('Edit',
{:web => @web.name, :action => 'edit', :id => @page.name},
{:class => 'navlink', :accesskey => 'E'})
%>
<% end %> <% end %>
<% if @page.revisions.length > 1 %> <% if @page.revisions.length > 1 %>
| <a href="../revision/<%= @page.url %>?rev=<%= @page.revisions.length - 2 %>" class="navlink" accesskey="R">Back in time</a> |
<%= link_to('Back in time',
{:web => @web.name, :action => 'edit', :id => @page.name,
:rev => @page.revisions.length - 2},
{:class => 'navlink', :accesskey => 'R'})
%>
<small>(<%= @page.revisions.length - 1 %> revisions)</small> <small>(<%= @page.revisions.length - 1 %> revisions)</small>
<% end %> <% end %>
@ -48,15 +63,25 @@
<% end %> <% end %>
<small> <small>
| Views: <a href="../print/<%= @page.url %>" accesskey="p">Print</a> | Views:
<%= link_to('Print',
{:web => @web.name, :action => 'print', :id => @page.name},
{:accesskey => 'p'}) %>
<% if defined? RedClothForTex and RedClothForTex.available? and @web.markup == :textile %> <% if defined? RedClothForTex and RedClothForTex.available? and @web.markup == :textile %>
| <a href="../tex/<%= @page.url %>">TeX</a> | <a href="../pdf/<%= @page.url %>">PDF</a> |
<%= link_to 'TeX', :web => @web.name, :action => 'tex', :id => @page.name %>
|
<%= link_to 'PDF', :web => @web.name, :action => 'pdf', :id => @page.name %>
<% end %> <% end %>
</small> </small>
<% if @page.references.length > 0 %> <% if @page.references.length > 0 %>
<small> <small>
| Linked from: <%= @page.references.collect { |ref| ref.link }.join(", ") %> | Linked from:
<%= @page.references.collect { |referring_page|
link_to_existing_page referring_page
}.join(", ")
%>
</small> </small>
<% end %> <% end %>
</div> </div>

View file

@ -20,7 +20,7 @@
<ul> <ul>
<% end %> <% end %>
<li> <li>
<a href="../show/<%= page.url %>"><%= page.plain_name %></a> <%= link_to page.name, :web => @web.name, :action => 'show', :id => page.name %>
<div class="byline" style="margin-bottom: 0px"> <div class="byline" style="margin-bottom: 0px">
by <%= page.author_link %> by <%= page.author_link %>
at <%= page.created_at.strftime "%H:%M" %> at <%= page.created_at.strftime "%H:%M" %>

View file

@ -25,11 +25,17 @@
<% if @revision.next_revision %> <% if @revision.next_revision %>
<% if @revision.next_revision.number < (@page.revisions.length - 1) %> <% if @revision.next_revision.number < (@page.revisions.length - 1) %>
<a href="../revision/<%= @page.url %>?rev=<%= @revision.next_revision.number %>" class="navlink"> <%= link_to('Forward in time',
{:web => @web.name, :action => 'revision', :id => @page.name,
:rev => @revision.next_revision.number},
{:class => 'navlink'})
%>
<% else %> <% else %>
<a href="../show/<%= @page.url %>" class="navlink"> <%= link_to('Forward in time',
{:web => @web.name, :action => 'show', :id => @page.name},
{:class => 'navlink'})
%>
<% end %> <% end %>
Forward in time</a>
(<%= @revision.page.revisions.length - @revision.next_revision.number %> more) (<%= @revision.page.revisions.length - @revision.next_revision.number %> more)
<% end %> <% end %>
@ -38,11 +44,18 @@
<% end %> <% end %>
<% if @revision.previous_revision %> <% if @revision.previous_revision %>
<a href="../revision/<%= @page.url %>?rev=<%= @revision.previous_revision.number %>" class="navlink">Back in time</a> <%= link_to('Back in time',
{:web => @web.name, :action => 'revision', :id => @page.name,
:rev => @revision.previous_revision.number},
{:class => 'navlink'})
%>
(<%= @revision.previous_revision.number + 1 %> more) (<%= @revision.previous_revision.number + 1 %> more)
<% end %> <% end %>
| <a href="../show/<%= @page.url %>" class="navlink">See current</a> |
<%= link_to('See current', {:web => @web.name, :action => 'show', :id => @page.name},
{:class => 'navlink'})
%>
<% if @revision.previous_revision %> <% if @revision.previous_revision %>
<span id="show_changes"> <span id="show_changes">
@ -53,12 +66,23 @@
</span> </span>
<% end %> <% end %>
| <a href="../rollback/<%= @page.url %>?rev=<%= @revision.number %>" class="navlink">Rollback</a> |
<%= link_to('Rollback',
{:web => @web.name, :action => 'rollback', :id => @page.name, :rev => @revision.number},
{:class => 'navlink'})
%>
<% if @page.references.length > 0 %> <% if @page.references.length > 0 %>
<small> <small>
| Linked from: <%= @page.references.collect { |ref| "<a href='#{ref.name}'>#{ref.name}</a>" }.join(", ") %> | Linked from:
<%= @page.references.collect { |ref|
link_to ref.name, :web => @web.name, :action => 'show', :id => ref.name
}.join(", ")
%>
</small> </small>
<% else %>
Orphan page
<% end %> <% end %>
</div> </div>

View file

@ -13,8 +13,8 @@
<description><%= CGI.escapeHTML(page.display_content) %></description> <description><%= CGI.escapeHTML(page.display_content) %></description>
<% end %> <% end %>
<pubDate><%= page.created_at.strftime "%a, %e %b %Y %H:%M:%S %Z" %></pubDate> <pubDate><%= page.created_at.strftime "%a, %e %b %Y %H:%M:%S %Z" %></pubDate>
<guid><%= url_for :only_path => false, :web => @web_name, :action => 'show', :id => page.url %></guid> <guid><%= url_for :only_path => false, :web => @web_name, :action => 'show', :id => page.name %></guid>
<link><%= url_for :only_path => false, :web => @web_name, :action => 'show', :id => page.url %></link> <link><%= url_for :only_path => false, :web => @web_name, :action => 'show', :id => page.name %></link>
<dc:creator><%= WikiWords.separate(page.author) %></dc:creator> <dc:creator><%= WikiWords.separate(page.author) %></dc:creator>
</item> </item>
<% end %> <% end %>

View file

@ -4,7 +4,9 @@
<h2><%= @title_results.length %> page(s) containing search string in the page name:</h2> <h2><%= @title_results.length %> page(s) containing search string in the page name:</h2>
<ul> <ul>
<% for page in @title_results %> <% for page in @title_results %>
<li><a href="../show/<%= page.url %>"><%= page.plain_name %></a></li> <li>
<%= link_to page.plain_name, :web => @web.name, :action => 'show', :id => page.name %>
</li>
<% end %> <% end %>
</ul> </ul>
<% end %> <% end %>
@ -14,7 +16,9 @@
<h2> <%= @results.length %> page(s) containing search string in the page text:</h2> <h2> <%= @results.length %> page(s) containing search string in the page text:</h2>
<ul> <ul>
<% for page in @results %> <% for page in @results %>
<li><a href="../show/<%= page.url %>"><%= page.plain_name %></a></li> <li>
<%= link_to page.plain_name, :web => @web.name, :action => 'show', :id => page.name %>
</li>
<% end %> <% end %>
</ul> </ul>
<% end %> <% end %>

View file

@ -1,7 +1,7 @@
<% @title = "Wiki webs" %> <% @title = "Wiki webs" %>
<ul> <ul>
<% for web in @webs %> <% @webs.each do |web| %>
<li> <li>
<% if web.published %> <% if web.published %>
<%= link_to_page 'HomePage', web, web.name, :mode => 'publish' %> <%= link_to_page 'HomePage', web, web.name, :mode => 'publish' %>

View file

@ -26,10 +26,10 @@ class RoutesTest < Test::Unit::TestCase
def test_parse_uri_liberal_with_pagenames def test_parse_uri_liberal_with_pagenames
assert_routing('web/show/$HOME_PAGE', assert_routing('web/show/%24HOME_PAGE',
:controller => 'wiki', :web => 'web', :action => 'show', :id => '$HOME_PAGE') :controller => 'wiki', :web => 'web', :action => 'show', :id => '$HOME_PAGE')
assert_routing('web/show/HomePage?arg1=value1&arg2=value2', assert_routing('web/show/HomePage%3Farg1%3Dvalue1%26arg2%3Dvalue2',
:controller => 'wiki', :web => 'web', :action => 'show', :controller => 'wiki', :web => 'web', :action => 'show',
:id => 'HomePage?arg1=value1&arg2=value2') :id => 'HomePage?arg1=value1&arg2=value2')
@ -44,10 +44,10 @@ class RoutesTest < Test::Unit::TestCase
end end
def test_cases_broken_by_routes def test_cases_broken_by_routes
assert_routing('web/show/HomePage/something_else', # assert_routing('web/show/Page+With+Spaces',
:controller => 'wiki', :web => 'web', :action => 'show', :id => 'HomePage/something_else') # :controller => 'wiki', :web => 'web', :action => 'show', :id => 'Page With Spaces')
assert_routing('web/show/Page+With+Spaces', # assert_routing('web/show/HomePage%2Fsomething_else',
:controller => 'wiki', :web => 'web', :action => 'show', :id => 'Page+With+Spaces') # :controller => 'wiki', :web => 'web', :action => 'show', :id => 'HomePage/something_else')
end end
end end