Skip to content

Commit

Permalink
using new parser extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
David Ricciardi authored and David Ricciardi committed Aug 6, 2010
1 parent e64a6d8 commit 4d17233
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions examples/wiki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
else
p = {}
headers.each { |k,v| p[$1.upcase.gsub(/\-/,'_')] = v if k =~ /x-amz-(.*)/ }
@wiki = WikiCloth::WikiCloth.new({
@wiki = WikiParser.new({
:data => response.body.respond_to?(:read) ? response.body.read : response.body.to_s,
:link_handler => CustomLinkHandler.new,
:params => p
})
r :wiki, @slot.name.gsub(/_/,' ')
Expand Down Expand Up @@ -67,28 +66,26 @@
end
end

class CustomLinkHandler < WikiCloth::WikiLinkHandler
def url_for(page)
class WikiParser < WikiCloth::Parser
url_for do |page|
page = page.strip.gsub(/\s+/,'_')
page = "/#{$1.downcase}/#{$2}" if page =~ /^([A-Za-z]+):(.*)$/
page
end

def link_attributes_for(page)
{ :href => url_for(page) }
external_link do |url,text|
"<a href=\"#{url}\" target=\"_blank\" class=\"exlink\">#{text.blank? ? url : text}</a>"
end

def external_link(url,text)
self.external_links << url
elem.a({ :href => url, :target => "_blank", :class => "exlink" }) { |x| x << (text.blank? ? url : text) }
template do |template|
begin
bucket = Bucket.find_root('templates')
slot = bucket.find_slot(template.strip.gsub(/\s+/,'_'))
slot.nil? ? nil : File.read(File.join(S3::STORAGE_PATH, slot.obj.path))
rescue S3::NoSuchKey
nil
end
end

def include_template(template)
bucket = Bucket.find_root('templates')
slot = bucket.find_slot(template.strip.gsub(/\s+/,'_'))
slot.nil? ? nil : File.read(File.join(S3::STORAGE_PATH, slot.obj.path))
end

end

class S3::Application < Sinatra::Base; enable :inline_templates; end
Expand Down

0 comments on commit 4d17233

Please sign in to comment.