Module: Websnapshot

Defined in:
lib/websnapshot.rb,
lib/websnapshot/cli.rb

Defined Under Namespace

Classes: CLI

Constant Summary collapse

VERSION =
'0.0.3'

Class Method Summary collapse

Class Method Details

.take(url, options = {}) ⇒ Object



13
14
15
16
17
18
19
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
# File 'lib/websnapshot.rb', line 13

def self.take(url, options = {})
  saved_filename = nil

  w = Gtk::Window.new
  w.signal_connect('destroy') do |*args|
    Gtk.main_quit
  end

  v = Gtk::WebKit::WebView.new
  v.open(url)

  # load-finished is deprecated. We should use notify::load-status
  v.signal_connect('load-finished') do |instance, *signal_related_args|
    begin
      options[:max_width] ||= 960
      options[:max_height] ||= 640
      options[:output_filename] ||= 'snapshot.png'
      options[:output_format] ||= 'png'

      saved_filename = save_viewport(instance.parent_window, options)
    rescue
      puts $!
      puts $@
    ensure
      Gtk.main_quit
    end
  end

  v.signal_connect('notify::load-status') do |instance, *signal_related_args|
    #puts 'notify::load-status ' + v.load_status.to_s
  end

  w.add(v)
  w.show_all

  Gtk.main

  saved_filename
end