Class: Slideshow::Runner
- Inherits:
-
Object
- Object
- Slideshow::Runner
- Includes:
- PluginHelper
- Defined in:
- lib/slideshow/cli/runner.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #find_file_with_known_extension(fn) ⇒ Object
- #find_files(file_or_dir_or_pattern) ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #run(args) ⇒ Object
Methods included from PluginHelper
#find_plugin_patterns, #find_plugins, #load_plugins
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 |
# File 'lib/slideshow/cli/runner.rb', line 7 def initialize @logger = Logger.new(STDOUT) @logger.level = Logger::INFO @opts = Opts.new @config = Config.new( @logger, @opts ) @headers = Headers.new( @config ) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/slideshow/cli/runner.rb', line 16 def config @config end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
16 17 18 |
# File 'lib/slideshow/cli/runner.rb', line 16 def headers @headers end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
16 17 18 |
# File 'lib/slideshow/cli/runner.rb', line 16 def logger @logger end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
16 17 18 |
# File 'lib/slideshow/cli/runner.rb', line 16 def opts @opts end |
Instance Method Details
#find_file_with_known_extension(fn) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/slideshow/cli/runner.rb', line 19 def find_file_with_known_extension( fn ) dirname = File.dirname( fn ) basename = File.basename( fn, '.*' ) extname = File.extname( fn ) logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}" config.known_extnames.each do |e| newname = File.join( dirname, "#{basename}#{e}" ) logger.debug "File.exists? #{newname}" return newname if File.exists?( newname ) end # each extension (e) nil # not found; return nil end |
#find_files(file_or_dir_or_pattern) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/slideshow/cli/runner.rb', line 35 def find_files( file_or_dir_or_pattern ) filtered_files = [] ## for now process/assume only single file ## (check for missing extension) if File.exists?( file_or_dir_or_pattern ) file = file_or_dir_or_pattern logger.debug " adding file '#{file}'..." filtered_files << file else # check for existing file w/ missing extension file = find_file_with_known_extension( file_or_dir_or_pattern ) if file.nil? puts " skipping missing file '#{file_or_dir_or_pattern}{#{config.known_extnames.join(',')}}'..." else logger.debug " adding file '#{file}'..." filtered_files << file end end filtered_files end |
#run(args) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/slideshow/cli/runner.rb', line 60 def run( args ) config.load opt=OptionParser.new do |cmd| cmd. = "Usage: slideshow [options] name" cmd.on( '-o', '--output PATH', "Output Path (default is #{opts.output_path})" ) { |path| opts.output_path = path } cmd.on( "-t", "--template MANIFEST", "Template Manifest (default is #{opts.manifest})" ) do |t| # todo: do some checks on passed in template argument opts.manifest = t end # cmd.on( '--header NUM', 'Header Level (default is 1)' ) do |n| # opts.header_level = n.to_i # end cmd.on( '--h1', 'Set Header Level to 1 (default)' ) { opts.header_level = 1 } cmd.on( '--h2', 'Set Header Level to 2' ) { opts.header_level = 2 } cmd.on( '--slide', 'Use only !SLIDE for slide breaks (Showoff Compatible)' ) do opts. = true end cmd.on( '--takahashi', 'Allow // for slide breaks' ) do opts.takahashi = true end # ?? opts.on( "-s", "--style STYLE", "Select Stylesheet" ) { |s| $options[:style]=s } # ?? cmd.on( '-i', '--include PATH', 'Load Path' ) { |s| opts.put( 'include', s ) } cmd.on( '-f', '--fetch URI', 'Fetch Templates' ) do |uri| opts.fetch_uri = uri end cmd.on( '--all', "Fetch Template Packs (#{config.default_fetch_shortcuts.keys.join(', ')})" ) do opts.fetch_all = true end cmd.on( '-l', '--list', 'List Installed Templates' ) { opts.list = true } cmd.on( '-c', '--config PATH', "Configuration Path (default is #{opts.config_path})" ) do |path| opts.config_path = path end cmd.on( '-g', '--generate', 'Generate Slide Show Templates (using built-in S6 Pack)' ) { opts.generate = true } ## fix:/todo: add generator for quickstart cmd.on( '-q', '--quick [MANIFEST]', "Generate Quickstart Slide Show Sample (default is #{opts.quick_manifest})") do |q| opts.quick = true opts.quick_manifest = q if q.nil? == false end cmd.on( '-v', '--version', "Show version" ) do puts Slideshow.generator exit end cmd.on( "-h", "--help", "Show this message" ) do puts " \nSlide Show (S9) is a free web alternative to PowerPoint or KeyNote in Ruby\n\n\#{cmd.help}\n\nExamples:\n slideshow microformats\n slideshow microformats.text # Process slides using Markdown (\#{config.known_markdown_extnames.join(', ')})\n slideshow microformats.textile # Process slides using Textile (\#{config.known_textile_extnames.join(', ')})\n slideshow microformats.rst # Process slides using reStructuredText (\#{config.known_rest_extnames.join(', ')})\n slideshow -o slides microformats # Output slideshow to slides folder\n\nMore examles:\n slideshow -q # Generate quickstart slide show sample\n slideshow -g # Generate slide show templates using built-in S6 pack\n\n slideshow -l # List installed slide show templates\n slideshow -f s5blank # Fetch (install) S5 blank starter template from internet\n slideshow -t s5blank microformats # Use your own slide show templates (e.g. s5blank)\n\nFurther information:\n http://slideshow.rubyforge.org\n \n" exit end cmd.on( '-p', '--plugins', '(Debug) List Plugin Scripts in Load Path' ) { opts.plugins = true } cmd.on( '--about', "(Debug) Show more version info" ) do puts "\n\#{Slideshow.generator}\n\nGems versions:\n - pakman \#{Pakman::VERSION}\n - fetcher \#{Fetcher::VERSION}\n - markdown \#{Markdown::VERSION}\n - textutils \#{TextUtils::VERSION}\n - props \#{Props::VERSION}\n\n Env home: \#{Env.home}\nSlideshow config: \#{config.config_dir}\n Slideshow cache: \#{config.cache_dir}\n Slideshow root: \#{Slideshow.root}\n\n" # dump Slideshow settings config.dump puts # dump Markdown settings Markdown.dump puts # todo: # add verison for rubygems ## todo: add more gem version info #- redcloth #- kramdown exit end cmd.on( "--verbose", "(Debug) Show debug trace" ) do logger.datetime_format = "%H:%H:%S" logger.level = Logger::DEBUG end end opt.parse!( args ) puts Slideshow.generator if logger.level == Logger::DEBUG # dump Slideshow settings config.dump puts # dump Markdown settings Markdown.dump puts end if opts.list? List.new( logger, opts, config ).run ### todo: remove opts (merge access into config) elsif opts.plugins? Plugins.new( logger, opts, config ).run ### todo: remove opts (merge access into config) elsif opts.generate? GenTemplates.new( logger, opts, config ).run ### todo: remove opts elsif opts.quick? Quick.new( logger, opts, config ).run ### todo: remove opts elsif opts.fetch? || opts.fetch_all? Fetch.new( logger, opts, config ).run ### todo: remove opts else load_plugins # check for optional plugins/extension in ./lib folder args.each do |arg| files = find_files( arg ) files.each do |file| ### fix/todo: reset/clean headers Gen.new( logger, opts, config, headers ).( file ) end end end end |