require 'optparse' require 'erb' require 'RedCloth' require 'BlueCloth' require 'logger' module Slideshow class Params def initialize( title, name ) @title = title @svgname = "#{name}.svg" @cssname = "#{name}.css" end def params_binding binding end end def Slideshow.load_template( name ) templatesdir = "#{File.dirname(__FILE__)}/templates" logger.debug "templatesdir=#{templatesdir}" File.read( "#{templatesdir}/#{name}" ) end def Slideshow.render_template( content, b=TOPLEVEL_BINDING ) ERB.new( content ).result( b ) end def Slideshow.create_slideshow( fn ) headerdoc = load_template( 'header.html.erb' ) footerdoc = load_template( 'footer.html.erb' ) styledoc = load_template( 'style.css.erb' ) gradientdoc = load_template( 'gradient.svg.erb' ) basename = File.basename( fn, '.*' ) extname = File.extname( fn ) params = Params.new( "Slideshow", basename ) known_textile_extnames = [ '.textile', '.t' ] known_markdown_extnames = [ '.markdown', '.mark', '.m', '.txt', '.text' ] known_extnames = known_textile_extnames + known_markdown_extnames if extname.eql?("") then extname = ".textile" # default to .textile known_extnames.each { |e| logger.debug "File.exists? #{basename}#{e}" if File.exists?( "#{basename}#{e}" ) then extname = e logger.debug "extname=#{extname}" break end } end inname = "#{basename}#{extname}" outname = "#{basename}.html" svgname = "#{basename}.svg" cssname = "#{basename}.css" logger.debug "inname=#{inname}" puts "Preparing slideshow stylesheet '#{cssname}'..." out = File.new( cssname, "w+" ) out << render_template( styledoc, params.params_binding ) out.flush out.close puts "Preparing slideshow theme '#{svgname}'..." out = File.new( svgname, "w+" ) out << render_template( gradientdoc, params.params_binding ) out.flush out.close puts "Preparing slideshow '#{outname}'..." # convert light-weight markup to hypertext content = File.read( inname ) if known_markdown_extnames.include?( extname ) content = BlueCloth.new( content ).to_html else content = RedCloth.new( content ).to_html end # post-processing slide_counter = 0 content2 = '' # wrap h1's in slide divs content.each_line { |line| if line.include?( '

' ) then content2 << "\n\n" if slide_counter > 0 content2 << "
\n\n" slide_counter += 1 end content2 << line } content2 << "\n\n
" if slide_counter > 0 out = File.new( outname, "w+" ) out << render_template( headerdoc, params.params_binding ) out << content2 out << render_template( footerdoc, params.params_binding ) out.flush out.close puts "Done." end def Slideshow.logger if @@logger.nil? @@logger = Logger.new(STDOUT) end @@logger end def Slideshow.main @@logger = nil $options = {} logger.level = Logger::INFO opt=OptionParser.new do |opts| opts.banner = "Usage: slideshow [options] name" # opts.on( "-s", "--style STYLE", "Select Stylesheet" ) { |s| $options[:style]=s } # opts.on( "-v", "--version", "Show version" ) {} opts.on( "-t", "--trace", "Show debug trace" ) { logger.datetime_format = "%H:%H:%S" logger.level = Logger::DEBUG } opts.on_tail( "-h", "--help", "Show this message" ) { puts puts "Slide Show (S9) is a free web alternative to PowerPoint or KeyNote in Ruby" puts puts opts.help puts puts "Examples:" puts " slideshow microformats" puts " slideshow microformats.textile" puts puts "Further information:" puts " http://slideshow.rubyforge.org" exit } end opt.parse! puts "Slide Show (S9) Version: 0.3 on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]" ARGV.each { |fn| Slideshow.create_slideshow( fn ) } end end