Module: Roda::RodaPlugins::LinkTo::InstanceMethods

Defined in:
lib/roda/plugins/link_to.rb

Instance Method Summary collapse

Instance Method Details

Return a string with an HTML a tag with an href attribute. See LinkTo module documentation for details.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/roda/plugins/link_to.rb', line 58

def link_to(body, href, attributes=OPTS)
  case href
  when Symbol
    href = public_send(:"#{href}_path")
  when String
    # nothing
  else
    href = path(href)
  end

  href = h(href)

  body = href if body.nil?

  buf = String.new << "<a href=\"#{href}\""
  attributes.each do |k, v|
    buf << " " << k.to_s << "=\"" << h(v) << "\""
  end
  buf << ">" << body << "</a>"
end