Class: SlideShowGenerator

Inherits:
Object
  • Object
show all
Extended by:
Logging
Includes:
Singleton
Defined in:
lib/html2slideshow.rb

Overview

The SlideShowGenerator class provides the main routine to start

the slideshow-generation.
Alternatively a commandline parameter -g or --generic can be
used to write a generic configuration file, which can be used
to alter the program output in later runs of the generator.
See Argparser for details on commandline parameters.

Constant Summary collapse

@@log =
self::init_logger()

Instance Method Summary collapse

Methods included from Logging

init_logger, log_level=, log_target=

Methods included from File_Checking

file_check, #file_check, last_mime_type, magic_check, mime_check

Constructor Details

#initializeSlideShowGenerator

Returns a new instance of SlideShowGenerator.



48
49
50
# File 'lib/html2slideshow.rb', line 48

def initialize
  @log = @@log
end

Instance Method Details

#generate(args) ⇒ Object

The original console-version works with this method



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/html2slideshow.rb', line 53

def generate(args)
  message = nil
  options = ArgParser.parse(args)
  @log.level = Logger::INFO  if !options.debug
  @log.debug('Log-level is ' << @log.level.to_s)
  
  @log.debug("options are " + options.to_s) 
  unless options.generic
    pwd = Dir.pwd()
    if(options.source && !options.source.empty?)
      message = File_Checking.file_check(options.source, [:exist?, :readable?, :writable?, :directory?])
      if(message)
        message = sprintf( trl("Source-directory") << ": %s" , message)
      else
        Dir.chdir(options.source)

        if('files' == options.source_type)      
          read_dir(options)
        else
          read_html(options)
        end
        Dir.chdir(pwd)
      end
    else
      message = trl('No source-directory given!')
    end
  else
    message = Configurator.write_configuration(options.generic)
  end
  message if message
end

#read_dir(options) ⇒ Object

read from DIR



86
87
88
89
90
91
92
93
94
95
# File 'lib/html2slideshow.rb', line 86

def read_dir(options) 
  @log.debug('reading files from souce-directory') 
  if(!options.formats || options.formats.empty?)
    options.formats = %w[jpg JPG jpeg JPEG webp]
    @log.debug("no image types chosen, looking for JPEGs and WebP") 
  end
  @log.debug('working on directory ' + Dir.pwd) 
  source = SourceFile.new(Dir.pwd, options)
  HtmlBuilder.new(source, options)
end

#read_html(options) ⇒ Object

read from html



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/html2slideshow.rb', line 98

def read_html(options) 
  @log.debug('reading references from html') 
  htmlfiles = Dir.glob("{*.htm,*.html}") 
  if(htmlfiles && !htmlfiles.empty?)
    htmlfiles.each do |sf|
      @log.debug('working on file ' + sf) 
      source = SourceFile.new(sf, options)
      HtmlBuilder.new(source, options)
    end
  else 
    @log.error("NO source-files in %s! Check source-directory!" %options.source)
  end
end

#runObject

main routine.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/html2slideshow.rb', line 113

def run()

  message = generate(ARGV)
  if message
    @log.error message
    @log.debug('returning nil') 
    nil
  else 
    msg = trl('DONE')
    puts "-" * msg.length << "\n" << msg
    @log.debug('returning true') 
    true
  end
end