Webby::Helpers::UrlHelper

Public Instance Methods

url_for( name, opts = {} ) click to toggle source

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
# File lib/webby/helpers/url_helper.rb, line 33
def url_for( *args )
  opts = Hash === args.last ? args.pop : {}
  obj = args.first

  anchor = opts.delete(:anchor)
  escape = opts.has_key?(:escape) ? opts.delete(:escape) : true

  url = Webby::Resources::Resource === obj ? obj.url : obj.to_s
  url = escape_once(url) if escape
  url << "#" << anchor if anchor

  return url
end
url_for_page( :key => value, :url => {} ) click to toggle source

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
# File lib/webby/helpers/url_helper.rb, line 63
def url_for_page( opts = {} )
  opts = opts.symbolize_keys
  url_opts = opts.delete(:url)

  p = @pages.find(opts)
  raise ::Webby::Error,
        "could not find requested page: #{opts.inspect}" if p.nil?

  self.url_for(p, url_opts)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.