Module: ChunkManager

Included in:
WikiContent, WikiContentStub
Defined in:
app/models/wiki_content.rb

Overview

Wiki content is just a string that can process itself with a chain of actions. The actions can modify wiki content so that certain parts of it are protected from being rendered by later actions.

When wiki content is rendered, it can be interrogated to find out which chunks were rendered. This means things like categories, wiki links, can be determined.

Exactly how wiki content is rendered is determined by a number of settings that are optionally passed in to a constructor. The current options are:

* :engine 
  => The structural markup engine to use (Textile, Markdown, RDoc)
* :engine_opts
  => A list of options to pass to the markup engines (safe modes, etc)
* :pre_engine_actions
  => A list of render actions or chunks to be processed before the
     markup engine is applied. By default this is:    
     Category, Include, URIChunk, WikiChunk::Link, WikiChunk::Word        
* :post_engine_actions
  => A list of render actions or chunks to apply after the markup 
     engine. By default these are:    
     Literal::Pre, Literal::Tags
* :mode
  => How should the content be rendered? For normal display (show), 
     publishing (:publish) or export (:export)?

AUTHOR: Mark Reid <mark @ threewordslong . com> CREATED: 15th May 2004 UPDATED: 22nd May 2004

Constant Summary collapse

ACTIVE_CHUNKS =
[ NoWiki, Category, WikiChunk::Link, URIChunk, LocalURIChunk, 
WikiChunk::Word ]
HIDE_CHUNKS =
[ Literal::Pre, Literal::Tags ]
MASK_RE =
{ 
  ACTIVE_CHUNKS => Chunk::Abstract.mask_re(ACTIVE_CHUNKS),
  HIDE_CHUNKS => Chunk::Abstract.mask_re(HIDE_CHUNKS)
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chunk_idObject (readonly)

Returns the value of attribute chunk_id.



42
43
44
# File 'app/models/wiki_content.rb', line 42

def chunk_id
  @chunk_id
end

#chunksObject (readonly)

Returns the value of attribute chunks.



42
43
44
# File 'app/models/wiki_content.rb', line 42

def chunks
  @chunks
end

#chunks_by_idObject (readonly)

Returns the value of attribute chunks_by_id.



42
43
44
# File 'app/models/wiki_content.rb', line 42

def chunks_by_id
  @chunks_by_id
end

#chunks_by_typeObject (readonly)

Returns the value of attribute chunks_by_type.



42
43
44
# File 'app/models/wiki_content.rb', line 42

def chunks_by_type
  @chunks_by_type
end

Instance Method Details

#add_chunk(c) ⇒ Object



64
65
66
67
68
69
# File 'app/models/wiki_content.rb', line 64

def add_chunk(c)
    @chunks_by_type[c.class] << c
    @chunks_by_id[c.id] = c
    @chunks << c
    @chunk_id += 1
end

#delete_chunk(c) ⇒ Object



71
72
73
74
75
# File 'app/models/wiki_content.rb', line 71

def delete_chunk(c)
  @chunks_by_type[c.class].delete(c)
  @chunks_by_id.delete(c.id)
  @chunks.delete(c)
end

#find_chunks(chunk_type) ⇒ Object



85
86
87
# File 'app/models/wiki_content.rb', line 85

def find_chunks(chunk_type)
  @chunks.select { |chunk| chunk.kind_of?(chunk_type) and chunk.rendered? }
end

#init_chunk_managerObject



54
55
56
57
58
59
60
61
62
# File 'app/models/wiki_content.rb', line 54

def init_chunk_manager
  @chunks_by_type = Hash.new
  Chunk::Abstract::derivatives.each{|chunk_type| 
    @chunks_by_type[chunk_type] = Array.new 
  }
  @chunks_by_id = Hash.new
  @chunks = []
  @chunk_id = 0
end

#merge_chunks(other) ⇒ Object



77
78
79
# File 'app/models/wiki_content.rb', line 77

def merge_chunks(other)
  other.chunks.each{|c| add_chunk(c)}
end

#page_idObject

for testing and WikiContentStub; we need a page_id even if we have no page



90
91
92
# File 'app/models/wiki_content.rb', line 90

def page_id
  0
end

#scan_chunkid(text) ⇒ Object



81
82
83
# File 'app/models/wiki_content.rb', line 81

def scan_chunkid(text)
  text.scan(MASK_RE[ACTIVE_CHUNKS]){|a| yield a[0] }
end