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?( '