Class: WikiChunk::Link

Inherits:
WikiLink show all
Defined in:
app/models/chunks/wiki.rb

Overview

This chunk handles [[bracketted wiki words]] and [[AliasedWords|aliased wiki words]]. The first part of an aliased wiki word must be a WikiWord. If the WikiWord is aliased, the link_text field will contain the alias, otherwise link_text will contain the entire contents within the double brackets.

NOTE: This chunk must be tested before WikiWord since

a WikiWords can be a substring of a WikiLink.

Constant Summary collapse

Regexp.new('^(.*)?\|(.*)$', 0, "utf-8")

Instance Attribute Summary collapse

Attributes inherited from Chunk::Abstract

#revision, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from WikiLink

#escaped_text, #mask, #regexp, #revert, #unmask

Methods inherited from Chunk::Abstract

#mask, #post_mask, #pre_mask, #revert, #unmask

Constructor Details

#initialize(match_data, revision) ⇒ Link

Returns a new instance of Link.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/chunks/wiki.rb', line 72

def initialize(match_data, revision)
  super(match_data, revision)

  # If the like is aliased, set the page name to the first bit
  # and the link text to the second, otherwise set both to the
  # contents of the double brackets.
  if match_data[1] =~ ALIASED_LINK_PATTERN
    @page_name, @link_text = $1, $2
  else
    @page_name, @link_text = match_data[1], match_data[1]
  end
  
  @link_text = WikiWords.separate(@link_text) if @link_text.match /^#{WikiWords::WIKI_WORD_PATTERN}$/
end

Instance Attribute Details

Returns the value of attribute link_text.



70
71
72
# File 'app/models/chunks/wiki.rb', line 70

def link_text
  @link_text
end

#page_nameObject (readonly)

Returns the value of attribute page_name.



70
71
72
# File 'app/models/chunks/wiki.rb', line 70

def page_name
  @page_name
end

Class Method Details

.patternObject



67
# File 'app/models/chunks/wiki.rb', line 67

def self.pattern() /\[\[([^\]]+)\]\]/ end