Module Webby::Helpers::UrlHelper
In: lib/webby/helpers/url_helper.rb

Methods

Public Instance methods

Create an HTTP anchor tag with

url can be a url string, a page, :back, or nothing

:attrs are used to generate HTML anchor tag attributes

Examples

   <%= link_to('Google', 'http://www.google.com/', :attrs => {:name => 'google'}) %>
   # => <a href="http://www.google.com/" name="google">Google</a>

   <%= link_to('A Page', @page, :anchor => 'blah') %>
   # => <a href="/a/page.html#blah">A Page</a>

Creates a link tag of the given name using a URL created by finding the associated page from the key/value pairs. If the key/value pairs are omitted, the name is used in conjunction with the default site find_by attribute. Unless changed by the user, the default find_by attribute is the page title.

Pages are found using key/value pairs. The key is any of the page attributes, and the value is what that attribute should be. Any number of key/value pairs can be included, but all values must equal the corresponding page attributes for a match to be found — i.e. the comparisons are joined by AND operations to determine a match.

In the absence of any key/value pairs — just a name was given — then the default site find_by attribute is used, and the name is compared against this attribute from the page. The default find_by attribue is set in the Rakefile or in the Webby.site.find_by parameter.

Several options can be passed to the method to determin how URLs are created and to specify any HTML attributes on the returned link tag. The URL options are given as a hash to the :url key. The HTML attributes are given as a hash to the :attrs key.

See the url_for method for a desciption of the :url options. See the link_to method for a description of the :attrs options.

Examples

   <%= link_to_page('Funny Story', :url => {:anchor => 'punchline'}) %>
   # => <a href="/humor/funny_story.html#punchline">Funny Story</a>

   <%= link_to_page('Hilarious', :title => 'Funny Story') %>
   # => <a href="/humor/funn_story.html">Hilarious</a>

This function operates in the same fashion as the link_to_page fuction with the exception that if the page to be linked to is the current page, then only the name is rendered without an HTML anchor tag.

Examples

   <%= link_to_page_unless_current('Funny Story') %>
   # => <a href="/humor/funny_story.html">Funny Story</a>

   <%= link_to_page_unless_current(@page) %>
   # => This Page

Creates a URL for the given name and opts. If name is a string then it is used as the URL base. If name is a Resource then it is converted to a URL by calling its url method.

Options

  • :escape — determines whether the returned URL will be HTML escaped or not (true by default)
  • :anchor — specifies the anchor name to be appended to the path

Examples

   <%= url_for('/some/page.html') %>
   # => /some/page

   <%= url_for('/some/page.html', :anchor => 'tidbit') %>
   # => /some/page#tidbit

   <%= url_for(@page) %>
   # => /current/page.html

   <%= url_for(@page, :anchor => 'this&that') %>
   # => /current/page.html#this&amp;that

Creates a URL for the page identified by the set of :key / value pairs. The :url options are passed to the url_for method for final URL creation; see the url_for method for documentation on those options.

The Resources::DB#find method is used to locate the page; see the find method for the available options.

Examples

   <%= url_for_page(:title => 'Funny Story', :anchor => 'punchline') %>
   # => /humor/funny_story.html#punchline

[Validate]