shrimp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,3 +2,12 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 1.9.2
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ - ruby-head
8
+ - 2.0.0
9
+ matrix:
10
+ allow_failures:
11
+ - rvm:
12
+ - ruby-head
13
+ - 2.0.0
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
  [![Build Status](https://travis-ci.org/adeven/shrimp.png?branch=master)](https://travis-ci.org/adeven/shrimp)
3
3
  Creates PDFs from URLs using phantomjs
4
4
 
5
+ Read our [blogpost](http://big-elephants.com/2012-12/pdf-rendering-with-phantomjs/) about how it works.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -61,9 +63,24 @@ Shrimp.configure do |config|
61
63
  # the timeout for the phantomjs rendering process in ms
62
64
  # this needs always to be higher than rendering_time
63
65
  # config.rendering_timeout = 90000
66
+
67
+ # the path to a json configuration file for command-line options
68
+ # config.command_config_file = "#{Rails.root.join('config', 'shrimp', 'config.json')}"
64
69
  end
65
70
  ```
66
71
 
72
+ ### Command Configuration
73
+
74
+ ```
75
+ {
76
+ "diskCache": false,
77
+ "ignoreSslErrors": false,
78
+ "loadImages": true,
79
+ "outputEncoding": "utf8",
80
+ "webSecurity": true
81
+ }
82
+ ```
83
+
67
84
  ## Middleware
68
85
 
69
86
  Shrimp comes with a middleware that allows users to get a PDF view of any page on your site by appending .pdf to the URL.
@@ -0,0 +1,7 @@
1
+ {
2
+ "diskCache": false,
3
+ "ignoreSslErrors": false,
4
+ "loadImages": true,
5
+ "outputEncoding": "utf8",
6
+ "webSecurity": true
7
+ }
@@ -4,7 +4,7 @@ module Shrimp
4
4
  attr_accessor :default_options
5
5
  attr_writer :phantomjs
6
6
 
7
- [:format, :margin, :zoom, :orientation, :tmpdir, :rendering_timeout, :rendering_time].each do |m|
7
+ [:format, :margin, :zoom, :orientation, :tmpdir, :rendering_timeout, :rendering_time, :command_config_file].each do |m|
8
8
  define_method("#{m}=") do |val|
9
9
  @default_options[m]=val
10
10
  end
@@ -12,13 +12,14 @@ module Shrimp
12
12
 
13
13
  def initialize
14
14
  @default_options = {
15
- :format => 'A4',
16
- :margin => '1cm',
17
- :zoom => 1,
18
- :orientation => 'portrait',
19
- :tmpdir => Dir.tmpdir,
20
- :rendering_timeout => 90000,
21
- :rendering_time => 1000
15
+ :format => 'A4',
16
+ :margin => '1cm',
17
+ :zoom => 1,
18
+ :orientation => 'portrait',
19
+ :tmpdir => Dir.tmpdir,
20
+ :rendering_timeout => 90000,
21
+ :rendering_time => 1000,
22
+ :command_config_file => File.expand_path('../config.json', __FILE__)
22
23
  }
23
24
  end
24
25
 
@@ -128,7 +128,7 @@ module Shrimp
128
128
  <head>
129
129
  </head>
130
130
  <body onLoad="setTimeout(function(){ window.location.reload()}, #{interval * 1000});">
131
- <h2>Prepareing pdf... </h2>
131
+ <h2>Preparing pdf... </h2>
132
132
  </body>
133
133
  </ html>
134
134
  HTML
@@ -56,19 +56,20 @@ module Shrimp
56
56
  format, zoom, margin, orientation = options[:format], options[:zoom], options[:margin], options[:orientation]
57
57
  rendering_time, timeout = options[:rendering_time], options[:rendering_timeout]
58
58
  @outfile ||= "#{options[:tmpdir]}/#{Digest::MD5.hexdigest((Time.now.to_i + rand(9001)).to_s)}.pdf"
59
-
60
- [Shrimp.configuration.phantomjs, SCRIPT_FILE, @source.to_s, @outfile, format, zoom, margin, orientation, cookie_file, rendering_time, timeout].join(" ")
59
+ command_config_file = "--config=#{options[:command_config_file]}"
60
+ [Shrimp.configuration.phantomjs, command_config_file, SCRIPT_FILE, @source.to_s, @outfile, format, zoom, margin, orientation, cookie_file, rendering_time, timeout].join(" ")
61
61
  end
62
62
 
63
63
  # Public: initializes a new Phantom Object
64
64
  #
65
- # url_or_file - The url of the html document to render
66
- # options - a hash with options for rendering
67
- # * format - the paper format for the output eg: "5in*7.5in", "10cm*20cm", "A4", "Letter"
68
- # * zoom - the viewport zoom factor
69
- # * margin - the margins for the pdf
70
- # cookies - hash with cookies to use for rendering
71
- # outfile - optional path for the output file a Tempfile will be created if not given
65
+ # url_or_file - The url of the html document to render
66
+ # options - a hash with options for rendering
67
+ # * format - the paper format for the output eg: "5in*7.5in", "10cm*20cm", "A4", "Letter"
68
+ # * zoom - the viewport zoom factor
69
+ # * margin - the margins for the pdf
70
+ # * command_config_file - the path to a json configuration file for command-line options
71
+ # cookies - hash with cookies to use for rendering
72
+ # outfile - optional path for the output file a Tempfile will be created if not given
72
73
  #
73
74
  # Returns self
74
75
  def initialize(url_or_file, options = { }, cookies={ }, outfile = nil)
@@ -124,7 +125,7 @@ module Shrimp
124
125
  private
125
126
  def dump_cookies
126
127
  host = @source.url? ? URI::parse(@source.to_s).host : "/"
127
- json = @cookies.inject([]) { |a, (k, v)| a.push({ name: k, value: v, domain: host }); a }.to_json
128
+ json = @cookies.inject([]) { |a, (k, v)| a.push({ :name => k, :value => v, :domain => host }); a }.to_json
128
129
  File.open("#{options[:tmpdir]}/#{rand}.cookies", 'w') { |f| f.puts json; f }.path
129
130
  end
130
131
  end
@@ -74,8 +74,9 @@ if (system.args.length < 3 || system.args.length > 10) {
74
74
  fs.move(output + '_tmp.pdf', output);
75
75
  }
76
76
  catch (e) {
77
- phantom.exit(1);
78
- throw e
77
+ console.log(e);
78
+ phantom.exit(1);
79
+ throw e
79
80
  }
80
81
  console.log('rendered to: ' + output, new Date().getTime());
81
82
  phantom.exit();
@@ -1,3 +1,3 @@
1
1
  module Shrimp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency(%q<rake>, [">=0.9.2"])
24
24
  gem.add_development_dependency(%q<rspec>, [">= 2.2.0"])
25
25
  gem.add_development_dependency(%q<rack-test>, [">= 0.5.6"])
26
+ gem.add_development_dependency(%q<rack>, ["= 1.4.1"])
26
27
  end
@@ -18,7 +18,6 @@ def mock_app(options = { }, conditions = { })
18
18
 
19
19
  @middleware = Shrimp::Middleware.new(main_app, options, conditions)
20
20
  @app = Rack::Session::Cookie.new(@middleware, :key => 'rack.session')
21
- @middleware.should_receive(:fire_phantom).any_number_of_times
22
21
  end
23
22
 
24
23
 
@@ -64,7 +63,7 @@ describe Shrimp::Middleware do
64
63
  end
65
64
 
66
65
  it "should return a pdf with 200 after rendering" do
67
- mock_file = mock(File, :read => "Hello World", :close => true, :mtime => Time.now)
66
+ mock_file = double(File, :read => "Hello World", :close => true, :mtime => Time.now)
68
67
  File.should_receive(:'exists?').and_return true
69
68
  File.should_receive(:'size').and_return 1000
70
69
  File.should_receive(:'open').and_return mock_file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrimp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70155488162600 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70155488162600
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &70155488162080 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.9.2
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70155488162080
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.2
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &70155488161560 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 2.2.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70155488161560
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.2.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rack-test
49
- requirement: &70155488161080 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,28 @@ dependencies:
54
69
  version: 0.5.6
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70155488161080
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.5.6
78
+ - !ruby/object:Gem::Dependency
79
+ name: rack
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.4.1
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.4.1
58
94
  description: html to pdf with phantomjs
59
95
  email:
60
96
  - manuel@adeven.com
@@ -70,6 +106,7 @@ files:
70
106
  - README.md
71
107
  - Rakefile
72
108
  - lib/shrimp.rb
109
+ - lib/shrimp/config.json
73
110
  - lib/shrimp/configuration.rb
74
111
  - lib/shrimp/middleware.rb
75
112
  - lib/shrimp/phantom.rb
@@ -94,16 +131,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
131
  - - ! '>='
95
132
  - !ruby/object:Gem::Version
96
133
  version: '0'
134
+ segments:
135
+ - 0
136
+ hash: 2078211269578037741
97
137
  required_rubygems_version: !ruby/object:Gem::Requirement
98
138
  none: false
99
139
  requirements:
100
140
  - - ! '>='
101
141
  - !ruby/object:Gem::Version
102
142
  version: '0'
143
+ segments:
144
+ - 0
145
+ hash: 2078211269578037741
103
146
  requirements:
104
147
  - phantomjs, v1.6 or greater
105
148
  rubyforge_project:
106
- rubygems_version: 1.8.10
149
+ rubygems_version: 1.8.25
107
150
  signing_key:
108
151
  specification_version: 3
109
152
  summary: a phantomjs based pdf renderer