require 'tempfile' module RDvdSlideshow # # A SlideshowInput is responsible for building the input file used by dvd-slideshow. # class SlideshowInput # # Initializes the file path and write the content of the file. # If no file path is given, a temp file is used (Tempfile). # The provided block is used to build the content of the file. # The file is flushed after writing. # def initialize(file_path=nil,&block) @file = file_path ? File.new(file_path,'w') : Tempfile.new('slideshow_input') block.call(self) if block @file.flush end # Path to the path where slideshow input configuration is written def file_path @file.path end # # Adds a new image # def image(path,duration,options={}) write_line(path,duration,options,[:subtitle,:effect,:effect_params]) end # # Adds a title # def title(duration,text) write_line("title",duration,{:text=>text},[:text]) end # # Adds a title bar # Possible options are : _upper\_title_ and _lower\_title_ # def titlebar(duration,options={}) write_line("titlebar",duration,options,[:upper_title,:lower_title]) end # # Adds a music # Possible options are : _subtitle_ # def musictitle(duration,options={}) write_line("musictitle",duration,options,[:subtitle]) end def fadein(duration,options={}) write_line("fadein",duration,options,[:subtitle]) end def fadeout(duration,options={}) write_line("fadeout",duration,options,[:subtitle]) end # # Adds an exit command # def exit @file.puts "exit" end protected def separator ':' end def write_line(keyword,duration,options={},sorted_keys=[]) @file.puts build_line(keyword,duration,options,sorted_keys) end def build_line(keyword,duration,options={},sorted_keys=[]) line = keyword + separator + format_duration(duration) index = 0 remaining_options = options.values.length while remaining_options > 0 line << separator value = options[sorted_keys[index]] line << (value || "") index += 1 remaining_options -= 1 if value end return line end def format_duration(duration) "%.3f" % duration.to_f end end end