lib/slideshow.rb in slideshow-0.7.1 vs lib/slideshow.rb in slideshow-0.7.2

- old
+ new

@@ -1,5 +1,7 @@ +$KCODE="U" + require 'optparse' require 'erb' require 'redcloth' require 'maruku' require 'logger' @@ -10,11 +12,11 @@ require 'pp' module Slideshow - VERSION = '0.7.1' + VERSION = '0.7.2' class Params def initialize( name, headers ) @name = name @@ -107,10 +109,14 @@ end def manifest get( 'manifest', 's6.txt' ) end + + def output_path + get( 'output', '.' ) + end DEFAULTS = { :title => 'Untitled Slide Show', :footer => '', @@ -262,33 +268,37 @@ end # fallback load builtin template packaged with gem load_builtin_template( builtin ) end - - def load_builtin_template_old_delete( name ) - templatesdir = "#{File.dirname(__FILE__)}/templates" - logger.debug "templatesdir=#{templatesdir}" - - File.read( "#{templatesdir}/#{name}" ) - end + def with_output_path( dest, output_path ) + dest_full = File.expand_path( dest, output_path ) + logger.debug "dest_full=#{dest_full}" + + # make sure dest path exists + dest_path = File.dirname( dest_full ) + logger.debug "dest_path=#{dest_path}" + File.makedirs( dest_path ) unless File.directory? dest_path + dest_full + end def create_slideshow_templates logger.debug "manifest=#{opts.manifest}.gen" manifest = load_manifest( opts.manifest+".gen" ) + # expand output path in current dir and make sure output path exists + outpath = File.expand_path( opts.output_path ) + logger.debug "outpath=#{outpath}" + File.makedirs( outpath ) unless File.directory? outpath + manifest.each do |entry| dest = entry[0] source = entry[1] - - # make sure dirs exist - logger.debug "makedirs( #{File.dirname(dest)} )" - File.makedirs( File.dirname(dest) ) - + puts "Copying to #{dest} from #{source}..." - File.copy( source, dest ) + File.copy( source, with_output_path( dest, outpath ) ) end puts "Done." end @@ -296,29 +306,36 @@ logger.debug "manifest=#{opts.manifest}" manifest = load_manifest( opts.manifest ) # pp manifest + # expand output path in current dir and make sure output path exists + outpath = File.expand_path( opts.output_path ) + logger.debug "outpath=#{outpath}" + File.makedirs( outpath ) unless File.directory? outpath + + dirname = File.dirname( fn ) basename = File.basename( fn, '.*' ) extname = File.extname( fn ) + logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}" known_extnames = KNOWN_TEXTILE_EXTNAMES + KNOWN_MARKDOWN_EXTNAMES if extname.empty? then extname = ".textile" # default to .textile known_extnames.each do |e| - logger.debug "File.exists? #{basename}#{e}" - if File.exists?( "#{basename}#{e}" ) then + logger.debug "File.exists? #{dirname}/#{basename}#{e}" + if File.exists?( "#{dirname}/#{basename}#{e}" ) then extname = e logger.debug "extname=#{extname}" break end end end - inname = "#{basename}#{extname}" + inname = "#{dirname}/#{basename}#{extname}" logger.debug "inname=#{inname}" content = File.read( inname ) @@ -435,11 +452,11 @@ outname = entry[0] if outname.include? '__file__' # process outname = outname.gsub( '__file__', basename ) puts "Preparing #{outname}..." - out = File.new( outname, "w+" ) + out = File.new( with_output_path( outname, outpath ), "w+" ) out << render_template( load_template( entry[1] ), params.params_binding ) if entry.size > 2 # more than one source file? assume header and footer with content added inbetween out << content2 @@ -450,17 +467,13 @@ out.close else # just copy verbatim if target/dest has no __file__ in name dest = entry[0] source = entry[1] - - # make sure dirs exist - logger.debug "makedirs( #{File.dirname(dest)} )" - File.makedirs( File.dirname(dest) ) - + puts "Copying to #{dest} from #{source}..." - File.copy( source, dest ) + File.copy( source, with_output_path( dest, outpath ) ) end end =begin @@ -496,10 +509,13 @@ cmd.on( '-f[OPTIONAL]', '--fullerscreen', 'FullerScreen Compatible Slide Show' ) { opts.put( 'fuller', true ); opts.put( 'manifest', 'fullerscreen.txt' ) } # opts.on( "-s", "--style STYLE", "Select Stylesheet" ) { |s| $options[:style]=s } # opts.on( "-v", "--version", "Show version" ) {} cmd.on( '-g', '--generate', 'Generate Slide Show Templates' ) { opts.put( 'generate', true ) } + + cmd.on( '-o', '--output PATH', 'outputs to Path' ) { |s| opts.put( 'output', s ) } + # use -d or -o to select output directory for slideshow or slideshow templates? # cmd.on( '-d', '--directory DIRECTORY', 'Output Directory' ) { |s| opts.put( 'directory', s ) } # cmd.on( '-i', '--include PATH', 'Load Path' ) { |s| opts.put( 'include', s ) } # todo: find different letter for debug trace switch (use v for version?) @@ -520,11 +536,12 @@ puts cmd.help puts puts "Examples:" puts " slideshow microformats" puts " slideshow microformats.textile" - puts " slideshow -s5 microformats # S5 compatible" - puts " slideshow -f microformats # FullerScreen compatible" + puts " slideshow -s5 microformats # S5 compatible" + puts " slideshow -f microformats # FullerScreen compatible" + puts " slideshow -o slides microformats # Output slideshow to slides folder" puts puts "More examles:" puts " slideshow -g # Generate slide show templates" puts " slideshow -g -s5 # Generate S5 compatible slide show templates" puts " slideshow -g -f # Generate FullerScreen compatible slide show templates" \ No newline at end of file