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 78: def anchor(text, *args) 79: case first = (args.first || text) 80: when URI 81: href = first.to_s 82: when /^\w+:\/\// 83: uri = URI(first) 84: uri.query = Rack::Utils.escape_html(uri.query) 85: href = uri.to_s 86: else 87: href = args.empty? ? r(text) : r(*args) 88: end 89: 90: text = Rack::Utils.escape_html(text) 91: %(<a href="#{href}">#{text}</a>) 92: end
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 26: def route(name = '/', *args) 27: hash = {} 28: hashes, names = args.partition{|arg| arg.respond_to?(:merge!) } 29: hashes.each{|to_merge| hash.merge!(to_merge) } 30: 31: name = name.to_s.gsub(/__/, '/') 32: 33: location = route_location(self) 34: front = Array[location, name, *names.map{|element| 35: Rack::Utils.escape(element) }].join('/').squeeze('/') 36: 37: return URI(front) if hash.empty? 38: 39: query = Rack::Utils.build_query(hash) 40: URI("#{front}?#{query}") 41: end
# File lib/innate/helper/link.rb, line 44 44: def route_location(klass) 45: prefix = Innate.options.prefix 46: location = Innate.to(klass) || Innate.to(klass.class) 47: [prefix, location].join('/') 48: end
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 [#] name @return [URI] to the location @see Ramaze::Helper::Link#route @author manveru
# File lib/innate/helper/link.rb, line 61 61: def route_self(name = '/', *args) 62: Current.action.node.route(name, *args) 63: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.