module Roda::RodaPlugins::LinkTo

  1. lib/roda/plugins/link_to.rb

The link_to plugin adds the link_to instance method, which can be used for constructing HTML links (a tag with href attribute).

The simplest usage of link_to is passing the body and the location to link to as strings:

link_to("body", "/path")
# => "<a href=\"/path\">body</a>"

The link_to plugin depends on the path plugin, and allows you to pass symbols for named paths:

# Class level
path :foo, "/path/to/too"

# Instance level
link_to("body", :foo)
# => "<a href=\"/path/to/foo\">body</a>"

It also allows you to pass instances of classes that you have registered with the path plugin:

# Class level
A =
path A do

# Instance level
# => "<a href=\"/path/to/a/1\">body</a>"

To set additional HTML attributes on the a tag, you can pass them as an options hash:

link_to("body", "/path", foo: "bar")
# => "<a href=\"/path\" foo=\"bar\">body</a>"

If the body is nil, it will be set to the same as the path:

link_to(nil, "/path")
# => "<a href=\"/path\">/path</a>"

The plugin will automatically HTML escape the path and any HTML attribute values, using the h plugin:

link_to("body", "/path?a=1&b=2", foo: '"bar"')
# => "<a href=\"/path?a=1&amp;b=2\" foo=\"&quot;bar&quot;\">body</a>"


Public Class

  1. load_dependencies

Public Class methods

[show source]
   # File lib/roda/plugins/link_to.rb
50 def self.load_dependencies(app)
51   app.plugin :h
52   app.plugin :path
53 end