Class: SnapUrl::Application
- Inherits:
-
Object
- Object
- SnapUrl::Application
- Defined in:
- lib/core/application.rb
Class Method Summary collapse
-
.parse(args) ⇒ Object
TODO: add option to control log-level TODO: add implementation for verbose run TODO: set –include-format = true if more than one format.
- .run(args) ⇒ Object
Class Method Details
.parse(args) ⇒ Object
TODO: add option to control log-level TODO: add implementation for verbose run TODO: set –include-format = true if more than one format
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/core/application.rb', line 20 def Application::parse(args) = Camera::DEFAULT_OPTIONS begin opts = OptionParser.new do |opts| opts. = <<-EOF Usage: #{opts.program_name} url0 [url1] [url2]... [options] #{opts.program_name} is a command line tool that creates PNG screenshots of webpages. With tall or wide pages that would normally require scrolling, it takes screenshots of the whole webpage, not just the area that would be visible in a browser window. It is a Ruby/RubyCocoa port of the webkit2png.py script by Paul Hammond (http://www.paulhammond.org/webkit2png/) EOF opts..gsub!(/ /, '') opts.separator ' ' opts.separator 'Specific Options:' opts.on('--width [WIDTH]', Float, "initial and minimum browser width (default: #{[:browser][:width].to_i})") { |n| [:browser][:width] = n } opts.on('--height [HEIGHT]', Float, "initial and minimum browser height (default: #{[:browser][:height].to_i})") { |n| [:browser][:height] = n } opts.separator ' ' opts.on('--[no-]fullsize', "create fullsize screenshot") { |n| n ? [:snapFormat] << :fullsize : [:snapFormat].delete(:fullsize) } opts.on('--[no-]thumbnail', "create thumbnail") { |n| n ? [:snapFormat] << :thumbnail : [:snapFormat].delete(:thumbnail) } opts.on('--[no-]clip', "create clip of thumbnail") { |n| n ? [:snapFormat] << :clip : [:snapFormat].delete(:clip) } opts.separator ' ' opts.on('--scale [SCALE]', Float, "scale factor for thumbnails (default: #{[:scaleFactor]})") { |n| [:scaleFactor] = n } opts.separator ' ' opts.on('--clipwidth [WIDTH]', Float, "width of clipped thumbnail (default: #{[:clip][:width].to_i})") { |n| [:clip][:width] = n } opts.on('--clipheight [HEIGHT]', Float, "height of clipped thumbnail (default: #{[:clip][:height].to_i})") { |n| [:clip][:height] = n } opts.separator ' ' opts.on('-f', '--filename [NAME]', "use NAME as part of filename (derived from url if not specified)") { |n| [:filename] = n } opts.on('--use-md5hash', "use md5 hash for filename (overriden by --filename)") { |n| [:useHashForFilename?] = n } opts.on('--include-datestamp', "include date in filename") { |n| [:datestampInFilename?] = n } opts.on('--include-timestamp', "include time in filename") { |n| [:timestampInFilename?] = n } opts.on('--include-size', "include image size in filename") { |n| [:sizeInFilename?] = n } opts.on('--include-format', "include image format in filename") { |n| [:snapFormatInFilename?] = n } opts.separator ' ' opts.on('-d', '--output-dir [DIRNAME]', "directory to place images into (default: #{[:outputDirectory]})") { |n| [:outputDirectory] = n } opts.separator ' ' opts.separator 'Common Options:' opts.on('-v', "--[no-]verbose", "Run verbosely") { |n| [:verbose?] = n } opts.on_tail("-h", "--help", "Show this message") do puts opts.help exit end opts.on_tail("--version", "Show version") do puts opts.ver exit end end urls = opts.permute!(args) raise OptionParser::MissingArgument.new('you need to supply at least one URL') if urls.empty? raise OptionParser::InvalidArgument.new('you can only use the filename option if there is only one URL') if (urls.size > 1) && ![:filename].empty? raise OptionParser::InvalidArgument.new('scale cannot be zero') if [:scaleFactor] < 0.0 # width and height cannot be zero or less than minimum # clipwidth and clipheight cannot be zero or less than minimum raise OptionParser::AmbiguousArgument.new('you need to allow at least one format') if [:snapFormat].empty? return { :urls => urls, :options => } rescue OptionParser::ParseError => e puts "#{e..capitalize}" exit(1) end end |
.run(args) ⇒ Object
12 13 14 15 |
# File 'lib/core/application.rb', line 12 def Application::run(args) config = Application.parse(args) Camera::snap(config[:urls], config[:options]) end |