./pimki.rb in Pimki-1.7.092 vs ./pimki.rb in Pimki-1.8.092

- old
+ new

@@ -1,182 +1,182 @@ -#!/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 'BlueCloth' - require_gem 'rubyzip' - require 'zip/zip' - -rescue LoadError => detail - # no rubygems, so load from the libraries directory - p detail if $DEBUG - puts 'Unable to load libraries through RubyGems. Loading from ./libraries directory' - require 'bluecloth' - require 'zip/zip' -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 - -graphviz_available = (`dot -V 2>&1` =~ /dot version/) - -OPTIONS = { - :server_type => fork_available ? Daemon : SimpleServer, - :port => 2500, - :storage => "#{Dir.pwd}/storage", - :pdflatex => pdflatex_available, - :redcloth => '3', - :graphviz_available => graphviz_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\n") { |OPTIONS[:port]| } - opts.on("-s", "--simple", "--simple-server", - "Forces Instiki not to run as a Daemon if fork is available.\n" - ) { OPTIONS[:server_type] = SimpleServer } - opts.on("-t", "--storage=storage", String, - "Makes Instiki use the specified directory for storage.", - "Default: [cwd]/storage/[port]\n") { |OPTIONS[:storage]| } - opts.on("-r", "--redcloth VERSION", String, - "Makes Instiki use the specified RedCloth version.", - "You can specify major version only (2 or 3)", - "Default: 2.0.11\n") { |OPTIONS[:redcloth]| } - - - opts.separator "" - - opts.on("-h", "--help", - "Show this help message.") { puts opts; exit } - - opts.parse! -end - -Socket.do_not_reverse_lookup = true -#}}} - -# RedCloth + Modifications: {{{ -begin - if defined? Gem - if Gem.source_index.search('redcloth').map { |s| s.version.version }.include? OPTIONS[:redcloth] - require_gem 'RedCloth', "#{OPTIONS[:redcloth]}" - else - require_gem 'RedCloth', "~> #{OPTIONS[:redcloth]}" - end - end - -rescue LoadError, NoMethodError => detail - if OPTIONS[:redcloth] < '3' - require 'redcloth_2.0.11' - else - require 'redcloth' - end -end - -# Remove the "caps" spanning: -RedCloth::GLYPHS.delete_if { |glyph| glyph[1] =~ /class=\"caps\"/ } - -# Fix missing hard_break in RedCloth 3.0.0/1 -if ['3.0.0', '3.0.1'].include? RedCloth::VERSION - class RedCloth #{{{ - # Attempts at fixing the list blocks recognition: - #BLOCKS_GROUP_RE = /(^([#*> ])(?:[^\n]|\n+|\n(?!\n|\Z))+)|((?:[^\n]+|\n+ +|\n(?![#*\n]|\Z))+)/m - - 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%/, '&#38;' ) - text.strip! - text - end #}}} - end #}}} -end #}}} - -# 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/" - -on_exit = lambda { - WebControllerServer::the_active_server.shutdown - WikiService.request_stop -} - -trap "INT", on_exit -trap "TERM", on_exit - -WebControllerServer.new(OPTIONS[:port], OPTIONS[:server_type], "#{cdir}/app/controllers/") - -# }}} - +#!/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 'BlueCloth' + require_gem 'rubyzip' + require 'zip/zip' + +rescue LoadError => detail + # no rubygems, so load from the libraries directory + p detail if $DEBUG + puts 'Unable to load libraries through RubyGems. Loading from ./libraries directory' + require 'bluecloth' + require 'zip/zip' +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 + +graphviz_available = (`dot -V 2>&1` =~ /dot version/) + +OPTIONS = { + :server_type => fork_available ? Daemon : SimpleServer, + :port => 2500, + :storage => "#{Dir.pwd}/storage", + :pdflatex => pdflatex_available, + :redcloth => '3', + :graphviz_available => graphviz_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\n") { |OPTIONS[:port]| } + opts.on("-s", "--simple", "--simple-server", + "Forces Instiki not to run as a Daemon if fork is available.\n" + ) { OPTIONS[:server_type] = SimpleServer } + opts.on("-t", "--storage=storage", String, + "Makes Instiki use the specified directory for storage.", + "Default: [cwd]/storage/[port]\n") { |OPTIONS[:storage]| } + opts.on("-r", "--redcloth VERSION", String, + "Makes Instiki use the specified RedCloth version.", + "You can specify major version only (2 or 3)", + "Default: 2.0.11\n") { |OPTIONS[:redcloth]| } + + + opts.separator "" + + opts.on("-h", "--help", + "Show this help message.") { puts opts; exit } + + opts.parse! +end + +Socket.do_not_reverse_lookup = true +#}}} + +# RedCloth + Modifications: {{{ +begin + if defined? Gem + if Gem.source_index.search('redcloth').map { |s| s.version.version }.include? OPTIONS[:redcloth] + require_gem 'RedCloth', "#{OPTIONS[:redcloth]}" + else + require_gem 'RedCloth', "~> #{OPTIONS[:redcloth]}" + end + end + +rescue LoadError, NoMethodError => detail + if OPTIONS[:redcloth] < '3' + require 'redcloth_2.0.11' + else + require 'redcloth' + end +end + +# Remove the "caps" spanning: +RedCloth::GLYPHS.delete_if { |glyph| glyph[1] =~ /class=\"caps\"/ } + +# Fix missing hard_break in RedCloth 3.0.0/1 +if ['3.0.0', '3.0.1'].include? RedCloth::VERSION + class RedCloth #{{{ + # Attempts at fixing the list blocks recognition: + #BLOCKS_GROUP_RE = /(^([#*> ])(?:[^\n]|\n+|\n(?!\n|\Z))+)|((?:[^\n]+|\n+ +|\n(?![#*\n]|\Z))+)/m + + 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%/, '&#38;' ) + text.strip! + text + end #}}} + end #}}} +end #}}} + +# Start the application: {{{ +storage_dir = File.join(OPTIONS[:storage], OPTIONS[:port].to_s) +require 'fileutils' +FileUtils.mkdir_p(storage_dir) +WikiService.storage_path = storage_dir + +WikiController.template_root = "#{cdir}/app/views/" + +on_exit = lambda { + WebControllerServer::the_active_server.shutdown + WikiService.request_stop +} + +trap "INT", on_exit +trap "TERM", on_exit + +WebControllerServer.new(OPTIONS[:port], OPTIONS[:server_type], "#{cdir}/app/controllers/") + +# }}} + # jEdit :folding=explicit:collapseFolds=1: \ No newline at end of file