imgkit 1.3.7 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imgkit (1.3.7)
4
+ imgkit (1.3.8)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -5,7 +5,7 @@ class IMGKit
5
5
  def initialize
6
6
  @meta_tag_prefix = 'imgkit-'
7
7
  @wkhtmltoimage = '/usr/local/bin/wkhtmltoimage'
8
- @default_options = {}
8
+ @default_options = {:height => 1000}
9
9
  @default_format = :jpg
10
10
  end
11
11
  end
@@ -21,14 +21,14 @@ class IMGKit
21
21
  # IMGKit.configure do |config|
22
22
  # config.wkhtmltoimage = '/usr/bin/wkhtmltoimage'
23
23
  # end
24
-
24
+
25
25
  def self.configuration
26
26
  @configuration ||= Configuration.new
27
27
  end
28
-
29
-
28
+
29
+
30
30
  def self.configure
31
- self.configuration
31
+ self.configuration
32
32
  yield(configuration)
33
33
  end
34
34
  end
@@ -8,7 +8,7 @@ class IMGKit
8
8
  super(msg)
9
9
  end
10
10
  end
11
-
11
+
12
12
  class ImproperSourceError < StandardError
13
13
  def initialize(msg)
14
14
  super("Improper Source: #{msg}")
@@ -29,31 +29,31 @@ class IMGKit
29
29
  super("Unknown Format: #{format}")
30
30
  end
31
31
  end
32
-
32
+
33
33
  attr_accessor :source, :stylesheets
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
40
 
41
41
  @options = IMGKit.configuration.default_options.merge(options)
42
42
  @options.merge! find_options_in_meta(url_file_or_html) unless source.url?
43
-
43
+
44
44
  raise NoExecutableError.new unless File.exists?(IMGKit.configuration.wkhtmltoimage)
45
45
  end
46
-
46
+
47
47
  def command
48
48
  args = [executable]
49
49
  args += normalize_options(@options).to_a.flatten.compact
50
-
50
+
51
51
  if @source.html?
52
52
  args << '-' # Get HTML from stdin
53
53
  else
54
54
  args << @source.to_s
55
55
  end
56
-
56
+
57
57
  args << '-' # Read IMG from stdout
58
58
  args
59
59
  end
@@ -68,7 +68,7 @@ class IMGKit
68
68
  end
69
69
  end
70
70
 
71
- if Open3.method_defined? :capture3
71
+ if Open3.respond_to? :capture3
72
72
  def capture3(*opts)
73
73
  Open3.capture3 *opts
74
74
  end
@@ -99,7 +99,7 @@ class IMGKit
99
99
  }
100
100
  end
101
101
  end
102
-
102
+
103
103
  def to_img(format = nil)
104
104
  append_stylesheets
105
105
  set_format(format)
@@ -107,11 +107,11 @@ class IMGKit
107
107
  opts = @source.html? ? {:stdin_data => @source.to_s} : {}
108
108
  result, stderr = capture3(*(command + [opts]))
109
109
  result.force_encoding("ASCII-8BIT") if result.respond_to? :force_encoding
110
-
110
+
111
111
  raise CommandFailedError.new(command.join(' '), stderr) if result.size == 0
112
112
  result
113
113
  end
114
-
114
+
115
115
  def to_file(path)
116
116
  format = File.extname(path).gsub(/^\./,'').to_sym
117
117
  set_format(format)
@@ -125,7 +125,7 @@ class IMGKit
125
125
  super
126
126
  end
127
127
  end
128
-
128
+
129
129
  protected
130
130
 
131
131
  def find_options_in_meta(body)
@@ -146,14 +146,14 @@ class IMGKit
146
146
  rescue # rexml random crash on invalid xml
147
147
  []
148
148
  end
149
-
149
+
150
150
  def style_tag_for(stylesheet)
151
151
  "<style>#{stylesheet.respond_to?(:read) ? stylesheet.read : File.read(stylesheet)}</style>"
152
152
  end
153
-
153
+
154
154
  def append_stylesheets
155
155
  raise ImproperSourceError.new('Stylesheets may only be added to an HTML source') if stylesheets.any? && !@source.html?
156
-
156
+
157
157
  stylesheets.each do |stylesheet|
158
158
  if @source.to_s.match(/<\/head>/)
159
159
  @source.to_s.gsub!(/(<\/head>)/, style_tag_for(stylesheet)+'\1')
@@ -162,7 +162,7 @@ class IMGKit
162
162
  end
163
163
  end
164
164
  end
165
-
165
+
166
166
  def normalize_options(options)
167
167
  normalized_options = {}
168
168
 
@@ -173,11 +173,11 @@ class IMGKit
173
173
  end
174
174
  normalized_options
175
175
  end
176
-
176
+
177
177
  def normalize_arg(arg)
178
178
  arg.to_s.downcase.gsub(/[^a-z0-9]/,'-')
179
179
  end
180
-
180
+
181
181
  def normalize_value(value)
182
182
  case value
183
183
  when TrueClass
@@ -1,3 +1,3 @@
1
1
  class IMGKit
2
- VERSION = "1.3.7"
2
+ VERSION = "1.3.8"
3
3
  end
@@ -22,10 +22,15 @@ describe IMGKit do
22
22
  end
23
23
 
24
24
  it "should provide no default options" do
25
+ end
26
+
27
+ it "should set a default height" do
25
28
  imgkit = IMGKit.new('<h1>Oh Hai</h1>')
26
- imgkit.options.should be_empty
29
+ imgkit.options.length.should be 1
30
+ imgkit.options[:height].should be 1000
27
31
  end
28
32
 
33
+
29
34
  =begin
30
35
  it "should default to 'UTF-8' encoding" do
31
36
  imgkit = IMGKit.new('Captación')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7
4
+ version: 1.3.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-19 00:00:00.000000000Z
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Uses wkhtmltoimage to create Images using HTML
15
15
  email: christopher.continanza@gmail.com
@@ -61,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  segments:
63
63
  - 0
64
- hash: -4046794491537096375
64
+ hash: 1349900022860754797
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
@@ -70,10 +70,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  segments:
72
72
  - 0
73
- hash: -4046794491537096375
73
+ hash: 1349900022860754797
74
74
  requirements: []
75
75
  rubyforge_project: imgkit
76
- rubygems_version: 1.8.10
76
+ rubygems_version: 1.8.23
77
77
  signing_key:
78
78
  specification_version: 3
79
79
  summary: HTML+CSS -> JPG