Class: Include

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

Overview

Includes the contents of another page for rendering. The include command looks like this: “[[!include PageName]]”. It is a WikiLink since it refers to another page (PageName) and the wiki content using this command must be notified of changes to that page. If the included page could not be found, a warning is displayed.

Instance Attribute Summary collapse

Attributes inherited from Chunk::Abstract

#revision, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from WikiChunk::WikiLink

#escaped_text, #regexp, #revert

Methods inherited from Chunk::Abstract

#post_mask, #pre_mask, #revert

Constructor Details

#initialize(match_data, revision) ⇒ Include

Returns a new instance of Include.



14
15
16
17
# File 'app/models/chunks/include.rb', line 14

def initialize(match_data, revision)
  super(match_data, revision)
  @page_name = match_data[1].strip
end

Instance Attribute Details

#page_nameObject (readonly)

Returns the value of attribute page_name.



12
13
14
# File 'app/models/chunks/include.rb', line 12

def page_name
  @page_name
end

Class Method Details

.patternObject



10
# File 'app/models/chunks/include.rb', line 10

def self.pattern() /^\s*\[\[!include([^\]]*)\]\]\s*$/i end

Instance Method Details

#mask(content) ⇒ Object

This replaces the [[!include PageName]] text with the contents of PageName if it exists. Otherwise a warning is displayed.



22
23
24
25
# File 'app/models/chunks/include.rb', line 22

def mask(content) 
  page = content.web.pages[page_name]
  (page ? page.content : "<em>Could not include #{page_name}</em>")
end

#unmask(content) ⇒ Object

Keep this chunk regardless of what happens.



28
# File 'app/models/chunks/include.rb', line 28

def unmask(content) self end