lib/flannel/stripe.rb in flannel-0.1.5 vs lib/flannel/stripe.rb in flannel-0.2.1

- old
+ new

@@ -1,7 +1,5 @@ -#require 'wrappable' -#require 'feed_parser' module Flannel class Stripe include Wrappable attr_reader :weave @@ -10,56 +8,58 @@ Flannel::Stripe.new weave, params end def initialize weave="", params={} @weave = weave - @wiki_link = params[:wiki_link] - @style = params[:style] + @params = params end def wiki_link topic - if @wiki_link - @wiki_link.call(permalink topic) + if @params[:wiki_link] + @params[: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 + topic.gsub(%r{[^/\w\s\-]},'').gsub(%r{[^\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>}} + @weave.gsub(/-\w(.*?)\w>/) { |match| %{<a href="#{wiki_link match}">#{format_link_display(match)}</a>}} end + + def format_link_display text + text[1..-2].split("/").last + end def to_h + if feed - parser = Flannel::FeedParser.new + parser = Flannel::FeedParser.new @params parser.sub_feeds @weave else text = build_wiki_links markup text end end def preformatted - @style == :preformatted + @params[:style] == :preformatted end def list - @style == :list + @params[:style] == :list end def feed - @style == :feed + @params[:style] == :feed end def markup text return html_escape text if preformatted