imgkit 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +3 -25
- data/README.md +11 -17
- data/lib/imgkit/imgkit.rb +23 -1
- data/lib/imgkit/version.rb +1 -1
- data/spec/fixtures/example.js +1 -0
- data/spec/imgkit_spec.rb +31 -0
- data/spec/spec_helper.rb +1 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6db8c1811095b219f1f7a4fabf5c8cd17f1185e
|
4
|
+
data.tar.gz: 934d7ca922cf72789af64fb78c13e82721c8f8ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85fd2c927e505b17de2dd6d5f965fdf02e27d6a330a14fa2504e9518f46c5dbb7d5b595140557eb1da587bce7263d13d6b2a2a7a1d9d6f783d13053d2b303e46
|
7
|
+
data.tar.gz: 7eb58a359bbbe0ed8e7e8833f025f9a51a5d4b2bad9082ad12237dc75a64982e1757739fef9e675fb24a2b0af73c10323ed2f2236d9bee50cf2d5105e74ff786
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
imgkit (1.
|
4
|
+
imgkit (1.6.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
archive-tar-minitar (0.5.2)
|
10
|
-
columnize (0.3.4)
|
11
9
|
diff-lcs (1.1.2)
|
12
|
-
linecache (0.46)
|
13
|
-
rbx-require-relative (> 0.0.4)
|
14
|
-
linecache19 (0.5.12)
|
15
|
-
ruby_core_source (>= 0.1.4)
|
16
10
|
mocha (0.9.12)
|
17
11
|
rack (1.3.0)
|
18
12
|
rake (0.9.2.2)
|
19
|
-
rbx-require-relative (0.0.5)
|
20
13
|
rspec (2.6.0)
|
21
14
|
rspec-core (~> 2.6.0)
|
22
15
|
rspec-expectations (~> 2.6.0)
|
@@ -25,21 +18,7 @@ GEM
|
|
25
18
|
rspec-expectations (2.6.0)
|
26
19
|
diff-lcs (~> 1.1.2)
|
27
20
|
rspec-mocks (2.6.0)
|
28
|
-
|
29
|
-
columnize (>= 0.1)
|
30
|
-
ruby-debug-base (~> 0.10.4.0)
|
31
|
-
ruby-debug-base (0.10.4)
|
32
|
-
linecache (>= 0.3)
|
33
|
-
ruby-debug-base19 (0.11.25)
|
34
|
-
columnize (>= 0.3.1)
|
35
|
-
linecache19 (>= 0.5.11)
|
36
|
-
ruby_core_source (>= 0.1.4)
|
37
|
-
ruby-debug19 (0.11.6)
|
38
|
-
columnize (>= 0.3.1)
|
39
|
-
linecache19 (>= 0.5.11)
|
40
|
-
ruby-debug-base19 (>= 0.11.19)
|
41
|
-
ruby_core_source (0.1.5)
|
42
|
-
archive-tar-minitar (>= 0.5.2)
|
21
|
+
wkhtmltoimage-binary (0.12.1)
|
43
22
|
|
44
23
|
PLATFORMS
|
45
24
|
ruby
|
@@ -51,5 +30,4 @@ DEPENDENCIES
|
|
51
30
|
rake
|
52
31
|
rspec (~> 2)
|
53
32
|
rspec-core (~> 2)
|
54
|
-
|
55
|
-
ruby-debug19
|
33
|
+
wkhtmltoimage-binary
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# IMGKit
|
2
2
|
|
3
|
+
<img src="https://travis-ci.org/csquared/IMGKit.svg?branch=master" />
|
4
|
+
|
3
5
|
Create JPGs using plain old HTML+CSS. Uses [wkhtmltoimage](http://github.com/antialize/wkhtmltopdf) on the backend which renders HTML using Webkit.
|
4
6
|
|
5
7
|
Heavily based on [PDFKit](http://github.com/jdpace/pdfkit/).
|
@@ -11,10 +13,14 @@ Heavily based on [PDFKit](http://github.com/jdpace/pdfkit/).
|
|
11
13
|
gem install imgkit
|
12
14
|
|
13
15
|
### wkhtmltoimage
|
14
|
-
|
16
|
+
1. Use installer: `sudo imgkit --install-wkhtmltoimage`
|
15
17
|
install latest version into /usr/local/bin
|
16
18
|
(overwrite defaults with e.g. ARCHITECTURE=amd64 TO=/home/foo/bin)
|
17
|
-
|
19
|
+
2. Install by hand: [http://wkhtmltopdf.org/downloads.html](http://wkhtmltopdf.org/downloads.html)
|
20
|
+
3. Try using the `wkhtmltoimage-binary` gem (mac + linux)
|
21
|
+
```
|
22
|
+
gem install wkhtmltoimage-binary
|
23
|
+
```
|
18
24
|
|
19
25
|
## Usage
|
20
26
|
|
@@ -22,6 +28,7 @@ Heavily based on [PDFKit](http://github.com/jdpace/pdfkit/).
|
|
22
28
|
# run `wkhtmltoimage --extended-help` for a full list of options
|
23
29
|
kit = IMGKit.new(html, :quality => 50)
|
24
30
|
kit.stylesheets << '/path/to/css/file'
|
31
|
+
kit.javascripts << '/path/to/js/file'
|
25
32
|
|
26
33
|
# Get the image BLOB
|
27
34
|
img = kit.to_img
|
@@ -36,7 +43,7 @@ Heavily based on [PDFKit](http://github.com/jdpace/pdfkit/).
|
|
36
43
|
file = kit.to_file('/path/to/save/file.png')
|
37
44
|
|
38
45
|
# IMGKit.new can optionally accept a URL or a File.
|
39
|
-
# Stylesheets can not be added when source is provided as a URL of File.
|
46
|
+
# Stylesheets nor Javascripts can not be added when source is provided as a URL of File.
|
40
47
|
kit = IMGKit.new('http://google.com')
|
41
48
|
kit = IMGKit.new(File.new('/path/to/html'))
|
42
49
|
|
@@ -245,20 +252,7 @@ Contributed by @ticktricktrack
|
|
245
252
|
|
246
253
|
## Testing
|
247
254
|
|
248
|
-
|
249
|
-
|
250
|
-
- 1.8.7-p370
|
251
|
-
- 1.9.2-p290
|
252
|
-
- 1.9.3-p194
|
253
|
-
|
254
|
-
You can simply
|
255
|
-
|
256
|
-
$ rbenv-install <version>
|
257
|
-
$ rbenv shell <version>
|
258
|
-
$ bundle
|
259
|
-
$ bundle exec rake
|
260
|
-
|
261
|
-
For each version
|
255
|
+
Travis.yml is configured for multiple rubies, so I would just test a 2.1.x version and let travis handle the rest.
|
262
256
|
|
263
257
|
## Copyright
|
264
258
|
|
data/lib/imgkit/imgkit.rb
CHANGED
@@ -30,13 +30,14 @@ class IMGKit
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
attr_accessor :source, :stylesheets
|
33
|
+
attr_accessor :source, :stylesheets, :javascripts
|
34
34
|
attr_reader :options
|
35
35
|
|
36
36
|
def initialize(url_file_or_html, options = {})
|
37
37
|
@source = Source.new(url_file_or_html)
|
38
38
|
|
39
39
|
@stylesheets = []
|
40
|
+
@javascripts = []
|
40
41
|
|
41
42
|
@options = IMGKit.configuration.default_options.merge(options)
|
42
43
|
@options.merge! find_options_in_meta(url_file_or_html) unless source.url?
|
@@ -102,6 +103,7 @@ class IMGKit
|
|
102
103
|
|
103
104
|
def to_img(format = nil)
|
104
105
|
append_stylesheets
|
106
|
+
append_javascripts
|
105
107
|
set_format(format)
|
106
108
|
|
107
109
|
opts = @source.html? ? {:stdin_data => @source.to_s} : {}
|
@@ -151,6 +153,14 @@ class IMGKit
|
|
151
153
|
"<style>#{stylesheet.respond_to?(:read) ? stylesheet.read : File.read(stylesheet)}</style>"
|
152
154
|
end
|
153
155
|
|
156
|
+
def script_tag_for(javascript)
|
157
|
+
if javascript.respond_to?(:read)
|
158
|
+
"<script>#{javascript.read}</script>"
|
159
|
+
else
|
160
|
+
"<script src=\"#{javascript}\" type=\"text/javascript\"></script>"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
154
164
|
def append_stylesheets
|
155
165
|
raise ImproperSourceError.new('Stylesheets may only be added to an HTML source') if stylesheets.any? && !@source.html?
|
156
166
|
|
@@ -163,6 +173,18 @@ class IMGKit
|
|
163
173
|
end
|
164
174
|
end
|
165
175
|
|
176
|
+
def append_javascripts
|
177
|
+
raise ImproperSourceError.new('Javascripts may only be added to an HTML source') if javascripts.any? && !@source.html?
|
178
|
+
|
179
|
+
javascripts.each do |javascript|
|
180
|
+
if @source.to_s.match(/<\/head>/)
|
181
|
+
@source.to_s.gsub!(/(<\/head>)/, script_tag_for(javascript)+'\1')
|
182
|
+
else
|
183
|
+
@source.to_s.insert(0, script_tag_for(javascript))
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
166
188
|
def normalize_options(options)
|
167
189
|
normalized_options = {}
|
168
190
|
|
data/lib/imgkit/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
console.log('Yay!');
|
data/spec/imgkit_spec.rb
CHANGED
@@ -163,6 +163,37 @@ describe IMGKit do
|
|
163
163
|
lambda { imgkit.to_img }.should raise_error(IMGKit::ImproperSourceError)
|
164
164
|
end
|
165
165
|
|
166
|
+
it "should have the script added to the head if it has one" do
|
167
|
+
imgkit = IMGKit.new("<html><head></head><body>Hai!</body></html>")
|
168
|
+
js = File.join(SPEC_ROOT,'fixtures','example.js')
|
169
|
+
imgkit.javascripts << js
|
170
|
+
imgkit.to_img
|
171
|
+
imgkit.source.to_s.should include("<script src=\"#{js}\" type=\"text/javascript\"></script>")
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should accept script as an object which responds to #read" do
|
175
|
+
imgkit = IMGKit.new("<html><head></head><body>Hai!</body></html>")
|
176
|
+
js = StringIO.new( File.read(File.join(SPEC_ROOT,'fixtures','example.js')) )
|
177
|
+
imgkit.javascripts << js
|
178
|
+
imgkit.to_img
|
179
|
+
imgkit.source.to_s.should include("<script>#{js.string}</script>")
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should prepend script tags if the HTML doesn't have a head tag" do
|
183
|
+
imgkit = IMGKit.new("<html><body>Hai!</body></html>")
|
184
|
+
js = File.join(SPEC_ROOT,'fixtures','example.js')
|
185
|
+
imgkit.javascripts << js
|
186
|
+
imgkit.to_img
|
187
|
+
imgkit.source.to_s.should include("<script src=\"#{js}\" type=\"text/javascript\"></script>")
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should throw an error if the source is not html and script have been added" do
|
191
|
+
imgkit = IMGKit.new('http://google.com')
|
192
|
+
js = File.join(SPEC_ROOT,'fixtures','example.js')
|
193
|
+
imgkit.javascripts << js
|
194
|
+
lambda { imgkit.to_img }.should raise_error(IMGKit::ImproperSourceError)
|
195
|
+
end
|
196
|
+
|
166
197
|
def set_wkhtmltoimage_binary(binary)
|
167
198
|
spec_dir = File.dirname(__FILE__)
|
168
199
|
IMGKit.configuration.should_receive(:wkhtmltoimage).at_least(1).times.and_return(File.join(spec_dir, binary))
|
data/spec/spec_helper.rb
CHANGED
@@ -9,9 +9,7 @@ require 'rack'
|
|
9
9
|
|
10
10
|
RSpec.configure do |config|
|
11
11
|
config.before do
|
12
|
-
IMGKit.any_instance.stubs(:wkhtmltoimage).returns(
|
13
|
-
File.join(SPEC_ROOT,'..','bin','wkhtmltoimage-proxy')
|
14
|
-
)
|
12
|
+
IMGKit.any_instance.stubs(:wkhtmltoimage).returns('bundle exec wkhtmltoimage')
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- csquared
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Uses wkhtmltoimage to create Images using HTML
|
14
14
|
email: christopher.continanza@gmail.com
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- ".gitignore"
|
22
22
|
- ".rspec"
|
23
23
|
- ".rvmrc"
|
24
|
+
- ".travis.yml"
|
24
25
|
- Gemfile
|
25
26
|
- Gemfile.lock
|
26
27
|
- LICENSE
|
@@ -38,6 +39,7 @@ files:
|
|
38
39
|
- spec/error_binary
|
39
40
|
- spec/fixtures/example.css
|
40
41
|
- spec/fixtures/example.html
|
42
|
+
- spec/fixtures/example.js
|
41
43
|
- spec/imgkit_spec.rb
|
42
44
|
- spec/source_spec.rb
|
43
45
|
- spec/spec_helper.rb
|
@@ -82,6 +84,7 @@ test_files:
|
|
82
84
|
- spec/error_binary
|
83
85
|
- spec/fixtures/example.css
|
84
86
|
- spec/fixtures/example.html
|
87
|
+
- spec/fixtures/example.js
|
85
88
|
- spec/imgkit_spec.rb
|
86
89
|
- spec/source_spec.rb
|
87
90
|
- spec/spec_helper.rb
|