websnap 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,7 +20,7 @@ Create snapshot of webpage. Uses [wkhtmltoimage](http://github.com/antialize/wkh
20
20
 
21
21
  # WebSnap.new takes the HTML and any options for wkhtmltoimage
22
22
  # run `wkhtmltoimage -H` for a full list of options
23
- snap = WebSnap.new('http://google.com', :format => 'png')
23
+ snap = WebSnap::Snapper.new('http://google.com', :format => 'png')
24
24
 
25
25
  # Get the binary image data
26
26
  png = snap.to_bytes
@@ -29,8 +29,8 @@ Create snapshot of webpage. Uses [wkhtmltoimage](http://github.com/antialize/wkh
29
29
  file = snap.to_file('/path/to/save/png')
30
30
 
31
31
  # WebSnap.new can optionally accept a URL or a File.
32
- kit = WebSnap.new('http://google.com')
33
- kit = WebSnap.new(File.new('/path/to/html'))
32
+ kit = WebSnap::Snapper.new('http://google.com')
33
+ kit = WebSnap::Snapper.new(File.new('/path/to/html'))
34
34
 
35
35
  ## Attributions
36
36
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'echoe'
4
4
  require 'rake'
5
5
  require 'rspec/core/rake_task'
6
6
 
7
- Echoe.new("websnap", "0.1.3") do |p|
7
+ Echoe.new("websnap", "0.1.4") do |p|
8
8
  p.author = "Francis Chong"
9
9
  p.description = "Create snapshot of webpage"
10
10
  p.url = "http://github.com/siuying/websnap"
@@ -22,10 +22,6 @@ module WebSnap
22
22
  @stylesheets = []
23
23
 
24
24
  default_options = {
25
- :'crop-h' => '768',
26
- :'crop-w' => '1024',
27
- :'crop-x' => '0',
28
- :'crop-y' => '0',
29
25
  :'format' => 'jpg'
30
26
  }
31
27
  @options = normalize_options(default_options.merge(options))
@@ -56,10 +52,30 @@ module WebSnap
56
52
  return result
57
53
  end
58
54
 
59
- def to_file(path)
55
+ def to_file(path, image_path=nil)
56
+ append_stylesheets
57
+ path = File.expand_path(path)
58
+
59
+ @source = Source.new(@source.to_s.gsub(/images\//, image_path)) unless image_path.nil?
60
60
  File.open(path,'w') {|file| file << self.to_bytes}
61
61
  end
62
62
 
63
+ def append_stylesheets
64
+ raise ImproperSourceError.new('Stylesheets may only be added to an HTML source') if stylesheets.any? && !@source.html?
65
+
66
+ stylesheets.each do |stylesheet|
67
+ if @source.to_s.match(/<\/head>/)
68
+ @source = Source.new(@source.to_s.gsub(/(<\/head>)/, style_tag_for(stylesheet)+'\1'))
69
+ else
70
+ @source.to_s.insert(0, style_tag_for(stylesheet))
71
+ end
72
+ end
73
+ end
74
+
75
+ def style_tag_for(stylesheet)
76
+ "<style>#{File.read(stylesheet)}</style>"
77
+ end
78
+
63
79
  protected
64
80
 
65
81
  def wkhtmltoimage
@@ -4,5 +4,5 @@ $LOAD_PATH.unshift(File.join(SPEC_ROOT, '..', 'lib'))
4
4
 
5
5
  require 'websnap'
6
6
  require 'rubygems'
7
- require 'spec/rake/spectask'
7
+ require 'rspec/core/rake_task'
8
8
  require 'mocha'
@@ -29,7 +29,7 @@ describe WebSnap::Snapper do
29
29
 
30
30
  it "should provide default options" do
31
31
  websnap = WebSnap::Snapper.new('<h1>Oh Hai</h1>')
32
- ['--crop-w', '--crop-h', '--scale-w', '--scale-h', '--format'].each do |option|
32
+ ['--crop-w', '--crop-h', '--crop-x', '--crop-y', '--format'].each do |option|
33
33
  websnap.options.should have_key(option)
34
34
  end
35
35
  end
@@ -1,23 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{websnap}
5
- s.version = "0.1.3"
4
+ s.name = "websnap"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Francis Chong"]
9
- s.date = %q{2011-05-05}
10
- s.description = %q{Create snapshot of webpage}
11
- s.email = %q{}
9
+ s.date = "2011-11-24"
10
+ s.description = "Create snapshot of webpage"
11
+ s.email = ""
12
12
  s.executables = ["wkhtmltoimage-linux-i386-0.10.0", "wkhtmltoimage-osx-i386-0.10.0", "wkhtmltoimage-proxy"]
13
13
  s.extra_rdoc_files = ["LICENSE", "README.md", "bin/wkhtmltoimage-linux-i386-0.10.0", "bin/wkhtmltoimage-osx-i386-0.10.0", "bin/wkhtmltoimage-proxy", "lib/websnap.rb", "lib/websnap/source.rb", "lib/websnap/websnap.rb"]
14
14
  s.files = ["LICENSE", "Manifest", "README.md", "Rakefile", "bin/wkhtmltoimage-linux-i386-0.10.0", "bin/wkhtmltoimage-osx-i386-0.10.0", "bin/wkhtmltoimage-proxy", "lib/websnap.rb", "lib/websnap/source.rb", "lib/websnap/websnap.rb", "spec/fixtures/google.html", "spec/source_spec.rb", "spec/spec_helper.rb", "spec/websnap_spec.rb", "websnap.gemspec"]
15
- s.homepage = %q{http://github.com/siuying/websnap}
15
+ s.homepage = "http://github.com/siuying/websnap"
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Websnap", "--main", "README.md"]
17
17
  s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{websnap}
19
- s.rubygems_version = %q{1.6.2}
20
- s.summary = %q{Create snapshot of webpage}
18
+ s.rubyforge_project = "websnap"
19
+ s.rubygems_version = "1.8.10"
20
+ s.summary = "Create snapshot of webpage"
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  s.specification_version = 3
metadata CHANGED
@@ -1,74 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: websnap
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Francis Chong
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-05 00:00:00 +08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70282342064160 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: echoe
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70282342064160
25
+ - !ruby/object:Gem::Dependency
26
+ name: echoe
27
+ requirement: &70282342062620 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: mocha
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70282342062620
36
+ - !ruby/object:Gem::Dependency
37
+ name: mocha
38
+ requirement: &70282342083920 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
61
44
  type: :development
62
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *70282342083920
63
47
  description: Create snapshot of webpage
64
- email: ""
65
- executables:
48
+ email: ''
49
+ executables:
66
50
  - wkhtmltoimage-linux-i386-0.10.0
67
51
  - wkhtmltoimage-osx-i386-0.10.0
68
52
  - wkhtmltoimage-proxy
69
53
  extensions: []
70
-
71
- extra_rdoc_files:
54
+ extra_rdoc_files:
72
55
  - LICENSE
73
56
  - README.md
74
57
  - bin/wkhtmltoimage-linux-i386-0.10.0
@@ -77,7 +60,7 @@ extra_rdoc_files:
77
60
  - lib/websnap.rb
78
61
  - lib/websnap/source.rb
79
62
  - lib/websnap/websnap.rb
80
- files:
63
+ files:
81
64
  - LICENSE
82
65
  - Manifest
83
66
  - README.md
@@ -93,45 +76,34 @@ files:
93
76
  - spec/spec_helper.rb
94
77
  - spec/websnap_spec.rb
95
78
  - websnap.gemspec
96
- has_rdoc: true
97
79
  homepage: http://github.com/siuying/websnap
98
80
  licenses: []
99
-
100
81
  post_install_message:
101
- rdoc_options:
82
+ rdoc_options:
102
83
  - --line-numbers
103
84
  - --inline-source
104
85
  - --title
105
86
  - Websnap
106
87
  - --main
107
88
  - README.md
108
- require_paths:
89
+ require_paths:
109
90
  - lib
110
- required_ruby_version: !ruby/object:Gem::Requirement
91
+ required_ruby_version: !ruby/object:Gem::Requirement
111
92
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
119
- required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
98
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 11
125
- segments:
126
- - 1
127
- - 2
128
- version: "1.2"
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '1.2'
129
103
  requirements: []
130
-
131
104
  rubyforge_project: websnap
132
- rubygems_version: 1.6.2
105
+ rubygems_version: 1.8.10
133
106
  signing_key:
134
107
  specification_version: 3
135
108
  summary: Create snapshot of webpage
136
109
  test_files: []
137
-