# 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

external_link(url,text=nil) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 117
    def external_link(url,text=nil)
      self.external_links << url
      elem.a({ :href => url, :target => "_blank" }) { |x| x << (text.nil? || text.blank? ? url : text) }
    end

external_links() click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 75
    def external_links
      @external_links ||= []
    end

external_links=(val) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 122
    def external_links=(val)
      @external_links = 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

image_url_for(image) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 134
    def image_url_for(image)
      "#{image}"
    end

include_resource(resource, options=[]) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 149
    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 166
    def included_templates
      @included_templates ||= {}
    end

internal_links() click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 79
    def internal_links
      @internal_links ||= []
    end

internal_links=(val) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 126
    def internal_links=(val)
      @internal_links = val
    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

link_attributes_for(page) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 138
    def link_attributes_for(page)
       { :href => url_for(page) }
    end

link_for(page, text) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 142
    def link_for(page, text)
      self.internal_links << page
      ltitle = !text.nil? && text.blank? ? self.pipe_trick(page) : text
      ltitle = page if text.nil?
      elem.a(link_attributes_for(page)) { |x| x << ltitle.strip }
    end

link_for_resource(prefix, resource, options=[]) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 174
    def link_for_resource(prefix, resource, options=[])
      ret = ""
      prefix.downcase!
      case
      when (MEDIA_NAMESPACES+FILE_NAMESPACES).include?(prefix)
        ret += wiki_image(resource,options,prefix)
      when CATEGORY_NAMESPACES.include?(prefix)
        self.categories << resource
      when LANGUAGE_NAMESPACES.include?(prefix)
        self.languages[prefix] = resource
      else
        title = options[0] ? options[0] : "#{prefix}:#{resource}"
        ret += link_for("#{prefix}:#{resource}",title)
      end
      ret
    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_link(section) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 15
    def section_link(section)
      "?section=#{section}"
    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 170
    def template(template)
      nil
    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 241
    def elem
      Builder::XmlMarkup.new
    end

pipe_trick(page) click to toggle source

    # File lib/wikicloth/wiki_link_handler.rb, line 192
    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,prefix='Image') click to toggle source

this code needs some work… lots of work

    # File lib/wikicloth/wiki_link_handler.rb, line 199
    def wiki_image(resource,options,prefix='Image')
        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="' + url_for("#{prefix.capitalize}:#{resource}") + '" class="image" title="' + sane_title + '">'
          post_img = '</a><div class="thumbcaption">' + title + '</div></div></div>'
        end
        "#{pre_img}<img src=\"#{image_url_for(resource)}\" alt=\"#{sane_title}\" title=\"#{sane_title}\" style=\"#{css.join(";")}\" />#{post_img}"
    end