WikiContent (Class)

In: app/models/wiki_content.rb
Parent: String

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 (:display),
      publishing (:publish) or export (:export)?

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

Methods

Constants

PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, URIChunk, WikiChunk::Link, WikiChunk::Word ]
POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ]
DEFAULT_OPTS = { :pre_engine_actions => PRE_ENGINE_ACTIONS, :post_engine_actions => POST_ENGINE_ACTIONS, :engine => Engines::Textile, :engine_opts => [], :mode => [:display]

Attributes

options  [R] 
rendered  [R] 
web  [R] 

Public Class methods

Create a new wiki content string from the given one. The options are explained at the top of this file.

[Source]

    # File app/models/wiki_content.rb, line 56
56:   def initialize(revision, options = {})
57:     @revision = revision
58:     @web = @revision.page.web
59: 
60:     # Deep copy of DEFAULT_OPTS to ensure that changes to PRE/POST_ENGINE_ACTIONS stay local

61:     @options = Marshal.load(Marshal.dump(DEFAULT_OPTS)).update(options)
62:     @options[:engine] = Engines::MAP[@web.markup] || Engines::Textile
63:     @options[:engine_opts] = (@web.safe_mode ? [:filter_html, :filter_styles] : [])
64: 
65:     @options[:pre_engine_actions].delete(WikiChunk::Word) if @web.brackets_only
66: 
67:     super(@revision.content)
68: 
69:     begin
70:       render!(@options[:pre_engine_actions] + [@options[:engine]] + @options[:post_engine_actions])
71:     rescue => e
72:       @rendered = e.message
73:     end
74:   end

Public Instance methods

Find all the chunks of the given type in this content Each time the type’s pattern is matched, create a new chunk for it, and replace the occurance of the chunk in this content with its mask.

[Source]

     # File app/models/wiki_content.rb, line 99
 99:   def apply_type!(chunk_type)
100:     self.gsub!( chunk_type.pattern ) do |match| 
101:       @chunks << chunk_type.new($~)
102:       @chunks.last.mask(self)
103:     end
104:   end

Find all the chunks of the given types

[Source]

    # File app/models/wiki_content.rb, line 82
82:   def find_chunks(chunk_type)
83:     rendered.select { |chunk| chunk.kind_of?(chunk_type) }
84:   end

Call @web.page_link using current options.

[Source]

    # File app/models/wiki_content.rb, line 77
77:   def page_link(name, text) 
78:     @web.make_link(name, text, @options) 
79:   end

Render this content using the specified actions.

[Source]

    # File app/models/wiki_content.rb, line 87
87:   def render!(chunk_types)
88:     @chunks = []
89:     chunk_types.each { |chunk_type| self.apply_type!(chunk_type) }
90:     
91:     @rendered = @chunks.map { |chunk| chunk.unmask(self) }.compact
92:     (@chunks - @rendered).each { |chunk| chunk.revert(self) }
93:   end

[Validate]