yabbie 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c31d73314e5756f24029458d3393b224d3b2dc9
4
- data.tar.gz: 733328151866ab81c14461274aa5dbb3eab5609f
3
+ metadata.gz: b6b1986d94973af7ece20471e87f0efe50eb095a
4
+ data.tar.gz: 57a64488b764bdff9586feff71564dfbaaf3a31d
5
5
  SHA512:
6
- metadata.gz: d44a6e2b4a26d0bbfc1d79a6ddfc46f9f88b1485f98d731105856e0e625dc8bf974bc704fc54f513675a08fdbdd945129fb8eaedad5f9e726762e3ecdaf33402
7
- data.tar.gz: 6e5148ebf79e2dcff0c0bec8c67be5968e758b1b8aa059792e87fbaa39bdbd81063ab1698b09788142d7ae67a76d648738a6583732c4e38e065fe2c7e5b6d5dd
6
+ metadata.gz: 648c2b6840bddf5f5cb4e848047ec5210b3dedab84f9d7e9d0a2ea6397368a5431ff4930d6466267753060d59ff9f0d591cb1ac269bf5624be373795b9509fed
7
+ data.tar.gz: fbabf190c6c0c5eaff47bc093b0604789d5b40e63e00da5a02191c5d7f67d07564c5609b4f724c9e0622e43d395081f9719c5ee62cf91f2dcb0e1cbafd0a445f
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -4,7 +4,7 @@ module Yabbie
4
4
  class Configuration
5
5
  attr_accessor :default_options
6
6
 
7
- [:format, :tmpdir, :timeout, :config_file, :error_log_file, :width, :height, :prepend_command, :script].each do |m|
7
+ [:format, :tmpdir, :timeout, :config_file, :error_log_file, :width, :height, :prepend_command, :script, :slimerjs].each do |m|
8
8
  define_method("#{m}=") do |val|
9
9
  @default_options[m] = val
10
10
  end
@@ -20,13 +20,10 @@ module Yabbie
20
20
  height: 600,
21
21
  error_log_file: Dir.tmpdir + "/log/yabbie_error.log",
22
22
  prepend_command: '',
23
- script: File.expand_path('../default.js', __FILE__)
23
+ script: File.expand_path('../default.js', __FILE__),
24
+ slimerjs: `which slimerjs`.chomp
24
25
  }
25
26
  end
26
-
27
- def slimerjs
28
- @slimerjs ||= `which slimerjs`.chomp
29
- end
30
27
  end
31
28
 
32
29
  class << self
@@ -2,13 +2,15 @@ var webpage = require('webpage'),
2
2
  system = require('system');
3
3
 
4
4
  var url = system.args[1],
5
- output = system.args[2];
5
+ output = system.args[2],
6
+ width = system.args[3],
7
+ height = system.args[4];
6
8
 
7
9
  var page = webpage.create();
8
10
 
9
11
  page.open(url)
10
12
  .then(function() {
11
- page.viewportSize = { width: 650, height: 320 };
13
+ page.viewportSize = { width: width, height: height };
12
14
  page.render(output, { onlyViewport: true });
13
15
 
14
16
  slimer.exit();
@@ -1,7 +1,7 @@
1
1
  module Yabbie
2
2
  class NoExecutableError < StandardError
3
- def initialize
4
- msg = "No slimerjs executable found at #{Yabbie.configuration.slimerjs}\n"
3
+ def initialize(executable = nil)
4
+ msg = "No slimerjs executable found at #{executable}\n"
5
5
  msg << ">> Please install slimerjs"
6
6
  super(msg)
7
7
  end
@@ -6,11 +6,11 @@ module Yabbie
6
6
  attr_accessor :source, :configuration
7
7
  attr_reader :options, :result, :error
8
8
 
9
- def initialize(url_or_file, options = {})
9
+ def initialize(url_or_file, opts = {})
10
10
  @source = Source.new(url_or_file)
11
- @options = Yabbie.configuration.default_options.merge(options)
11
+ @options = Yabbie.configuration.default_options.merge(opts)
12
12
 
13
- raise NoExecutableError.new unless File.exists?(Yabbie.configuration.slimerjs)
13
+ raise NoExecutableError.new(options[:slimerjs]) unless command?(options[:slimerjs])
14
14
  end
15
15
 
16
16
  def run
@@ -28,7 +28,7 @@ module Yabbie
28
28
  def cmd
29
29
  [
30
30
  prepend_command,
31
- Yabbie.configuration.slimerjs,
31
+ slimerjs,
32
32
  command_config_file,
33
33
  command_error_log,
34
34
  script,
@@ -44,6 +44,9 @@ module Yabbie
44
44
  def render(path = nil)
45
45
  @outfile = File.expand_path(path) if path
46
46
  self.run
47
+
48
+ raise Yabbie::RenderingError.new(@error) if @error
49
+
47
50
  @outfile
48
51
  end
49
52
 
@@ -82,12 +85,16 @@ module Yabbie
82
85
  options[:prepend_command]
83
86
  end
84
87
 
88
+ def slimerjs
89
+ options[:slimerjs]
90
+ end
91
+
85
92
  def command_config_file
86
- "--config=#{options[:config_file]}"
93
+ options[:config_file].empty? ? nil : "--config=#{options[:config_file]}"
87
94
  end
88
95
 
89
96
  def command_error_log
90
- "--error-log-file=#{options[:error_log_file]}"
97
+ options[:error_log_file].empty? ? nil : "--error-log-file=#{options[:error_log_file]}"
91
98
  end
92
99
 
93
100
  def outfile
@@ -97,5 +104,9 @@ module Yabbie
97
104
  "#{options[:tmpdir]}/#{Digest::MD5.hexdigest((Time.now.to_i + rand(9001)).to_s)}.#{format}"
98
105
  end
99
106
  end
107
+
108
+ def command?(name)
109
+ !`which #{name}`.empty?
110
+ end
100
111
  end
101
112
  end
@@ -1,3 +1,3 @@
1
1
  module Yabbie
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -3,5 +3,10 @@ require 'pry'
3
3
 
4
4
  RSpec.configure do |config|
5
5
  config.order = 'random'
6
+
7
+ config.before do
8
+ allow_any_instance_of(Yabbie::Slimer).to receive(:`).and_return('/usr/bin/slimerjs')
9
+ end
10
+
6
11
  end
7
12
 
@@ -6,7 +6,8 @@ describe Yabbie::Configuration do
6
6
  describe 'accessors' do
7
7
  context 'when values are not provided' do
8
8
  it 'falls back to defaults' do
9
- defaults = { format: 'png',
9
+ defaults = {
10
+ format: 'png',
10
11
  tmpdir: Dir.tmpdir,
11
12
  timeout: 120000,
12
13
  config_file: File.expand_path('../../../lib/yabbie/config.json', __FILE__),
@@ -14,7 +15,9 @@ describe Yabbie::Configuration do
14
15
  height: 600,
15
16
  error_log_file: Dir.tmpdir + "/log/yabbie_error.log",
16
17
  prepend_command: '',
17
- script: 'default.js' }
18
+ script: File.expand_path('../../../lib/yabbie/default.js', __FILE__),
19
+ slimerjs: `which slimerjs`.chomp
20
+ }
18
21
 
19
22
  expect(subject.default_options).to eq(defaults)
20
23
  end
@@ -64,13 +67,10 @@ describe Yabbie::Configuration do
64
67
  subject.script = 'config/cool_slimerjs_stuff.js'
65
68
  expect(subject.default_options[:script]).to eq('config/cool_slimerjs_stuff.js')
66
69
  end
67
- end
68
-
69
- describe '#slimerjs' do
70
- it 'finds where slimerjs is installed' do
71
- allow(subject).to receive(:`).with('which slimerjs').and_return('/usr/bin/slimerjs')
72
70
 
73
- expect(subject.slimerjs).to eq('/usr/bin/slimerjs')
71
+ it 'defines accessor to slimerjs' do
72
+ subject.slimerjs = '/sbin/slimerjs-094'
73
+ expect(subject.default_options[:slimerjs]).to eq('/sbin/slimerjs-094')
74
74
  end
75
75
  end
76
76
 
@@ -11,26 +11,24 @@ describe Yabbie::Slimer do
11
11
  height: 10,
12
12
  format: 'pdf',
13
13
  tmpdir: '/tmp',
14
- timeout: 10
14
+ timeout: 10,
15
+ slimerjs: '/usr/bin/slimerjs'
15
16
  }
16
17
  }
17
18
 
18
19
  subject { described_class.new('http://google.com', options) }
19
20
 
20
- before(:each) do
21
- # Assume slimerjs is installed
22
- allow(File).to receive(:exists?).and_return(true)
23
- allow(Yabbie.configuration).to receive(:slimerjs).and_return('/usr/bin/slimerjs')
21
+ before do
24
22
  allow(Digest::MD5).to receive(:hexdigest).and_return('md5')
25
23
  end
26
24
 
27
25
  describe 'initialization' do
28
26
  context 'when slimerjs is not present in the system' do
29
27
  it 'raises no executable error' do
30
- allow(File).to receive(:exists?).and_return(false)
28
+ allow_any_instance_of(described_class).to receive(:`).and_return('')
31
29
 
32
30
  expect {
33
- described_class.new('http://google.com')
31
+ described_class.new('http://google.com', options)
34
32
  }.to raise_error(Yabbie::NoExecutableError)
35
33
  end
36
34
  end
@@ -17,10 +17,10 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
- spec.requirements << 'slimerjs, v0.10 or greater'
20
+ spec.requirements << 'slimerjs, v0.9.4 or greater'
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rake", "~> 10.3"
24
- spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "rspec", "~> 3.1"
25
25
  spec.add_development_dependency "pry-meta", "~> 0.0"
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabbie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Bernardeli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '3.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '3.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-meta
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
+ - ".rspec"
77
78
  - ".travis.yml"
78
79
  - Gemfile
79
80
  - LICENSE.txt
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  - !ruby/object:Gem::Version
117
118
  version: '0'
118
119
  requirements:
119
- - slimerjs, v0.10 or greater
120
+ - slimerjs, v0.9.4 or greater
120
121
  rubyforge_project:
121
122
  rubygems_version: 2.2.2
122
123
  signing_key:
@@ -128,3 +129,4 @@ test_files:
128
129
  - spec/yabbie/configuration_spec.rb
129
130
  - spec/yabbie/slimer_spec.rb
130
131
  - spec/yabbie/source_spec.rb
132
+ has_rdoc: