Class: WikiContent
- Includes:
- ChunkManager
- Defined in:
- app/models/wiki_content.rb
Constant Summary collapse
- DEFAULT_OPTS =
{ :active_chunks => ACTIVE_CHUNKS, :engine => Engines::Textile, :engine_opts => [], :mode => :show }.freeze
Constants included from ChunkManager
ChunkManager::ACTIVE_CHUNKS, ChunkManager::HIDE_CHUNKS, ChunkManager::MASK_RE
Instance Attribute Summary collapse
-
#not_rendered ⇒ Object
readonly
Returns the value of attribute not_rendered.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pre_rendered ⇒ Object
readonly
Returns the value of attribute pre_rendered.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
-
#web ⇒ Object
readonly
Returns the value of attribute web.
Attributes included from ChunkManager
#chunk_id, #chunks, #chunks_by_id, #chunks_by_type
Instance Method Summary collapse
- #build_chunks ⇒ Object
-
#initialize(revision, options = {}) ⇒ WikiContent
constructor
Create a new wiki content string from the given one.
- #page_id ⇒ Object
-
#page_link(name, text, link_type) ⇒ Object
Call @web.page_link using current options.
- #page_name ⇒ Object
- #pre_render! ⇒ Object
- #render! ⇒ Object
Methods included from ChunkManager
#add_chunk, #delete_chunk, #find_chunks, #init_chunk_manager, #merge_chunks, #scan_chunkid
Methods inherited from String
Constructor Details
#initialize(revision, options = {}) ⇒ WikiContent
Create a new wiki content string from the given one. The options are explained at the top of this file.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/models/wiki_content.rb', line 136 def initialize(revision, = {}) @revision = revision @web = @revision.page.web @options = DEFAULT_OPTS.dup.merge() @options[:engine] = Engines::MAP[@web.markup] @options[:engine_opts] = [:filter_html, :filter_styles] if @web.safe_mode @options[:active_chunks] = (ACTIVE_CHUNKS - [WikiChunk::Word] ) if @web.brackets_only super(@revision.content) init_chunk_manager build_chunks @not_rendered = String.new(self) end |
Instance Attribute Details
#not_rendered ⇒ Object (readonly)
Returns the value of attribute not_rendered.
132 133 134 |
# File 'app/models/wiki_content.rb', line 132 def not_rendered @not_rendered end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
132 133 134 |
# File 'app/models/wiki_content.rb', line 132 def @options end |
#pre_rendered ⇒ Object (readonly)
Returns the value of attribute pre_rendered.
132 133 134 |
# File 'app/models/wiki_content.rb', line 132 def pre_rendered @pre_rendered end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
132 133 134 |
# File 'app/models/wiki_content.rb', line 132 def revision @revision end |
#web ⇒ Object (readonly)
Returns the value of attribute web.
132 133 134 |
# File 'app/models/wiki_content.rb', line 132 def web @web end |
Instance Method Details
#build_chunks ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'app/models/wiki_content.rb', line 157 def build_chunks # create and mask Includes and "active_chunks" chunks Include.apply_to(self) @options[:active_chunks].each{|chunk_type| chunk_type.apply_to(self)} # Handle hiding contexts like "pre" and "code" etc.. # The markup (textile, rdoc etc) can produce such contexts with its own syntax. # To reveal them, we work on a copy of the content. # The copy is rendered and used to detect the chunks that are inside protecting context # These chunks are reverted on the original content string. copy = WikiContentStub.new(self, @options) @options[:engine].apply_to(copy) copy.inside_chunks(HIDE_CHUNKS) do |id| @chunks_by_id[id].revert end end |
#page_id ⇒ Object
203 204 205 |
# File 'app/models/wiki_content.rb', line 203 def page_id @revision.page.id end |
#page_link(name, text, link_type) ⇒ Object
Call @web.page_link using current options.
152 153 154 155 |
# File 'app/models/wiki_content.rb', line 152 def page_link(name, text, link_type) @options[:link_type] = (link_type || :show) @web.make_link(name, text, @options) end |
#page_name ⇒ Object
199 200 201 |
# File 'app/models/wiki_content.rb', line 199 def page_name @revision.page.name end |
#pre_render! ⇒ Object
176 177 178 179 180 181 182 |
# File 'app/models/wiki_content.rb', line 176 def pre_render! unless @pre_rendered @chunks_by_type[Include].each{|chunk| chunk.unmask } @pre_rendered = String.new(self) end @pre_rendered end |
#render! ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'app/models/wiki_content.rb', line 184 def render! pre_render! @options[:engine].apply_to(self) # unmask in one go. $~[1] is the chunk id gsub!(MASK_RE[ACTIVE_CHUNKS]){ if chunk = @chunks_by_id[$~[1]] chunk.unmask_text # if we match a chunkmask that existed in the original content string # just keep it as it is else $~[0] end} self end |