#!/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 'madeleine' require 'redcloth' require 'bluecloth' require_gem 'rubyzip' require 'zip/zip' rescue LoadError => detail # no rubygems, so load from the libraries directory p detail require 'redcloth' require 'bluecloth' require 'zip/zip' 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 #{{{ def to_html( *rules ) rules = @rules if rules.empty? # make our working copy text = self.dup @urlrefs = {} @shelf = [] textile_rules = [:refs_textile, :block_textile_table, :block_textile_lists, :block_textile_prefix, :inline_textile_image, :inline_textile_link, :inline_textile_code, :inline_textile_span, :inline_textile_glyphs] markdown_rules = [:refs_markdown, :block_markdown_setext, :block_markdown_atx, :block_markdown_rule, :block_markdown_bq, :block_markdown_lists, :inline_markdown_reflink, :inline_markdown_link] @rules = rules.collect do |rule| case rule when :markdown markdown_rules when :textile textile_rules else rule end end.flatten # standard clean up incoming_entities text clean_white_space text # start processor pre_list = rip_offtags text refs text blocks text inline text smooth_offtags text, pre_list retrieve text hard_break text # PIMKI: this is the missing bit! text.gsub!( /<\/?notextile>/, '' ) text.gsub!( /x%x%/, '&' ) text.strip! 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: