module Flatrack::View::LinkHelper
View
helpers to render link tags
Public Instance Methods
link_to(*args, &block)
click to toggle source
Creates an HTML link tag
@overload link_to
(href, options={})
Creates an html link tag to URL, using the URL as the content of the tag. @param href [String] the link @param options [Hash] html options for the tag @return [String]
@overload link_to
(content, href, options={})
Creates an html link tag to URL, using the provided content as the content of the tag. @param content [String] the content to be displayed for the link tag @param href [String] the link @param options [Hash] html options for the tag @return [String]
@overload link_to
(href, options={}, &block)
Creates an html link tag to URL, using the provided return value of the block as the content of the tag. @param href [String] the link @yield the content of the tag @return [String]
# File lib/flatrack/view/link_helper.rb, line 33 def link_to(*args, &block) href, options, block = link_to_options(*args, &block) if href.start_with?('/') && !href.start_with?('//') && mount_path != '/' href = File.join '', mount_path, href end tag_opts = link_to_tag_options(href, options || {}) if current_path == tag_opts[:href] ((tag_opts[:class] ||= '') << ' active').strip! end html_tag(:a, tag_opts, false, &block) end
Private Instance Methods
link_to_options(content_or_href = nil, href_or_options = nil, options = nil, &block)
click to toggle source
# File lib/flatrack/view/link_helper.rb, line 47 def link_to_options(content_or_href = nil, href_or_options = nil, options = nil, &block) if block_given? [content_or_href, href_or_options, block] elsif href_or_options.is_a?(Hash) || href_or_options.blank? [content_or_href, href_or_options, proc { content_or_href }] else [href_or_options, options, proc { content_or_href }] end end
link_to_tag_options(link, opts = {})
click to toggle source
# File lib/flatrack/view/link_helper.rb, line 58 def link_to_tag_options(link, opts = {}) link << '?' + opts.delete(:params).to_param if opts[:params].present? { href: link }.merge(opts) end