./pimki.rb in Pimki-1.4.092 vs ./pimki.rb in Pimki-1.5.092
- old
+ new
@@ -7,80 +7,21 @@
# 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 'madeleine'
+ require_gem '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'
@@ -103,28 +44,34 @@
OPTIONS = {
:server_type => fork_available ? Daemon : SimpleServer,
:port => 2500,
:storage => "#{Dir.pwd}/storage",
- :pdflatex => pdflatex_available
+ :pdflatex => pdflatex_available,
+ :redcloth => '2.0.11'
}
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]| }
+ "Default: 2500\n") { |OPTIONS[:port]| }
opts.on("-s", "--simple", "--simple-server",
- "Forces Instiki not to run as a Daemon if fork is available."
+ "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]") { |OPTIONS[:storage]| }
+ "Default: [cwd]/storage/[port]\n") { |OPTIONS[:storage]| }
+ opts.on("-r", "--redcloth VERSION", Integer,
+ "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 }
@@ -133,23 +80,91 @@
end
Socket.do_not_reverse_lookup = true
#}}}
+# RedCloth + Modifications: {{{
+begin
+ require_gem 'RedCloth', "~> #{OPTIONS[:redcloth]}"
+
+rescue LoadError => 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%/, '&' )
+ 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/"
-trap "INT" do
+on_exit = lambda {
WebControllerServer::the_active_server.shutdown
-end
-trap "TERM" do
- WebControllerServer::the_active_server.shutdown
-end
+ MadeleineService.request_stop
+}
+
+trap "INT", on_exit
+trap "TERM", on_exit
WebControllerServer.new(OPTIONS[:port], OPTIONS[:server_type], "#{cdir}/app/controllers/")
# }}}
\ No newline at end of file