Module: Innate::Helper::Link

### Home Classes Methods

### In Files

- lib/innate/helper/link.rb

### Methods

- ::included
- #a
- #anchor
- #r
- #route
- #route_location
- #route_self
- #rs

### Class/Module Index

Quicksearch

- Innate
- Innate::Action
- Innate::Adapter
- Innate::Cache
- Innate::Cache::API
- Innate::Cache::DRb
- Innate::Cache::FileBased
- Innate::Cache::Marshal
- Innate::Cache::Memory
- Innate::Cache::YAML
- Innate::Current
- Innate::Etanni
- Innate::Helper
- Innate::Helper::Aspect
- Innate::Helper::Aspect::SingletonMethods
- Innate::Helper::CGI
- Innate::Helper::Flash
- Innate::Helper::Link
- Innate::Helper::Redirect
- Innate::Helper::Render
- Innate::HelperAccess
- Innate::HelpersHelper
- Innate::LRUHash
- Innate::LogHub
- Innate::Mock
- Innate::Mock::Session
- Innate::Node
- Innate::Optioned
- Innate::Optioned::SingletonMethods
- Innate::Options
- Innate::Request
- Innate::Response
- Innate::Rewrite
- Innate::Route
- Innate::Session
- Innate::Session::Flash
- Innate::SingletonMethods
- Innate::StateAccessor
- Innate::Traited
- Innate::Trinity
- Innate::URLMap
- Innate::View
- Innate::View::ERB
- Innate::View::Etanni
- Innate::View::None
- Logger
- Logger::ColorFormatter
- Object

No matching classes.

# Innate::Helper::Link

### Public Class Methods

included(into) click to toggle source

    # File lib/innate/helper/link.rb, line 4
    def self.included(into)
      into.extend(self)
    end

### Public Instance Methods

a(text, *args) click to toggle source
Alias for: anchor
anchor(text, *args) click to toggle source

Create a link tag

Usage, given Wiki is mapped to `/wiki`:

    Wiki.a(:home)                   # => '<a href="/wiki/home">home</a>'
    Wiki.a('home', :home)           # => '<a href="/wiki/home">home</a>'
    Wiki.a('home', :/)              # => '<a href="/wiki/">home</a>'
    Wiki.a('foo', :/, :foo => :bar) # => '<a href="/wiki/?foo=bar">foo</a>'
    Wiki.a('example', 'http://example.com')
    # => '<a href="http://example.com">example</a>'

@return [String]

    # File lib/innate/helper/link.rb, line 78
    def anchor(text, *args)
      case first = (args.first || text)
      when URI
        href = first.to_s
      when /^\w+:\/\//
        uri       = URI(first)
        uri.query = Rack::Utils.escape_html(uri.query) if uri.query
        href      = uri.to_s
      else
        href = args.empty? ? r(text) : r(*args)
      end

      text = Rack::Utils.escape_html(text)
      %(<a href="#{href}">#{text}</a>)
    end

Also aliased as: a
r(name = '/', *args) click to toggle source
Alias for: route
route(name = '/', *args) click to toggle source

Provide the path to given Node and actions. Escapes GET parameters.

Usage, mapping is Pages => '/', Users => '/users':

    Pages.r                       # => URI('/')
    Pages.r(:foo)                 # => URI('/foo')
    Pages.r(:foo, :bar)           # => URI('/foo/bar')
    Pages.r(:foo, :a => :b)       # => URI('/foo?a=b')
    Pages.r(:foo, :bar, :a => :b) # => URI('/foo/bar?a=b')

    Users.r                       # => URI('/users/')
    Users.r(:foo)                 # => URI('/users/foo')
    Users.r(:foo, :bar)           # => URI('/users/foo/bar')
    Users.r(:foo, :a => :b)       # => URI('/users/foo?a=b')
    Users.r(:foo, :bar, :a => :b) # => URI('/users/foo/bar?a=b')

@return [URI] to the location

    # File lib/innate/helper/link.rb, line 26
    def route(name = '/', *args)
      hash = {}
      hashes, names = args.partition{|arg| arg.respond_to?(:merge!) }
      hashes.each{|to_merge| hash.merge!(to_merge) }

      name = name.to_s.gsub(/__/, '/')

      location = route_location(self)
      front = Array[location, name, *names.map{|element|
        Rack::Utils.escape(element) }].join('/').squeeze('/')

      return URI(front) if hash.empty?

      query = Rack::Utils.build_query(hash)
      URI("#{front}?#{query}")
    end

Also aliased as: r
route_location(klass) click to toggle source

    # File lib/innate/helper/link.rb, line 44
    def route_location(klass)
      prefix = Innate.options.prefix
      location = Innate.to(klass) || Innate.to(klass.class)
      [prefix, location].join('/')
    end

route_self(name = '/', *args) click to toggle source

Create a route to the currently active Node.

This method is mostly here in case you include this helper elsewhere and don't want (or can't) type SomeNode.r all the time.

The usage is identical with {Innate::Helper::Link#route}.

@param [to_s] name @return [URI] to the location @see Ramaze::Helper::Link#route @author manveru

    # File lib/innate/helper/link.rb, line 61
    def route_self(name = '/', *args)
      Current.action.node.route(name, *args)
    end

Also aliased as: rs
rs(name = '/', *args) click to toggle source
Alias for: route_self

[Validate]

Generated with the Darkfish Rdoc Generator 2.