moved apply_to from WikiContent to Chunk, so tha UriChunk can override it and decide when it
wants to match a URL and when it doesn't want to the in the way of Textile syntax
This commit is contained in:
parent
02930e20fe
commit
e8b2a3c30a
2 changed files with 34 additions and 17 deletions
|
@ -11,10 +11,37 @@ module Chunk
|
|||
attr_reader :text
|
||||
|
||||
def initialize(match_data) @text = match_data[0] end
|
||||
def pre_mask() "chunk#{self.object_id}start " end
|
||||
def post_mask() " chunk#{self.object_id}end" end
|
||||
def mask(content) "chunk#{self.object_id}chunk" end
|
||||
def revert(content) content.sub!( Regexp.new(mask(content)), text ) end
|
||||
def unmask(content) self if revert(content) end
|
||||
|
||||
# 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.
|
||||
def self.apply_to(content)
|
||||
content.gsub!( self.pattern ) do |match|
|
||||
content.chunks << self.new($~)
|
||||
content.chunks.last.mask(content)
|
||||
end
|
||||
end
|
||||
|
||||
def pre_mask()
|
||||
"chunk#{self.object_id}start "
|
||||
end
|
||||
|
||||
def post_mask()
|
||||
" chunk#{self.object_id}end"
|
||||
end
|
||||
|
||||
def mask(content)
|
||||
"chunk#{self.object_id}chunk"
|
||||
end
|
||||
|
||||
def revert(content)
|
||||
content.sub!( Regexp.new(mask(content)), text )
|
||||
end
|
||||
|
||||
def unmask(content)
|
||||
self if revert(content)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue