lib/slideshow.rb in slideshow-0.7.2 vs lib/slideshow.rb in slideshow-0.7.3
- old
+ new
@@ -1,22 +1,23 @@
-$KCODE="U"
+$KCODE = 'utf'
require 'optparse'
require 'erb'
require 'redcloth'
-require 'maruku'
require 'logger'
require 'fileutils'
require 'ftools'
-require 'hpricot'
-require 'uv'
require 'pp'
+# todo: move code highlighting in (optional) plugin/extension
+# require 'hpricot'
+# require 'uv'
+
module Slideshow
- VERSION = '0.7.2'
+ VERSION = '0.7.3'
class Params
def initialize( name, headers )
@name = name
@@ -167,10 +168,24 @@
class Gen
KNOWN_TEXTILE_EXTNAMES = [ '.textile', '.t' ]
KNOWN_MARKDOWN_EXTNAMES = [ '.markdown', '.mark', '.m', '.txt', '.text' ]
+
+ # note: only bluecloth is listed as a dependency in gem specs (because it's Ruby only and, thus, easy to install)
+ # if you want to use other markdown libs install the required/desired lib e.g.
+ # use gem install rdiscount for rdiscount and so on
+ #
+ # also note for now the first present markdown library gets used
+ # the search order is first come, first serve, that is: rdiscount, rpeg-markdown, maruku, bluecloth (fallback, always present)
+ KNOWN_MARKDOWN_LIBS = [
+ [ 'rdiscount', lambda { |content| RDiscount.new( content ).to_html } ],
+ [ 'rpeg-markdown', lambda { |content| PEGMarkdown.new( content ).to_html } ],
+ [ 'maruku', lambda { |content| Maruku.new( content, {:on_error => :raise} ).to_html } ],
+ [ 'bluecloth', lambda { |content| BlueCloth.new( content ).to_html } ]
+ ]
+
BUILTIN_MANIFESTS = [ 'fullerscreen.txt', 'fullerscreen.txt.gen',
's5.txt','s5.txt.gen',
's6.txt','s6.txt.gen' ]
def initialize
@@ -184,11 +199,33 @@
end
def opts
@opts
end
+
+ def check_markdown_libs
+ # check for available markdown libs/gems
+ # try to require each lib and remove any not installed
+ @markdown_libs = []
+ KNOWN_MARKDOWN_LIBS.each do |lib|
+ begin
+ require lib[0]
+ @markdown_libs << lib
+ rescue LoadError => ex
+ logger.debug "Markdown library #{lib[0]} not found. Use gem install #{lib[0]} to install."
+ end
+ end
+
+ logger.debug "Installed Markdown libraries: #{@markdown_libs.map{ |lib| lib[0] }.join(', ')}"
+ logger.debug "Using Markdown library #{@markdown_libs.first[0]}."
+ end
+
+ def markdown_to_html( content )
+ @markdown_libs.first[1].call( content )
+ end
+
def cache_dir
PLATFORM =~ /win32/ ? win32_cache_dir : File.join(File.expand_path("~"), ".slideshow")
end
def win32_cache_dir
@@ -380,11 +417,12 @@
puts "Preparing slideshow '#{basename}'..."
# convert light-weight markup to hypertext
if KNOWN_MARKDOWN_EXTNAMES.include?( extname )
- content = Maruku.new( content, {:on_error => :raise} ).to_html
+ content = markdown_to_html( content )
+ # old code: content = Maruku.new( content, {:on_error => :raise} ).to_html
# old code: content = BlueCloth.new( content ).to_html
else
# turn off hard line breaks
# turn off span caps (see http://rubybook.ca/2008/08/16/redcloth)
red = RedCloth.new( content, [:no_span_caps] )
@@ -560,9 +598,11 @@
puts "Slide Show (S9) Version: #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
if opts.generate?
create_slideshow_templates
else
+ check_markdown_libs
+
args.each { |fn| create_slideshow( fn ) }
end
end
end # class Gen
\ No newline at end of file