class Card::Content::Chunk::Link

Constants

CODE

Attributes

Public Instance Methods

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
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
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