Sha256: fab75be02d5292c4127d7de1bc4f9cb42268bdf90af4d184b3f443f04505be00
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
# -*- coding: utf-8 -*- vim: encoding=utf-8:sw=4:ts=4:sts=4:et: $KCODE = 'u' require 'rblosxom/base' require 'uri' module Rblosxom class Base < Sinatra::Base not_found do haml :'404', :layout => false end error do haml :'500', :layout => false end helpers do def title File.basename(Dir.getwd).gsub(/_/, ' ') end def pages Dir.chdir(File.expand_path("#{@root}/#{@config["datadir"]}")) { Dir["**/*.textile"].sort } end end end class Wiki < Base get '/?' do set_common_variables @log.info "Wiki Render start" @log.debug "Wiki Render debug" # If there is only one file present, serve that instantly.` redirect "/wiki/#{pages.first}", 302 if pages.size == 1 haml :wikis, :layout => true end page_regex = '(?:/.+)+' page_url = %r@^(#{page_regex})\b$@ get page_url do set_common_variables @log.info "Wiki Render #{request.env["PATH_INFO"]}" @log.info "Wiki Render #{params[:captures]}" request_file = File.expand_path("#{@root}/#{@config["datadir"]}/#{request.env["PATH_INFO"][1..-1]}") @log.debug "Wiki Render request file: #{request_file}" begin haml :wiki, :layout => true, :locals => { :content => File.read(URI.decode(request_file)) } rescue #raise Sinatra::NotFound halt 404, 'page not found!' end end end end # wiki_render.rb end here
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rblosxom-0.1.6 | demo/wiki_render.rb |