Sha256: ccf40ef1dd5442b40707c797fa6744e543077404875f32c77b537f5cd272bfb8
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 KB
Contents
module ActionView module Helpers module UrlHelper alias original_convert_options_to_data_attributes convert_options_to_data_attributes def link_to_target_blank?(html_options) html_options['target'] && html_options['target'].to_s.include?('_blank') end def link_to_rel_from_html_options(html_options) html_options['rel'].is_a?(Array) ? html_options['rel'].map(&:to_s) : html_options['rel'].to_s.split(' ') end def link_to_option_enabled?(html_options, option) html_options.is_a?(Hash) && (html_options.delete(option.to_s) || html_options.delete(option.to_sym)) end def link_to_target_blank_default_rel(html_options) rel = link_to_rel_from_html_options(html_options) rel.push('noopener') if !SafeTargetBlank.opener && !link_to_option_enabled?(html_options, 'opener') rel.push('noreferrer') if !SafeTargetBlank.referrer && !link_to_option_enabled?(html_options, 'referrer') rel.map(&:presence).compact.uniq.join(' ') end def convert_options_to_data_attributes(options, html_options) if html_options html_options = html_options.stringify_keys if link_to_target_blank?(html_options) rel = link_to_target_blank_default_rel(html_options).presence html_options['rel'] = rel if rel end end original_convert_options_to_data_attributes(options, html_options) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
safe_target_blank-1.0.2 | lib/safe_target_blank/url_helper.rb |