Created
September 30, 2012 23:04
Tinki, a really short wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
%w{sinatra redcarpet erb}.map{|l|require l};include Redcarpet | |
md=Markdown.new Class.new(Render::HTML){def preprocess text;text.gsub /\[\[([\w-]+?)\]\]/,'[\1](/\1)';end},filter_html:1 | |
helpers{include ERB::Util};Dir.mkdir'w'unless Dir.exist?'w' | |
get('/'){redirect to'home'} | |
get('/:p'){f='w/'+params[:p];File.exist?(f)? "<h1>#{h params[:p]}</h1>#{md.render File.read f}<a href=\"/#{params[:p]}/edit\">edit</a>; last was #{File.mtime f}": redirect(to params[:p]+'/edit')} | |
get('/:p/edit'){"<h1>Edit #{h params[:p]}</h1><form method=post><textarea name=c>#{h File.read "w/#{params[:p]}" rescue()}</textarea><input type=submit></form>"} | |
post('/:p/edit'){File.write('w/'+params[:p],params[:c]);redirect to params[:p]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not quite smaller than WyPy yet.