#!/usr/local/bin/ruby if RUBY_VERSION < "1.8.1" puts "Pimki requires Ruby 1.8.1+" exit end # Handle rubygems support & loading libraries: {{{ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "libraries") begin require 'rubygems' require_gem 'madeleine' require_gem 'RedCloth' require_gem 'rubyzip' rescue LoadError => detail # no rubygems, so load from the libraries directory p detail require 'redcloth' require 'bluecloth' end ### RedCloth Modifications: # Remove the "caps" spanning: RedCloth::GLYPHS.delete_if { |glyph| glyph[1] =~ /class=\"caps\"/ } # Fix missing hard_break if RedCloth::VERSION == '3.0.0' class RedCloth #{{{ alias_method :old_clean_white_space, :clean_white_space def clean_white_space text old_clean_white_space text hard_break text end end #}}} else # Redcloth v3.0.0 can handle markdown, so BlueCloth is only required if we # have an earlier redcloth version. require 'BlueCloth' end # }}} # Handle command-line options: {{{ require 'optparse' cdir = File.expand_path(File.dirname(__FILE__)) %w( /libraries/ /app/models /app/controllers ).each { |dir| $:.unshift(cdir + dir) } %w( web_controller_server action_controller_servlet wiki_service wiki ).each { |lib| require lib } fork_available = true begin exit unless fork rescue NotImplementedError fork_available = false end begin pdflatex_available = system "pdflatex -version" rescue Errno::ENOENT pdflatex_available = false end OPTIONS = { :server_type => fork_available ? Daemon : SimpleServer, :port => 2500, :storage => "#{Dir.pwd}/storage", :pdflatex => pdflatex_available } ARGV.options do |opts| script_name = File.basename($0) opts.banner = "Usage: ruby #{script_name} [options]" opts.separator "" opts.on("-p", "--port=port", Integer, "Runs Instiki on the specified port.", "Default: 2500") { |OPTIONS[:port]| } opts.on("-s", "--simple", "--simple-server", "Forces Instiki not to run as a Daemon if fork is available." ) { OPTIONS[:server_type] = SimpleServer } opts.on("-t", "--storage=storage", String, "Makes Instiki use the specified directory for storage.", "Default: [cwd]/storage/[port]") { |OPTIONS[:storage]| } opts.separator "" opts.on("-h", "--help", "Show this help message.") { puts opts; exit } opts.parse! end Socket.do_not_reverse_lookup = true #}}} # Start the application: {{{ storage_dir = OPTIONS[:storage] + "/" + OPTIONS[:port].to_s require 'fileutils' FileUtils.mkdir_p(storage_dir) WikiService.storage_path = storage_dir WikiController.template_root = "#{cdir}/app/views/" trap "INT" do WebControllerServer::the_active_server.shutdown end trap "TERM" do WebControllerServer::the_active_server.shutdown end WebControllerServer.new(OPTIONS[:port], OPTIONS[:server_type], "#{cdir}/app/controllers/") # }}} # jEdit :folding=explicit:collapseFolds=1: