class Card::Content::Chunk::Link
Constants
- CODE
Attributes
link_text[R]
Public Instance Methods
explicit_link?()
click to toggle source
# File lib/card/content/chunk/link.rb, line 41 def explicit_link? @explicit_link end
inspect()
click to toggle source
# File lib/card/content/chunk/link.rb, line 24 def inspect "<##{self.class}:e[#{@explicit_link}]n[#{@name}]l[#{@link_text}]" \ "p[#{@process_chunk}] txt:#{@text}>" end
link_target()
click to toggle source
# File lib/card/content/chunk/link.rb, line 55 def link_target if @explicit_link render_obj @explicit_link elsif @name referee_name end end
options()
click to toggle source
view options
# File lib/card/content/chunk/link.rb, line 30 def options link_text ? { title: link_text } : {} end
process_chunk()
click to toggle source
# File lib/card/content/chunk/link.rb, line 20 def process_chunk @process_chunk ||= render_link end
reference_code()
click to toggle source
# File lib/card/content/chunk/link.rb, line 16 def reference_code CODE end
render_link(view: :link, explicit_link_opts: {})
click to toggle source
# File lib/card/content/chunk/link.rb, line 45 def render_link view: :link, explicit_link_opts: {} @link_text = render_obj @link_text if @explicit_link render_explicit_link explicit_link_opts elsif @name render_name_link view end end
replace_reference(old_name, new_name)
click to toggle source
# File lib/card/content/chunk/link.rb, line 34 def replace_reference old_name, new_name replace_name_reference old_name, new_name replace_link_text old_name, new_name link_text_syntax = "|#{@link_text}" if @link_text.present? @text = "[[#{referee_name}#{link_text_syntax}]]" end
Private Instance Methods
divider_index(string)
click to toggle source
# File lib/card/content/chunk/link.rb, line 98 def divider_index string # there's probably a better way to do the following. # point is to find the first pipe that's not inside an nest return unless string.index "|" string_copy = string.dup string.scan(/\{\{[^}]*\}\}/) do |incl| string_copy.gsub! incl, ("x" * incl.length) end string_copy.index "|" end
interpret(match, _content)
click to toggle source
interpret a chunk matching
# File lib/card/content/chunk/link.rb, line 77 def interpret match, _content target, @link_text = target_and_link_text match[1] @link_text = objectify @link_text if target.match? %r{^(/|https?:|mailto:)} @explicit_link = objectify target else @name = target end end
objectify(raw)
click to toggle source
turn a string into a Content
object if it looks like it might have more chunks in it
# File lib/card/content/chunk/link.rb, line 112 def objectify raw return unless raw raw.strip! if raw.match?(/(^|[^\\])\{\{/) Content.new raw, format else raw end end
render_explicit_link(explicit_link_opts)
click to toggle source
# File lib/card/content/chunk/link.rb, line 65 def render_explicit_link explicit_link_opts @explicit_link = render_obj @explicit_link format.link_to_resource @explicit_link, @link_text, explicit_link_opts end
render_name_link(view)
click to toggle source
# File lib/card/content/chunk/link.rb, line 70 def render_name_link view format.with_nest_mode :normal do format.nest referee_name, options.merge(view: view) end end
replace_link_text(old_name, new_name)
click to toggle source
# File lib/card/content/chunk/link.rb, line 123 def replace_link_text old_name, new_name if @link_text.is_a?(Content) @link_text.find_chunks(:Reference).each do |chunk| chunk.replace_reference old_name, new_name end elsif @link_text.present? @link_text = old_name.to_name.sub_in(@link_text, with: new_name) end end
target_and_link_text(raw_syntax)
click to toggle source
# File lib/card/content/chunk/link.rb, line 88 def target_and_link_text raw_syntax return unless raw_syntax if (i = divider_index raw_syntax) # if [[A | B]] [raw_syntax[0..(i - 1)], raw_syntax[(i + 1)..-1]] # [A, B] else # else must be [[ A ]] [raw_syntax, nil] # [A, nil] end end