Sha256: 29132b98e9b8ba5306af8d547d1eafa41a1decc85788c053d00430b445d0b4c1

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'wrappable'

module Flannel
  class Stripe
    include Wrappable
    attr_reader :weave

    def self.stitch weave="", params={}
       Flannel::Stripe.new weave, params
    end

    def initialize weave="", params={}
      @weave = weave
      @wiki_link = params[:wiki_link]
      @style = params[:style]
    end
    
    def wiki_link topic
      if @wiki_link
        @wiki_link.call(permalink topic)
      else
        permalink topic[1..-2]
      end
    end

    def permalink topic
      require 'iconv'
      # thanks to ismasan http://snippets.dzone.com/posts/show/4457
      (Iconv.new('US-ASCII//TRANSLIT', 'utf-8').iconv topic).gsub(/[^\w\s\-]/,'').gsub(/[^\w]|[\_]/,' ').split.join('-').downcase
    end

    def empty?
      @weave == nil || @weave.strip == ""
    end

    def build_wiki_links
      return @weave if preformatted
      @weave.gsub(/-\w(.*)\w>/) { |match| %{<a href="#{wiki_link match}">#{match[1..-2]}</a>}}
    end

    def to_h
      text = build_wiki_links
      markup text
    end

    def preformatted
      @style == :preformatted
    end

    def list
      @style == :list
    end

    def markup text
      return html_escape text if preformatted

      tag = "li" if list
      wrap(text, tag)
    end

    def html_escape text
      require 'cgi'

      CGI::escapeHTML(text)
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
rubyyot-flannel-0.0.1 lib/stripe.rb
flannel-0.0.1 lib/stripe.rb