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)?
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
-
#chunk_id ⇒ Object
readonly
Returns the value of attribute chunk_id.
-
#chunks ⇒ Object
readonly
Returns the value of attribute chunks.
-
#chunks_by_id ⇒ Object
readonly
Returns the value of attribute chunks_by_id.
-
#chunks_by_type ⇒ Object
readonly
Returns the value of attribute chunks_by_type.
Instance Method Summary collapse
- #add_chunk(c) ⇒ Object
- #delete_chunk(c) ⇒ Object
- #find_chunks(chunk_type) ⇒ Object
- #init_chunk_manager ⇒ Object
- #merge_chunks(other) ⇒ Object
-
#page_id ⇒ Object
for testing and WikiContentStub; we need a page_id even if we have no page.
- #scan_chunkid(text) ⇒ Object
Instance Attribute Details
#chunk_id ⇒ Object (readonly)
Returns the value of attribute chunk_id.
38 39 40 |
# File 'app/models/wiki_content.rb', line 38 def chunk_id @chunk_id end |
#chunks ⇒ Object (readonly)
Returns the value of attribute chunks.
38 39 40 |
# File 'app/models/wiki_content.rb', line 38 def chunks @chunks end |
#chunks_by_id ⇒ Object (readonly)
Returns the value of attribute chunks_by_id.
38 39 40 |
# File 'app/models/wiki_content.rb', line 38 def chunks_by_id @chunks_by_id end |
#chunks_by_type ⇒ Object (readonly)
Returns the value of attribute chunks_by_type.
38 39 40 |
# File 'app/models/wiki_content.rb', line 38 def chunks_by_type @chunks_by_type end |
Instance Method Details
#add_chunk(c) ⇒ Object
60 61 62 63 64 65 |
# File 'app/models/wiki_content.rb', line 60 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
67 68 69 70 71 |
# File 'app/models/wiki_content.rb', line 67 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
81 82 83 |
# File 'app/models/wiki_content.rb', line 81 def find_chunks(chunk_type) @chunks.select { |chunk| chunk.kind_of?(chunk_type) and chunk.rendered? } end |
#init_chunk_manager ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'app/models/wiki_content.rb', line 50 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
73 74 75 |
# File 'app/models/wiki_content.rb', line 73 def merge_chunks(other) other.chunks.each{|c| add_chunk(c)} end |
#page_id ⇒ Object
for testing and WikiContentStub; we need a page_id even if we have no page
86 87 88 |
# File 'app/models/wiki_content.rb', line 86 def page_id 0 end |
#scan_chunkid(text) ⇒ Object
77 78 79 |
# File 'app/models/wiki_content.rb', line 77 def scan_chunkid(text) text.scan(MASK_RE[ACTIVE_CHUNKS]){|a| yield a[0] } end |