class WikiCloth::WikiLinkHandler

Constants

CATEGORY_NAMESPACES
FILE_NAMESPACES
LANGUAGE_NAMESPACES
MEDIA_NAMESPACES

Public Instance Methods

cache(item) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 27
def cache(item)
  nil
end
categories() click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 87
def categories
  @categories ||= []
end
categories=(val) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 101
def categories=(val)
  @categories = val
end
find_reference_by_name(n) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 91
def find_reference_by_name(n)
  references.each { |r| return r if !r[:name].nil? && r[:name].strip == n }
  return nil
end
function(name, params) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 23
def function(name, params)
  nil
end
include_resource(resource, options=[]) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 145
def include_resource(resource, options=[])
  @template_cache ||= {}
  if @template_cache[resource]
    @included_templates[resource] += 1
    @template_cache[resource]
  else
    ret = template(resource)
    unless ret.nil?
      @included_templates ||= {}
      @included_templates[resource] ||= 0
      @included_templates[resource] += 1
    end
    @template_cache[resource] = ret
    ret
  end
end
included_templates() click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 162
def included_templates
  @included_templates ||= {}
end
languages() click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 83
def languages
  @languages ||= {}
end
languages=(val) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 105
def languages=(val)
  @languages = val
end
params() click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 19
def params
  @params ||= {}
end
params=(val) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 113
def params=(val)
  @params = val
end
reference_index(h) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 96
def reference_index(h)
  references.each_index { |r| return r+1 if references[r] == h }
  return nil
end
references() click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 11
def references
  @references ||= []
end
references=(val) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 109
def references=(val)
  @references = val
end
section_list(root=nil) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 31
def section_list(root=nil)
  ret = []
  root = sections[0].children if root.nil?
  root.each do |child|
    ret << child
    unless child.children.empty?
      ret << [section_list(child.children)]
    end
  end
  ret.flatten
end
template(template) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 166
def template(template)
  nil
end
toc(sections, toc_numbered=false) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 43
def toc(sections, toc_numbered=false)
  ret = "<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">#{I18n.t('table of contents')}</div><ul>"
  previous_depth = 1
  indices = []
  section_list(sections).each do |section|
    next if section.title.nil?
    if section.depth > previous_depth
      indices[section.depth] = 0 if indices[section.depth].nil?
      indices[section.depth] += 1
      c = section.depth - previous_depth
      c.times { ret += "<ul>" }
      ret += "<li><a href=\"##{section.id}\">#{indices[0..section.depth].compact.join('.') + " " if toc_numbered}#{section.title}</a>"
    elsif section.depth == previous_depth
      indices[section.depth] = 0 if indices[section.depth].nil?
      indices[section.depth] += 1
      ret += "</li><li><a href=\"##{section.id}\">#{indices[0..section.depth].compact.join('.') + " " if toc_numbered}#{section.title}</a>"
    else 
      indices[section.depth] = 0 if indices[section.depth].nil?
      indices[section.depth] += 1
      indices = indices[0..section.depth]
      ret += "</li>" unless previous_depth == 1
      c = previous_depth - section.depth
      c.times { ret += "</ul>" }
      ret += "<li><a href=\"##{section.id}\">#{indices[0..section.depth].compact.join('.') + " " if toc_numbered}#{section.title}</a>"
    end
    previous_depth = section.depth
  end
  ret += "</li>"
  (previous_depth-1).times { ret += "</ul>" }
  "#{ret}</ul></td></tr></table>"
end
url_for(page) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 130
def url_for(page)
  "#{page}"
end

Protected Instance Methods

elem() click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 237
def elem
  Builder::XmlMarkup.new
end
pipe_trick(page) click to toggle source
# File lib/wikicloth/wiki_link_handler.rb, line 188
def pipe_trick(page)
  t = page.split(":")
  t = t[1..-1] if t.size > 1
  return t.join("").split(/[,(]/)[0]
end
wiki_image(resource,options) click to toggle source

this code needs some work… lots of work

# File lib/wikicloth/wiki_link_handler.rb, line 195
def wiki_image(resource,options)
    pre_img = ''
    post_img = ''
    css = []
    loc = "right"
    type = nil
    w = 180
    h = nil
    title = ''
    ffloat = false

    options.each do |x|
      case
      when ["miniatur","thumb","thumbnail","frame","border"].include?(x.strip)
        type = x.strip
      when ["left","right","center","none"].include?(x.strip)
        ffloat = true
        loc = x.strip
      when x.strip =~ /^([0-9]+)\s*px$/
        w = $1
        css << "width:#{w}px"
      when x.strip =~ /^([0-9]+)\s*x\s*([0-9]+)\s*px$/
        w = $1
        css << "width:#{w}px"
        h = $2
        css << "height:#{h}px"
      else
        title = x.strip
      end
    end
    css << "float:#{loc}" if ffloat == true
    css << "border:1px solid #000" if type == "border"

    sane_title = title.nil? ? "" : title.gsub(/<\/?[^>]*>/, "")
    if ["thumb","thumbnail","frame","miniatur"].include?(type)
      pre_img = '<div class="thumb t' + loc + '"><div class="thumbinner" style="width: ' + w.to_s +
          'px;"><a href="" class="image" title="' + sane_title + '">'
      post_img = '</a><div class="thumbcaption">' + title + '</div></div></div>'
    end
    "#{pre_img}<img src=\"#{resource}\" alt=\"#{sane_title}\" title=\"#{sane_title}\" style=\"#{css.join(";")}\" />#{post_img}"
end