Class: Chunk::Abstract
- Inherits:
-
Object
- Object
- Chunk::Abstract
- Defined in:
- app/models/chunks/chunk.rb
Direct Known Subclasses
Category, Engines::AbstractEngine, Literal::AbstractLiteral, NoWiki, URIChunk, WikiChunk::WikiReference
Class Attribute Summary collapse
-
.derivatives ⇒ Object
readonly
Returns the value of attribute derivatives.
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#unmask_mode ⇒ Object
readonly
Returns the value of attribute unmask_mode.
-
#unmask_text ⇒ Object
readonly
Returns the value of attribute unmask_text.
Class Method Summary collapse
-
.apply_to(content) ⇒ Object
Find all the chunks of the given type in content Each time the pattern is matched, create a new chunk for it, and replace the occurance of the chunk in this content with its mask.
- .inherited(klass) ⇒ Object
-
.mask_re(chunk_types) ⇒ Object
a regexp that matches all chunk_types masks.
-
.mask_string ⇒ Object
the class name part of the mask strings.
Instance Method Summary collapse
- #escaped? ⇒ Boolean
-
#id ⇒ Object
We should not use object_id because object_id is not guarantied to be unique when we restart the wiki (new object ids can equal old ones that were restored from madeleine storage).
-
#initialize(match_data, content) ⇒ Abstract
constructor
A new instance of Abstract.
-
#mask ⇒ Object
should contain only [a-z0-9].
- #rendered? ⇒ Boolean
- #revert ⇒ Object
- #unmask ⇒ Object
Constructor Details
#initialize(match_data, content) ⇒ Abstract
Returns a new instance of Abstract.
36 37 38 39 40 |
# File 'app/models/chunks/chunk.rb', line 36 def initialize(match_data, content) @text = match_data[0] @content = content @unmask_mode = :normal end |
Class Attribute Details
.derivatives ⇒ Object (readonly)
Returns the value of attribute derivatives.
16 17 18 |
# File 'app/models/chunks/chunk.rb', line 16 def derivatives @derivatives end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
34 35 36 |
# File 'app/models/chunks/chunk.rb', line 34 def text @text end |
#unmask_mode ⇒ Object (readonly)
Returns the value of attribute unmask_mode.
34 35 36 |
# File 'app/models/chunks/chunk.rb', line 34 def unmask_mode @unmask_mode end |
#unmask_text ⇒ Object (readonly)
Returns the value of attribute unmask_text.
34 35 36 |
# File 'app/models/chunks/chunk.rb', line 34 def unmask_text @unmask_text end |
Class Method Details
.apply_to(content) ⇒ Object
Find all the chunks of the given type in content Each time the pattern is matched, create a new chunk for it, and replace the occurance of the chunk in this content with its mask.
46 47 48 49 50 51 52 |
# File 'app/models/chunks/chunk.rb', line 46 def self.apply_to(content) content.gsub!( self.pattern ) do |match| new_chunk = self.new($~, content) content.add_chunk(new_chunk) new_chunk.mask end end |
.inherited(klass) ⇒ Object
19 20 21 |
# File 'app/models/chunks/chunk.rb', line 19 def self::inherited( klass ) Abstract::derivatives << klass end |
.mask_re(chunk_types) ⇒ Object
a regexp that matches all chunk_types masks
29 30 31 32 |
# File 'app/models/chunks/chunk.rb', line 29 def Abstract::mask_re(chunk_types) tmp = chunk_types.map{|klass| klass.mask_string}.join("|") Regexp.new("chunk([0-9a-f]+n\\d+)(#{tmp})chunk") end |
.mask_string ⇒ Object
the class name part of the mask strings
24 25 26 |
# File 'app/models/chunks/chunk.rb', line 24 def self.mask_string self.to_s.delete(':').downcase end |
Instance Method Details
#escaped? ⇒ Boolean
74 75 76 |
# File 'app/models/chunks/chunk.rb', line 74 def escaped? @unmask_mode == :escape end |
#id ⇒ Object
We should not use object_id because object_id is not guarantied to be unique when we restart the wiki (new object ids can equal old ones that were restored from madeleine storage)
62 63 64 |
# File 'app/models/chunks/chunk.rb', line 62 def id @id ||= "#{@content.page_id}n#{@content.chunk_id}" end |
#mask ⇒ Object
should contain only [a-z0-9]
55 56 57 |
# File 'app/models/chunks/chunk.rb', line 55 def mask @mask ||="chunk#{@id}#{self.class.mask_string}chunk" end |
#rendered? ⇒ Boolean
70 71 72 |
# File 'app/models/chunks/chunk.rb', line 70 def rendered? @unmask_mode == :normal end |
#revert ⇒ Object
78 79 80 81 82 |
# File 'app/models/chunks/chunk.rb', line 78 def revert @content.sub!(mask, @text) # unregister @content.delete_chunk(self) end |
#unmask ⇒ Object
66 67 68 |
# File 'app/models/chunks/chunk.rb', line 66 def unmask @content.sub!(mask, @unmask_text) end |