Sha256: 66b552a59bb335cdfae24f9882074cd0f74d456fb8c0c6603445c01b3821fb8d

Contents?: true

Size: 963 Bytes

Versions: 4

Compression:

Stored size: 963 Bytes

Contents

module OpenConferenceWare
  module DisplayLinkToHelper

    # Return a #link_to for a +url+ that's been sanitized by #h, had its text
    # truncated, and optionally has the 'rel="nofollow"' flag set.
    #
    # Options:
    # * maxlength: Maximum length of the displayed URL. Defaults to 64.
    # * nofollow: Include a 'rel="nofollow"' in link to discourage spammers. Defaults to true.
    # * mailto: The URL is an email address and should be rendered as a mailto link.
    # * title: Title to give link, else URL.
    def display_link_to(url, opts={})
      opts.symbolize_keys!.reverse_merge!({
        maxlength: 64,
        nofollow: true,
        mailto: false
      })
      link_to_opts = {}
      link_to_opts[:rel] = "nofollow" if opts[:nofollow]
      truncated_url = truncate(url, length: opts[:maxlength])
      url = "mailto:#{url}" if opts[:mailto];
      return link_to(h(opts[:title] || truncated_url), h(url), link_to_opts)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
open_conference_ware-1.0.0.pre4 app/helpers/open_conference_ware/display_link_to_helper.rb
open_conference_ware-1.0.0.pre3 app/helpers/open_conference_ware/display_link_to_helper.rb
open_conference_ware-1.0.0.pre2 app/helpers/open_conference_ware/display_link_to_helper.rb
open_conference_ware-1.0.0.pre1 app/helpers/open_conference_ware/display_link_to_helper.rb