Class: WikiChunk::WikiLink

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

Overview

A wiki link is the top-level class for anything that refers to another wiki page.

Direct Known Subclasses

Include, BlikiLink, Link, Word

Instance Attribute Summary

Attributes inherited from Chunk::Abstract

#revision, #text

Instance Method Summary collapse

Methods inherited from Chunk::Abstract

#initialize, #post_mask, #pre_mask

Constructor Details

This class inherits a constructor from Chunk::Abstract

Instance Method Details

#escaped_textObject

By default, no escaped text



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

def escaped_text() nil end

#mask(content) ⇒ Object

Delimit the link text with markers to replace later unless the word is escaped. In that case, just return the link text



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

def mask(content) escaped_text || pre_mask + link_text + post_mask end

#regexpObject



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

def regexp() Regexp.new(pre_mask + '(.*)?' + post_mask) end

#revert(content) ⇒ Object



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

def revert(content) content.sub!(regexp, text) end

#unmask(content) ⇒ Object

Do not keep this chunk if it is escaped. Otherwise, pass the link procedure a page_name and link_text and get back a string of HTML to replace the mask with.



27
28
29
30
# File 'app/models/chunks/wiki.rb', line 27

def unmask(content)
  return nil if escaped_text
  return self if content.sub!(regexp) { |match| content.page_link(page_name, $1) }
end