websnapshot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2011-04-12
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,19 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/websnapshot
7
+ dependencies.memo.text
8
+ lib/websnapshot.rb
9
+ lib/websnapshot/cli.rb
10
+ script/console
11
+ script/destroy
12
+ script/generate
13
+ spec/spec.opts
14
+ spec/spec_helper.rb
15
+ spec/websnapshot_spec.rb
16
+ tasks/rspec.rake
17
+ test/test_helper.rb
18
+ test/test_websnapshot.rb
19
+ test/test_websnapshot_cli.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on websnapshot, see http://websnapshot.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = websnapshot
2
+
3
+ * http://github.com/#{github_username}/#{project_name}
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2011 FIXME full name
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/websnapshot'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'websnapshot' do
14
+ self.developer 'Takashi Oguma', 'bear.mini@gmail.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ self.extra_deps = [['gtk2','>= 0.90.8']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
data/bin/websnapshot ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2011-4-16.
4
+ # Copyright (c) 2011. All rights reserved.
5
+
6
+ require 'rubygems'
7
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/websnapshot")
8
+ require "websnapshot/cli"
9
+
10
+ Websnapshot::CLI.execute(STDOUT, ARGV)
@@ -0,0 +1,10 @@
1
+
2
+ = Install Prerequisite Packages
3
+
4
+ Ubuntu:
5
+ $ sudo apt-get install ruby-gnome2-dev webkit-1.0 libgtk2.0-dev
6
+ # atk1.0 libcairo2-dev
7
+
8
+ Mac OS X:
9
+ $ sudo port install rb-gnome webkit-gtk
10
+
@@ -0,0 +1,55 @@
1
+ require 'optparse'
2
+ require 'lib/websnapshot.rb'
3
+
4
+ module Websnapshot
5
+ unless defined? Websnapshot::CLI
6
+
7
+ class CLI
8
+ def self.execute(stdout, arguments=[])
9
+
10
+ options = {
11
+ :max_width => 960,
12
+ :max_height => 640,
13
+ }
14
+ mandatory_options = %w( )
15
+
16
+ parser = OptionParser.new do |opts|
17
+ opts.banner = <<-BANNER.gsub(/^ /,'')
18
+ This is an application to capture snapshot images of web pages.
19
+
20
+ Usage: #{File.basename($0)} [options] [URL]...
21
+
22
+ Options are:
23
+ BANNER
24
+ opts.separator ""
25
+ opts.on("-x", "--max-width WIDTH", Integer,
26
+ "Maximum width (in pixels) of an artifact image.",
27
+ "If the page you want to take an snapshot image has ",
28
+ "width less than the specified value, the original size",
29
+ "will be preserved.",
30
+ "Default: 960") { |arg| options[:max_width] = arg }
31
+ opts.on("-y", "--max-height HEIGHT", Integer,
32
+ "Maximum height (in pixels) of an artifact image.",
33
+ "If the page you want to take an snapshot image has ",
34
+ "height less than the specified value, the original size",
35
+ "will be preserved.",
36
+ "Default: 640") { |arg| options[:max_height] = arg }
37
+ opts.on("-h", "--help",
38
+ "Show this help message.") { stdout.puts opts; exit }
39
+ opts.on("-v", "--version",
40
+ "Show the version number of this application.") { stdout.puts Websnapshot::VERSION; exit }
41
+ opts.parse!(arguments)
42
+
43
+ if (mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }) || arguments.length == 0
44
+ stdout.puts opts; exit
45
+ end
46
+ end
47
+
48
+ # do stuff
49
+ arguments.each do |url|
50
+ Websnapshot::take(url, options)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/ruby
2
+ # vim: set ts=2 sts=2 sw=2 tw=0 ff=unix expandtab :
3
+
4
+ unless defined? Websnapshot
5
+
6
+ require 'gtk2'
7
+ require 'webkit' # https://github.com/danlucraft/rbwebkitgtk
8
+
9
+
10
+ module Websnapshot
11
+ VERSION = '0.0.1'
12
+
13
+ def self.take(url, options = {})
14
+ saved_filename = nil
15
+
16
+ w = Gtk::Window.new
17
+ w.signal_connect('destroy') do |*args|
18
+ Gtk.main_quit
19
+ end
20
+
21
+ v = Gtk::WebKit::WebView.new
22
+ v.open(url)
23
+
24
+ # load-finished is deprecated. We should use notify::load-status
25
+ v.signal_connect('load-finished') do |instance, *signal_related_args|
26
+ begin
27
+ options[:max_width] ||= 960
28
+ options[:max_height] ||= 640
29
+ options[:output_filename] ||= 'snapshot.png'
30
+ options[:output_format] ||= 'png'
31
+
32
+ saved_filename = save_viewport(instance.parent_window, options)
33
+ rescue
34
+ puts $!
35
+ puts $@
36
+ ensure
37
+ Gtk.main_quit
38
+ end
39
+ end
40
+
41
+ v.signal_connect('notify::load-status') do |instance, *signal_related_args|
42
+ #puts 'notify::load-status ' + v.load_status.to_s
43
+ end
44
+
45
+ w.add(v)
46
+ w.show_all
47
+
48
+ Gtk.main
49
+
50
+ saved_filename
51
+ end
52
+
53
+ private
54
+
55
+ def self.save_viewport(gdk_window, options)
56
+ win = gdk_window
57
+ win.raise
58
+ win.focus(0)
59
+ win.resize(options[:max_width], options[:max_height])
60
+ win.freeze_updates
61
+ x, y, w, h = win.geometry
62
+ pixbuf = Gdk::Pixbuf.from_drawable(nil, win, 0, 0, [options[:max_width], w].min, [options[:max_height], h].min)
63
+ pixbuf.save(options[:output_filename], options[:output_format])
64
+ return options[:output_filename]
65
+ end
66
+
67
+ end
68
+ end
69
+
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/websnapshot.rb'}"
9
+ puts "Loading websnapshot gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'rspec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'rspec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'websnapshot'
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ def tidy(fname)
4
+ File.unlink(fname)
5
+ end
6
+
7
+ def image_size(fname)
8
+ %x{file #{fname}} =~ /([0-9]+ x [0-9]+)/
9
+ return $1
10
+ end
11
+
12
+
13
+ describe Websnapshot do
14
+ describe 'take' do
15
+ it 'returns a saved file name in relative form' do
16
+ fname = Websnapshot.take('spec/testpage_960x640.html')
17
+ fname.should == 'snapshot.png'
18
+ tidy fname
19
+ end
20
+
21
+ context 'only a URL is specified' do
22
+ context 'the URL is point to a local file' do
23
+ it "saves 960x640 snapshot.png for 960x640 page without any options" do
24
+ fname = Websnapshot.take('spec/testpage_960x640.html')
25
+ fname.should == 'snapshot.png'
26
+ image_size(fname).should == '960 x 640'
27
+ tidy fname
28
+ end
29
+ end
30
+
31
+ context 'the URL is point to a remote file (http)' do
32
+ end
33
+
34
+ context 'the URL is point to a remote file (https)' do
35
+ end
36
+ end
37
+
38
+ context 'a URL and size options are specified' do
39
+ end
40
+
41
+ context 'a specified URL cannot be loaded' do
42
+ end
43
+ end
44
+
45
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'rspec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'rspec'
6
+ end
7
+ begin
8
+ require 'rspec/core/rake_task'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ RSpec::Core::RakeTask.new(:spec) do |t|
19
+ t.rspec_opts = ['--options', "spec/spec.opts"]
20
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/websnapshot'
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestWebsnapshot < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_take
9
+ # without options
10
+ Websnapshot.take('http://google.co.jp')
11
+ assert_image('screenshot.png', 960, 640, 'png')
12
+
13
+ Websnapshot.take('testpage_128x128.html')
14
+ assert_image('screenshot.png', 128, 128, 'png')
15
+
16
+ Websnapshot.take('testpage_1280x720.html')
17
+ assert_image('screenshot.png', 960, 640, 'png')
18
+
19
+ # with max_width option
20
+ Websnapshot.take('testpage_960x640.html', :max_width => 320)
21
+ assert_image('screenshot.png', 320, 640, 'png')
22
+
23
+ Websnapshot.take('testpage_128x128.html', :max_width => 320)
24
+ assert_image('screenshot.png', 128, 128, 'png')
25
+
26
+ Websnapshot.take('testpage_1280x720.html', :max_width => 320)
27
+ assert_image('screenshot.png', 320, 640, 'png')
28
+
29
+ # with max_height option
30
+ Websnapshot.take('testpage_960x640.html', :max_height => 240)
31
+ assert_image('screenshot.png', 960, 240, 'png')
32
+
33
+ Websnapshot.take('testpage_128x128.html', :max_height => 240)
34
+ assert_image('screenshot.png', 128, 128, 'png')
35
+
36
+ Websnapshot.take('testpage_1280x720.html', :max_height => 240)
37
+ assert_image('screenshot.png', 960, 240, 'png')
38
+
39
+ # with max_width and max_height options
40
+
41
+ # with output_filename option
42
+
43
+ # with output_format option
44
+ end
45
+
46
+ def assert_image(filename, expected_width, expected_height, expected_image_format)
47
+ end
48
+
49
+ end
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
+ require 'websnapshot/cli'
3
+
4
+ class TestWebsnapshotCli < Test::Unit::TestCase
5
+ def setup
6
+ Websnapshot::CLI.execute(@stdout_io = StringIO.new, [])
7
+ @stdout_io.rewind
8
+ @stdout = @stdout_io.read
9
+ end
10
+
11
+ def test_print_default_output
12
+ assert_match(/To update this executable/, @stdout)
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: websnapshot
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Takashi Oguma
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-04 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: gtk2
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 359
29
+ segments:
30
+ - 0
31
+ - 90
32
+ - 8
33
+ version: 0.90.8
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: hoe
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 35
45
+ segments:
46
+ - 2
47
+ - 9
48
+ - 4
49
+ version: 2.9.4
50
+ type: :development
51
+ version_requirements: *id002
52
+ description: FIX (describe your package)
53
+ email:
54
+ - bear.mini@gmail.com
55
+ executables:
56
+ - websnapshot
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - History.txt
61
+ - Manifest.txt
62
+ - PostInstall.txt
63
+ files:
64
+ - History.txt
65
+ - Manifest.txt
66
+ - PostInstall.txt
67
+ - README.rdoc
68
+ - Rakefile
69
+ - bin/websnapshot
70
+ - dependencies.memo.text
71
+ - lib/websnapshot.rb
72
+ - lib/websnapshot/cli.rb
73
+ - script/console
74
+ - script/destroy
75
+ - script/generate
76
+ - spec/spec.opts
77
+ - spec/spec_helper.rb
78
+ - spec/websnapshot_spec.rb
79
+ - tasks/rspec.rake
80
+ - test/test_helper.rb
81
+ - test/test_websnapshot.rb
82
+ - test/test_websnapshot_cli.rb
83
+ - .gemtest
84
+ homepage: http://github.com/#{github_username}/#{project_name}
85
+ licenses: []
86
+
87
+ post_install_message: PostInstall.txt
88
+ rdoc_options:
89
+ - --main
90
+ - README.rdoc
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project: websnapshot
114
+ rubygems_version: 1.7.2
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: FIX (describe your package)
118
+ test_files:
119
+ - test/test_helper.rb
120
+ - test/test_websnapshot.rb
121
+ - test/test_websnapshot_cli.rb