Skip to content

Instantly share code, notes, and snippets.

@dpk
Created September 30, 2012 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpk/3808680 to your computer and use it in GitHub Desktop.
Save dpk/3808680 to your computer and use it in GitHub Desktop.
Tinki, a really short wiki
#!/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]}
@dpk
Copy link
Author

dpk commented Sep 30, 2012

Not quite smaller than WyPy yet.

@dpk
Copy link
Author

dpk commented Sep 30, 2012

Shorter than WyPy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment