diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 00000000..23c4d8dd --- /dev/null +++ b/AUTHORS @@ -0,0 +1,9 @@ +Originally by Simon Rozet (http://atonie.org/2008/02/git-wiki) + +Modified by: + - Jesse Newland (http://jnewland.com/) - http auth + - Alex Payne (http://www.al3x.net) + - Jesse Andrews (http://www.overstimulate.com) + - Timoni Grone (http://www.timoni.org) - stylesheet and design aid + - Scott Chacon (http://jointheconversation.org) - ruby-git migration + - Daniel Mendler - code restructuring, support for hierarchical repositories, multiple render engines diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..88078a2c --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License + +Copyright (c) 2009 Daniel Mendler + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/README.markdown b/README.markdown index 8bfe0a53..629bb4d8 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,43 @@ README ====== -WARNING: This is an fork of the original git-wiki by [SR](http://github.com/sr/git-wiki). It is currently undocumented and not yet usable. +Git-Wiki is a a wiki that stores pages in a git repository. + +Installation +------------ + +Run with `./run.ru -sthin -p4567` and point your browser at . +It automatically creates a repository in the directory '.wiki'. + +Dependencies +------------ + +- [Sinatra][] +- [ruby-git][] +- [HAML][] +- [RubyPants][] + +Optional Dependencies +--------------------- + +- [RubyPants][] to fix puncation +- [Pygments][] for syntax highlighting + +Dependencies for page rendering +------------------------------- + +- [creole][] for creole wikitext rendering +- [RDiscount][] for markdown rendering +- [RedCloth][] for textile rendering + +At least one of the renderers should be installed. + + [Sinatra]: http://www.sinatrarb.com + [ruby-git]: http://github.com/schacon/ruby-git + [HAML]: http://haml.hamptoncatlin.com + [RDiscount]: http://github.com/rtomayko/rdiscount + [RedCloth]: http://whytheluckystiff.net/ruby/redcloth/ + [RubyPants]: http://chneukirchen.org/blog/static/projects/rubypants.html + [creole]: http://github.com/larsch/creole + [pygments]: http://pygments.org/ diff --git a/wiki.rb b/wiki.rb index 2d2c1e97..1e05cdaf 100644 --- a/wiki.rb +++ b/wiki.rb @@ -1,5 +1,5 @@ %w(rubygems sinatra_ext git haml -sass rubypants mime logger open3 +sass mime logger open3 yaml/store digest cgi).each { |dep| require dep } class Object @@ -71,7 +71,15 @@ def /(name) end module Highlighter + `pygmentize -V 2>&1 > /dev/null` + @installed = $? == 0 + + def self.installed? + @installed + end + def self.text(text, format) + return CGI::escapeHTML(text) if !installed? content = Open3.popen3("pygmentize -O linenos=table -f html -l '#{format}'") { |stdin, stdout, stderr| stdin << text stdin.close @@ -167,7 +175,6 @@ def self.child?(child, parent) add('text/x-markdown', %w(markdown md mdown mkdn mdown), %w(text/plain)) end - class Entry class ConcurrentModificationError < RuntimeError; end @@ -245,6 +252,13 @@ def forbid(conds) raise MessageError.new(failed) if !failed.empty? end +def safe_require(name) + require(name) + true +rescue LoadError + false +end + module Wiki PATH_PATTERN = '[\w.+\-_\/](?:[\w.+\-_\/ ]+[\w.+\-_\/])?' SHA_PATTERN = '[A-Fa-f0-9]{40}' @@ -511,6 +525,10 @@ def action?(name) request.path_info.ends_with? '/' + name.to_s end end + + def fix_punctuation(text) + safe_require('rubypants') ? RubyPants.new(text).to_html : text + end end class Engine @@ -559,9 +577,8 @@ def self.mime(&block) ENGINES = [ Engine.create(:creole, true) { - accepts {|page| page.mime == 'text/x-creole' } + accepts {|page| page.mime == 'text/x-creole' && safe_require('creole') } output {|page| - require 'creole' creole = Creole::CreoleParser.new class << creole def make_image_link(url) @@ -571,25 +588,19 @@ def make_link(url) escape_url(url).urlpath end end - RubyPants.new(creole.parse(page.content)).to_html + fix_punctuation(creole.parse(page.content)) } }, Engine.create(:markdown, true) { - accepts {|page| page.mime == 'text/x-markdown' } - output {|page| - require 'rdiscount' - RubyPants.new(RDiscount.new(page.content).to_html).to_html - } + accepts {|page| page.mime == 'text/x-markdown' && safe_require('rdiscount') } + output {|page| RDiscount.new(page.content).to_html } }, Engine.create(:textile, true) { - accepts {|page| page.mime == 'text/x-textile' } - output {|page| - require 'redcloth' - RubyPants.new(RedCloth.new(page.content).to_html).to_html - } + accepts {|page| page.mime == 'text/x-textile' && safe_require('redcloth') } + output {|page| fix_punctuation(RedCloth.new(page.content).to_html) } }, Engine.create(:code, true) { - accepts {|page| Highlighter.supports?(page.name) } + accepts {|page| Highlighter.installed? && Highlighter.supports?(page.name) } output {|page| Highlighter.file(page.content, page.name) } }, Engine.create(:image, true) {