Class: WikiChunk::BlikiLink

Inherits:
WikiLink show all
Defined in:
app/models/chunks/wiki.rb

Overview

This chunk handles [bliki[entry name]]. This format has been extended for some other pre-configured redirection. Probably a bad name now, as we’re using this for any link outside the current web, but if I change the class name it’ll break existing storages.

Instance Attribute Summary collapse

Attributes inherited from Chunk::Abstract

#revision, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from WikiLink

#escaped_text, #regexp, #revert

Methods inherited from Chunk::Abstract

#post_mask, #pre_mask, #revert

Constructor Details

#initialize(match_data, revision) ⇒ BlikiLink

Returns a new instance of BlikiLink.



97
98
99
100
# File 'app/models/chunks/wiki.rb', line 97

def initialize(match_data, revision)
  super(match_data, revision)
  @target, @page_name, @link_text = match_data[1], match_data[2], match_data[2]
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



95
96
97
# File 'app/models/chunks/wiki.rb', line 95

def entry
  @entry
end

Returns the value of attribute link_text.



95
96
97
# File 'app/models/chunks/wiki.rb', line 95

def link_text
  @link_text
end

#page_nameObject (readonly)

Returns the value of attribute page_name.



95
96
97
# File 'app/models/chunks/wiki.rb', line 95

def page_name
  @page_name
end

Class Method Details

.patternObject



93
# File 'app/models/chunks/wiki.rb', line 93

def self.pattern() /\[(\w+)\[([\w\d\s]+)\]\]/ end

Instance Method Details

#mask(content) ⇒ Object



102
# File 'app/models/chunks/wiki.rb', line 102

def mask(content) pre_mask + post_mask end

#unmask(content) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/models/chunks/wiki.rb', line 104

def unmask(content)
  return self if content.sub!(regexp) { |match|
    case @target
    when 'bliki'
      web = revision.page.web
      entry = web.bliki[page_name]
      if entry.nil?
        #"<span style='background:lightgrey;font-style:italic'>Unknown Bliki entry: '#{page_name}'</span>"
        "<a class='newWikiWord' href='/#{web.address}/bliki_new/?entry_name=#{CGI::escape page_name}'>Bliki::#{page_name}</a>"
      else
        "<a class='existingWikiWord' href='/#{web.address}/bliki_revision/#{entry.name}?rev=#{entry.revisions.size-1}'>Bliki::#{entry.name}</a>"
      end
      
    when 'c2'
      "<a href='http://c2.com/cgi/wiki?#{@page_name}'>C2::#{@page_name}</a>"
      
    else
      if web = WikiService.instance.webs[@target]
        "<a href='/#{web.address}/show/#@page_name'>#{web.name}::#@page_name</a>"
      else
        "<i>#@text</i>"
      end
    end
  }
end