class Linkificator::ConditionsStorage::Condition
Attributes
options[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 4 def initialize(options={}) @options = options end
Public Instance Methods
link_to(name = nil, options = nil, html_options = nil, &block)
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 17 def link_to(name = nil, options = nil, html_options = nil, &block) html_options, options, name = options, name, block if block_given? options ||= {} view_context = view_context((html_options || {}).delete(:view_context)) if processing[:data_href] url = view_context.url_for(*options) html_options = (html_options || {}).merge('href' => '#', 'data-href' => Base64.strict_encode64(url)) end if processing[:rel_nofollow] html_options = (html_options || {}).merge(rel: 'nofollow') end link = if block_given? call_link_method(view_context, options, html_options, &block) else call_link_method(view_context, name, options, html_options) end if processing[:wrap_noindex] view_context.content_tag(:noindex) { link } else link end end
match?(options)
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 8 def match?(options) [ context[:target] ? detect_presence(context[:target], options[:target]) : true, context[:target_not] ? !detect_presence(context[:target_not], options[:target]) : true, context[:current] ? detect_presence(context[:current], options[:current]) : true, context[:current_not] ? !detect_presence(context[:current_not], options[:current]) : true, ].all? end
Private Instance Methods
call_link_method(view_context, *params, &block)
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 79 def call_link_method(view_context, *params, &block) @link_method = if options[:link_via] && view_context(view_context).respond_to?(options[:link_via]) options[:link_via] else :link_to end view_context(view_context).send(*([@link_method] + params), &block) end
context()
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 71 def context @context ||= options[:context] || {} end
detect_presence(pool, element)
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 58 def detect_presence(pool, element) pool.detect { |target| match_regexp(element, target) }.present? end
match_regexp(str, regexp_str)
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 62 def match_regexp(str, regexp_str) regexp = wrap_regexp(regexp_str) str.to_s.match(regexp) end
processing()
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 75 def processing @processing ||= options[:processing] || {} end
view_context(view_context=nil)
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 54 def view_context(view_context=nil) view_context || (@view_context ||= ViewContext.new) end
wrap_regexp(str)
click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 67 def wrap_regexp(str) /^#{str}$/i end