wisepdf 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,10 +3,10 @@ source "http://rubygems.org"
3
3
  group :development, :test do
4
4
  gem 'sqlite3'
5
5
  gem 'wkhtmltopdf-binary'
6
-
6
+
7
7
  gem "shoulda", ">= 0"
8
8
  gem "bundler", ">= 1.0.0"
9
9
  gem "jeweler", "~> 1.6.4"
10
10
 
11
11
  gem 'rails', '>=3.0.0'
12
- end
12
+ end
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- actionmailer (3.2.9)
5
- actionpack (= 3.2.9)
4
+ actionmailer (3.2.11)
5
+ actionpack (= 3.2.11)
6
6
  mail (~> 2.4.4)
7
- actionpack (3.2.9)
8
- activemodel (= 3.2.9)
9
- activesupport (= 3.2.9)
7
+ actionpack (3.2.11)
8
+ activemodel (= 3.2.11)
9
+ activesupport (= 3.2.11)
10
10
  builder (~> 3.0.0)
11
11
  erubis (~> 2.7.0)
12
12
  journey (~> 1.0.4)
@@ -14,21 +14,23 @@ GEM
14
14
  rack-cache (~> 1.2)
15
15
  rack-test (~> 0.6.1)
16
16
  sprockets (~> 2.2.1)
17
- activemodel (3.2.9)
18
- activesupport (= 3.2.9)
17
+ activemodel (3.2.11)
18
+ activesupport (= 3.2.11)
19
19
  builder (~> 3.0.0)
20
- activerecord (3.2.9)
21
- activemodel (= 3.2.9)
22
- activesupport (= 3.2.9)
20
+ activerecord (3.2.11)
21
+ activemodel (= 3.2.11)
22
+ activesupport (= 3.2.11)
23
23
  arel (~> 3.0.2)
24
24
  tzinfo (~> 0.3.29)
25
- activeresource (3.2.9)
26
- activemodel (= 3.2.9)
27
- activesupport (= 3.2.9)
28
- activesupport (3.2.9)
25
+ activeresource (3.2.11)
26
+ activemodel (= 3.2.11)
27
+ activesupport (= 3.2.11)
28
+ activesupport (3.2.11)
29
29
  i18n (~> 0.6)
30
30
  multi_json (~> 1.0)
31
31
  arel (3.0.2)
32
+ bourne (1.1.2)
33
+ mocha (= 0.10.5)
32
34
  builder (3.0.4)
33
35
  erubis (2.7.0)
34
36
  git (1.2.5)
@@ -39,45 +41,49 @@ GEM
39
41
  git (>= 1.2.5)
40
42
  rake
41
43
  journey (1.0.4)
42
- json (1.7.5)
44
+ json (1.7.6)
43
45
  mail (2.4.4)
44
46
  i18n (>= 0.4.0)
45
47
  mime-types (~> 1.16)
46
48
  treetop (~> 1.4.8)
49
+ metaclass (0.0.1)
47
50
  mime-types (1.19)
48
- multi_json (1.3.7)
51
+ mocha (0.10.5)
52
+ metaclass (~> 0.0.1)
53
+ multi_json (1.5.0)
49
54
  polyglot (0.3.3)
50
- rack (1.4.1)
55
+ rack (1.4.3)
51
56
  rack-cache (1.2)
52
57
  rack (>= 0.4)
53
58
  rack-ssl (1.3.2)
54
59
  rack
55
60
  rack-test (0.6.2)
56
61
  rack (>= 1.0)
57
- rails (3.2.9)
58
- actionmailer (= 3.2.9)
59
- actionpack (= 3.2.9)
60
- activerecord (= 3.2.9)
61
- activeresource (= 3.2.9)
62
- activesupport (= 3.2.9)
62
+ rails (3.2.11)
63
+ actionmailer (= 3.2.11)
64
+ actionpack (= 3.2.11)
65
+ activerecord (= 3.2.11)
66
+ activeresource (= 3.2.11)
67
+ activesupport (= 3.2.11)
63
68
  bundler (~> 1.0)
64
- railties (= 3.2.9)
65
- railties (3.2.9)
66
- actionpack (= 3.2.9)
67
- activesupport (= 3.2.9)
69
+ railties (= 3.2.11)
70
+ railties (3.2.11)
71
+ actionpack (= 3.2.11)
72
+ activesupport (= 3.2.11)
68
73
  rack-ssl (~> 1.3.2)
69
74
  rake (>= 0.8.7)
70
75
  rdoc (~> 3.4)
71
76
  thor (>= 0.14.6, < 2.0)
72
- rake (10.0.2)
77
+ rake (10.0.3)
73
78
  rdoc (3.12)
74
79
  json (~> 1.4)
75
80
  shoulda (3.3.2)
76
81
  shoulda-context (~> 1.0.1)
77
82
  shoulda-matchers (~> 1.4.1)
78
- shoulda-context (1.0.1)
79
- shoulda-matchers (1.4.1)
83
+ shoulda-context (1.0.2)
84
+ shoulda-matchers (1.4.2)
80
85
  activesupport (>= 3.0.0)
86
+ bourne (~> 1.1.2)
81
87
  sprockets (2.2.2)
82
88
  hike (~> 1.2)
83
89
  multi_json (~> 1.0)
data/MIT-LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
  Copyright (c) 2008 Miles Z. Sterret
2
-
2
+
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
5
5
  "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@ without limitation the rights to use, copy, modify, merge, publish,
7
7
  distribute, sublicense, and/or sell copies of the Software, and to
8
8
  permit persons to whom the Software is furnished to do so, subject to
9
9
  the following conditions:
10
-
10
+
11
11
  The above copyright notice and this permission notice shall be
12
12
  included in all copies or substantial portions of the Software.
13
-
13
+
14
14
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
data/README.md CHANGED
@@ -23,7 +23,7 @@ Add this to your Gemfile:
23
23
 
24
24
  then do:
25
25
 
26
- bundle
26
+ bundle install
27
27
 
28
28
  ## How does it work?
29
29
 
@@ -230,17 +230,28 @@ However, the wisepdf_* helpers will use file:// paths for assets when using :sho
230
230
 
231
231
  Know other projects? Then contact me and I will add them to the list.
232
232
 
233
- ## Contributing to wisepdf
233
+ ## Note on Patches / Pull Requests
234
234
 
235
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
236
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
237
- * Fork the project
238
- * Start a feature/bugfix branch
239
- * Commit and push until you are happy with your contribution
240
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
241
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
235
+ * Fork the project.
236
+ * Make your feature addition or bug fix.
237
+ * Add tests for it. This is important so I don't break it in a
238
+ future version unintentionally.
239
+ * Commit, do not mess with rakefile, version, or history.
240
+ (if you want to have your own version, that is fine but
241
+ bump version in a commit by itself I can ignore when I pull)
242
+ * Send me a pull request. Bonus points for topic branches.
242
243
 
243
- ## Copyright
244
+ ## Credits
244
245
 
245
- Copyright (c) 2012 Igor Alexandrov. See LICENSE.txt for
246
- further details.
246
+ ![JetRockets](http://www.jetrockets.ru/images/logo.png)
247
+
248
+ Wisepsd is maintained by [JetRockets](http://www.jetrockets.ru/en).
249
+
250
+ Contributors:
251
+
252
+ * [Igor Alexandrov](http://igor-alexandrov.github.com/)
253
+ * [Alexey Solilin](https://github.com/solilin)
254
+
255
+ ## License
256
+
257
+ It is free software, and may be redistributed under the terms specified in the LICENSE file.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.6
1
+ 1.2.7
@@ -6,4 +6,4 @@ if defined?(Rails) && Rails::VERSION::MAJOR > 2
6
6
  copy_file 'configure_wisepdf.rb', 'config/initializers/configure_wisepdf.rb'
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -3,51 +3,51 @@ require 'singleton'
3
3
  module Wisepdf
4
4
  class Configuration
5
5
  include Singleton
6
-
6
+
7
7
  class << self
8
8
  attr_accessor :options
9
9
  attr_accessor :wkhtmltopdf
10
-
10
+
11
11
  def wkhtmltopdf
12
12
  return @wkhtmltopdf if @wkhtmltopdf.present?
13
-
13
+
14
14
  if @wkhtmltopdf.nil? && !self.windows?
15
15
  @wkhtmltopdf = (defined?(Bundler) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
16
16
  end
17
- return @wkhtmltopdf
17
+ return @wkhtmltopdf
18
18
  end
19
-
19
+
20
20
  def configure
21
21
  yield self
22
22
  end
23
-
23
+
24
24
  def reset!
25
25
  @options = {
26
26
  :encoding => "UTF-8",
27
27
  :use_xserver => false
28
28
  }
29
29
  @wkhtmltopdf = nil
30
- end
31
-
30
+ end
31
+
32
32
  def development?
33
33
  (defined?(::Rails) && ::Rails.env == 'development') ||
34
34
  (defined?(RAILS_ENV) && RAILS_ENV == 'development')
35
35
  end
36
-
36
+
37
37
  def test?
38
38
  (defined?(::Rails) && ::Rails.env == 'test') ||
39
39
  (defined?(RAILS_ENV) && RAILS_ENV == 'test')
40
- end
41
-
40
+ end
41
+
42
42
  def windows?
43
43
  RbConfig::CONFIG['target_os'] == 'mingw32'
44
44
  end
45
45
  end
46
-
46
+
47
47
  self.reset!
48
-
48
+
49
49
  def method_missing(method)
50
50
  self.class.send(method)
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -7,7 +7,7 @@ module Wisepdf
7
7
  super(msg)
8
8
  end
9
9
  end
10
-
10
+
11
11
  class WriteError < StandardError
12
12
  end
13
- end
13
+ end
data/lib/wisepdf/ext.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  class Object
2
2
  def blank?
3
- !self
3
+ !self
4
4
  end unless method_defined? :blank?
5
5
 
6
6
  def present?
7
7
  !blank?
8
8
  end unless method_defined? :present?
9
- end
9
+ end
@@ -3,9 +3,9 @@ module Wisepdf
3
3
  module Legacy
4
4
  def wisepdf_stylesheet_tag(*sources)
5
5
  stylesheets_dir = ::Rails.root.join('public','stylesheets')
6
-
6
+
7
7
  sources.collect { |source|
8
- filename = ( source =~ /.css\z/ ? source : source + '.css' )
8
+ filename = ( source =~ /.css\z/ ? source : source + '.css' )
9
9
  "<style type='text/css'>
10
10
  #{File.read(stylesheets_dir.join(filename))}
11
11
  </style>"
@@ -15,10 +15,10 @@ module Wisepdf
15
15
  def wisepdf_image_tag(img, options={})
16
16
  image_tag "file:///#{::Rails.root.join('public', 'images', img).pathname.to_s}", options
17
17
  end
18
-
18
+
19
19
  def wisepdf_javascript_tag(*sources)
20
20
  javascripts_dir = ::Rails.root.join('public','javascripts')
21
-
21
+
22
22
  sources.collect { |source|
23
23
  filename = ( source =~ /.js\z/ ? source : source + '.js' )
24
24
  "<script type='text/javascript'>
@@ -28,12 +28,12 @@ module Wisepdf
28
28
  </script>"
29
29
  }.join("\n").html_safe
30
30
  end
31
- end
32
-
31
+ end
32
+
33
33
  module Assets
34
- def wisepdf_stylesheet_tag(*sources)
34
+ def wisepdf_stylesheet_tag(*sources)
35
35
  sources.collect { |source|
36
- filename = ( source =~ /.css\z/ ? source : source + '.css' )
36
+ filename = ( source =~ /.css\z/ ? source : source + '.css' )
37
37
  "<style type='text/css'>
38
38
  #{::Rails.application.assets.find_asset(filename)}
39
39
  </style>"
@@ -47,7 +47,7 @@ module Wisepdf
47
47
  image_tag "file:///#{asset.pathname.to_s}", options
48
48
  end
49
49
  end
50
-
50
+
51
51
  def wisepdf_javascript_tag(*sources)
52
52
  sources.collect { |source|
53
53
  filename = ( source =~ /.js\z/ ? source : source + '.js' )
@@ -60,4 +60,4 @@ module Wisepdf
60
60
  end
61
61
  end
62
62
  end
63
- end
63
+ end
@@ -1,14 +1,14 @@
1
1
  module Wisepdf
2
2
  class Parser
3
3
  include Singleton
4
-
4
+
5
5
  ESCAPED_OPTIONS = [
6
6
  :pdf, :layout, :template, :action, :partial,
7
7
  :object, :collection, :as, :spacer_template,
8
8
  :disposition, :locals, :status, :file, :text,
9
9
  :xml, :json, :callback, :inline, :location, :save_to_file
10
10
  ]
11
-
11
+
12
12
  class << self
13
13
  def parse(options)
14
14
  options = self.escape(options)
@@ -23,27 +23,27 @@ module Wisepdf
23
23
  end
24
24
  parsed_options
25
25
  end
26
-
27
- protected
26
+
27
+ protected
28
28
  def escape(options)
29
- options.delete_if{ |k,v| ESCAPED_OPTIONS.include?(k.to_sym) }
29
+ options.delete_if{ |k,v| ESCAPED_OPTIONS.include?(k.to_sym) }
30
30
  end
31
-
31
+
32
32
  def flatten(options, prefix = nil)
33
33
  hash = {}
34
34
  options.each do |k,v|
35
35
  key = prefix.nil? ? k : "#{prefix.to_s}-#{k}"
36
36
 
37
37
  if v.is_a?(Hash)
38
- hash.delete(k)
38
+ hash.delete(k)
39
39
  hash.merge!(self.flatten(v, key))
40
- else
41
- hash[key.to_s] = v
42
- end
40
+ else
41
+ hash[key.to_s] = v
42
+ end
43
43
  end
44
44
  return hash
45
- end
46
-
45
+ end
46
+
47
47
  def normalize_arg(arg)
48
48
  arg.to_s.downcase.gsub(/[^a-z0-9]/,'-')
49
49
  end
@@ -56,6 +56,6 @@ module Wisepdf
56
56
  value.to_s
57
57
  end
58
58
  end
59
- end
59
+ end
60
60
  end
61
- end
61
+ end
@@ -4,7 +4,7 @@ module Wisepdf
4
4
  initializer "wicked_pdf.register" do
5
5
  ActionController::Base.send :include, Render
6
6
  ActionView::Base.send :include, Helper::Legacy
7
- end
7
+ end
8
8
  end
9
9
  end
10
- end
10
+ end
data/lib/wisepdf/rails.rb CHANGED
@@ -7,9 +7,9 @@ module Wisepdf
7
7
  require 'wisepdf/rails/railtie'
8
8
  else
9
9
  require 'wisepdf/rails/engine'
10
- end
11
- end
12
-
10
+ end
11
+ end
12
+
13
13
  if Mime::Type.lookup_by_extension(:pdf).nil?
14
14
  Mime::Type.register('application/pdf', :pdf)
15
15
  end
@@ -10,9 +10,9 @@ module Wisepdf
10
10
 
11
11
  def render(options = nil, *args, &block)
12
12
  if options.is_a?(Hash) && options.has_key?(:pdf)
13
- options = self.default_pdf_render_options.merge(options)
13
+ options = self.default_pdf_render_options.merge(options)
14
14
  super(options.merge(:content_type => "text/html"), *args, &block) and return if options[:show_as_html]
15
-
15
+
16
16
  self.log_pdf_creation
17
17
  self.make_and_send_pdf(options)
18
18
  else
@@ -29,7 +29,7 @@ module Wisepdf
29
29
  end
30
30
  end
31
31
 
32
- protected
32
+ protected
33
33
  def log_pdf_creation
34
34
  logger.info '*'*15 + 'WISEPDF' + '*'*15
35
35
  end
@@ -39,29 +39,29 @@ module Wisepdf
39
39
  @hf_tempfiles.each { |tf| tf.close! }
40
40
  end
41
41
  end
42
-
42
+
43
43
  def default_pdf_render_options
44
44
  {
45
45
  :wkhtmltopdf => nil,
46
46
  :layout => false,
47
47
  :template => "#{controller_path}/#{action_name}",
48
- :disposition => "inline"
48
+ :disposition => "inline"
49
49
  }.merge(Wisepdf::Configuration.options)
50
50
  end
51
-
51
+
52
52
  def make_pdf(options = {})
53
- options = self.prerender_header_and_footer(options)
54
- html = render_to_string(:template => options[:template], :layout => options[:layout])
53
+ options = self.prerender_header_and_footer(options)
54
+ html = render_to_string(:template => options[:template], :layout => options[:layout])
55
55
  Wisepdf::Writer.new(options[:wkhtmltopdf], options.dup).to_pdf(html)
56
56
  end
57
57
 
58
- def make_and_send_pdf(options = {})
58
+ def make_and_send_pdf(options = {})
59
59
  pdf = self.make_pdf(options)
60
60
  File.open(options[:save_to_file], 'wb') {|file| file << pdf } if options[:save_to_file].present?
61
-
61
+
62
62
  filename = options.delete(:pdf)
63
63
  filename += '.pdf' unless filename =~ /.pdf\z|.PDF\Z/
64
-
64
+
65
65
  send_data(pdf, options.merge(:filename => filename, :type => 'application/pdf')) unless options[:save_only]
66
66
  end
67
67
 
@@ -69,18 +69,18 @@ module Wisepdf
69
69
  [:header, :footer].each do |hf|
70
70
  if arguments[hf] && arguments[hf][:html] && arguments[hf][:html].is_a?(Hash)
71
71
  opts = arguments[hf].delete(:html)
72
-
72
+
73
73
  @hf_tempfiles = [] if ! defined?(@hf_tempfiles)
74
74
  @hf_tempfiles.push( tf = Tempfile.new(["wisepdf_#{hf}_pdf", '.html']) )
75
75
  opts[:layout] ||= arguments[:layout]
76
-
76
+
77
77
  tf.write render_to_string(:template => opts[:template], :layout => opts[:layout], :locals => opts[:locals])
78
78
  tf.flush
79
-
80
- arguments[hf][:html] = "file://#{tf.path}"
79
+
80
+ arguments[hf][:html] = "file://#{tf.path}"
81
81
  end
82
82
  end
83
83
  arguments
84
84
  end
85
85
  end
86
- end
86
+ end
@@ -1,14 +1,14 @@
1
1
  require 'open3'
2
2
 
3
3
  module Wisepdf
4
- class Writer
4
+ class Writer
5
5
  def initialize(wkhtmltopdf = nil, options = {})
6
6
  self.wkhtmltopdf = wkhtmltopdf unless wkhtmltopdf.nil?
7
7
  self.options = options
8
8
  end
9
9
 
10
10
  def to_pdf(string, options={})
11
- invoke = self.command(options).join(' ')
11
+ invoke = self.command(options).join(' ')
12
12
  self.log(invoke) if Wisepdf::Configuration.development? || Wisepdf::Configuration.test?
13
13
 
14
14
  result, err = Open3.popen3(invoke) do |stdin, stdout, stderr|
@@ -24,42 +24,41 @@ module Wisepdf
24
24
  end
25
25
 
26
26
  def wkhtmltopdf
27
- @wkhtmltopdf ||= Wisepdf::Configuration.wkhtmltopdf
28
- @wkhtmltopdf
27
+ @wkhtmltopdf || self.wkhtmltopdf = Wisepdf::Configuration.wkhtmltopdf
29
28
  end
30
29
 
31
- def wkhtmltopdf=(value)
30
+ def wkhtmltopdf=(value)
31
+ raise Wisepdf::NoExecutableError.new(value) if value.blank? || !File.exists?(value)
32
32
  @wkhtmltopdf = value
33
- raise Wisepdf::NoExecutableError.new(@wkhtmltopdf) if @wkhtmltopdf.blank? || !File.exists?(@wkhtmltopdf)
34
33
  end
35
-
34
+
36
35
  def options
37
36
  @options ||= Wisepdf::Parser.parse(Wisepdf::Configuration.options.dup)
38
37
  @options
39
38
  end
40
-
39
+
41
40
  def options=(value)
42
41
  self.options.merge!(Wisepdf::Parser.parse(value))
43
42
  end
44
-
45
- protected
43
+
44
+ protected
46
45
  def command(options = {})
47
46
  options = Wisepdf::Parser.parse(options)
48
-
47
+
49
48
  args = [self.wkhtmltopdf]
50
49
  args += self.options.merge(options).to_a.flatten.compact
51
50
  args << '--quiet'
52
51
 
53
- args << '-'
52
+ args << '-'
54
53
  args << '-'
55
54
 
56
55
  args.map {|arg| %Q{"#{arg.gsub('"', '\"')}"}}
57
56
  end
58
57
 
59
58
  def log(command)
60
- puts "*"*15
59
+ puts "*"*15
61
60
  puts command
62
61
  puts "*"*15
63
62
  end
64
63
  end
65
- end
64
+ end
@@ -1,8 +1,8 @@
1
1
  require 'helper'
2
-
2
+
3
3
  class ApplicationControllerTest < ActionController::TestCase
4
4
  tests ApplicationController
5
-
5
+
6
6
  context "The controller" do
7
7
  setup do
8
8
  module Wisepdf::Render
@@ -11,22 +11,22 @@ class ApplicationControllerTest < ActionController::TestCase
11
11
  public :prerender_header_and_footer
12
12
  end
13
13
  end
14
-
14
+
15
15
  should "respond to #make_pdf" do
16
16
  assert_respond_to @controller, :make_pdf
17
17
  end
18
-
18
+
19
19
  should "respond to #make_and_send_pdf" do
20
20
  assert_respond_to @controller, :make_and_send_pdf
21
- end
22
-
21
+ end
22
+
23
23
  should "respond to #prerender_header_and_footer" do
24
24
  assert_respond_to @controller, :prerender_header_and_footer
25
- end
26
-
25
+ end
26
+
27
27
  should 'render pdf' do
28
28
  get :index, :format => :pdf
29
29
  assert_response 200
30
30
  end
31
31
  end
32
- end
32
+ end
@@ -1,37 +1,37 @@
1
1
  require 'helper'
2
2
 
3
- class ConfigurationTest < Test::Unit::TestCase
3
+ class ConfigurationTest < Test::Unit::TestCase
4
4
  context "Default configuration" do
5
5
  setup do
6
6
  Wisepdf::Configuration.reset!
7
7
  end
8
-
8
+
9
9
  should 'read default configuration' do
10
10
  assert_equal "UTF-8", Wisepdf::Configuration.options[:encoding]
11
11
  assert_equal false, Wisepdf::Configuration.options[:use_xserver]
12
12
  end
13
-
13
+
14
14
  if RbConfig::CONFIG['target_os'] != 'mingw32'
15
15
  should 'try to find wkhtmltopdf if not on windows' do
16
16
  path = (defined?(Bundler) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
17
-
17
+
18
18
  assert_equal path, Wisepdf::Configuration.wkhtmltopdf
19
19
  end
20
20
  end
21
21
  end
22
-
22
+
23
23
  context "Configuration" do
24
24
  setup do
25
25
  Wisepdf::Configuration.reset!
26
26
  end
27
-
27
+
28
28
  should 'accept and override default configuration' do
29
29
  Wisepdf::Configuration.configure do |config|
30
30
  config.wkhtmltopdf = '/path/to/wkhtmltopdf'
31
31
  config.options = {
32
32
  :layout => "layout.html",
33
33
  :use_xserver => true,
34
- :footer => {
34
+ :footer => {
35
35
  :right => "#{Date.today.year}",
36
36
  :font_size => 8,
37
37
  :spacing => 8
@@ -42,7 +42,7 @@ class ConfigurationTest < Test::Unit::TestCase
42
42
  }
43
43
  end
44
44
  assert_equal '/path/to/wkhtmltopdf', Wisepdf::Configuration.wkhtmltopdf
45
-
45
+
46
46
  assert_equal 'layout.html', Wisepdf::Configuration.options[:layout]
47
47
  assert_equal true, Wisepdf::Configuration.options[:use_xserver]
48
48
  assert_equal "#{Date.today.year}", Wisepdf::Configuration.options[:footer][:right]
@@ -50,5 +50,5 @@ class ConfigurationTest < Test::Unit::TestCase
50
50
  assert_equal 8, Wisepdf::Configuration.options[:footer][:spacing]
51
51
  assert_equal 15, Wisepdf::Configuration.options[:margin][:bottom]
52
52
  end
53
- end
54
- end
53
+ end
54
+ end
@@ -1,7 +1,7 @@
1
1
  class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
-
2
+ protect_from_forgery
3
+
4
4
  def index
5
5
  render :pdf => 'filename'
6
- end
6
+ end
7
7
  end
@@ -1,25 +1,25 @@
1
1
  require 'helper'
2
-
2
+
3
3
  class AssetsHelperTest < ActionView::TestCase
4
4
  include Wisepdf::Helper::Assets
5
-
6
- context "wisepdf_stylesheet_tag" do
5
+
6
+ context "wisepdf_stylesheet_tag" do
7
7
  should 'include stylesheet if no extension is given' do
8
8
  assert_match wisepdf_stylesheet_tag('wisepdf').strip, /Wisepdf styles/
9
9
  end
10
-
10
+
11
11
  should 'include stylesheet if .css extension is given' do
12
12
  assert_match wisepdf_stylesheet_tag('wisepdf.css').strip, /Wisepdf styles/
13
13
  end
14
- end
15
-
16
- context "wisepdf_javascript_tag" do
14
+ end
15
+
16
+ context "wisepdf_javascript_tag" do
17
17
  should 'include javascript if no extension is given' do
18
18
  assert_match wisepdf_javascript_tag('wisepdf').strip, /Wisepdf javascript/
19
19
  end
20
-
20
+
21
21
  should 'include javascript if .js extension is given' do
22
22
  assert_match wisepdf_javascript_tag('wisepdf.js').strip, /Wisepdf javascript/
23
23
  end
24
- end
24
+ end
25
25
  end
@@ -1,25 +1,25 @@
1
1
  require 'helper'
2
-
2
+
3
3
  class LegacyHelperTest < ActionView::TestCase
4
4
  include Wisepdf::Helper::Legacy
5
-
6
- context "wisepdf_stylesheet_tag" do
5
+
6
+ context "wisepdf_stylesheet_tag" do
7
7
  should 'include stylesheet if no extension is given' do
8
8
  assert_match wisepdf_stylesheet_tag('wisepdf').strip, /Wisepdf styles/
9
9
  end
10
-
10
+
11
11
  should 'include stylesheet if .css extension is given' do
12
12
  assert_match wisepdf_stylesheet_tag('wisepdf.css').strip, /Wisepdf styles/
13
13
  end
14
- end
15
-
16
- context "wisepdf_javascript_tag" do
14
+ end
15
+
16
+ context "wisepdf_javascript_tag" do
17
17
  should 'include javascript if no extension is given' do
18
18
  assert_match wisepdf_javascript_tag('wisepdf').strip, /Wisepdf javascript/
19
19
  end
20
-
20
+
21
21
  should 'include javascript if .js extension is given' do
22
22
  assert_match wisepdf_javascript_tag('wisepdf.js').strip, /Wisepdf javascript/
23
23
  end
24
- end
24
+ end
25
25
  end
data/test/parser_test.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'helper'
2
2
 
3
- class ParserTest < Test::Unit::TestCase
3
+ class ParserTest < Test::Unit::TestCase
4
4
  context "Options normalization" do
5
5
  setup do
6
6
  Wisepdf::Configuration.reset!
7
-
7
+
8
8
  @options = { Wisepdf::Parser::ESCAPED_OPTIONS.sample => 'value' }
9
9
  end
10
-
10
+
11
11
  should 'escape and parse digit options' do
12
12
  @options.merge!({
13
13
  :key => 10
@@ -15,10 +15,10 @@ class ParserTest < Test::Unit::TestCase
15
15
  expected = {
16
16
  '--key' => '10'
17
17
  }
18
-
18
+
19
19
  assert_equal expected, Wisepdf::Parser.parse(@options)
20
20
  end
21
-
21
+
22
22
  should 'escape and parse string options' do
23
23
  @options.merge!({
24
24
  :key => 'value'
@@ -26,10 +26,10 @@ class ParserTest < Test::Unit::TestCase
26
26
  expected = {
27
27
  '--key' => 'value'
28
28
  }
29
-
29
+
30
30
  assert_equal expected, Wisepdf::Parser.parse(@options)
31
31
  end
32
-
32
+
33
33
  should 'escape and parse boolean (true) options' do
34
34
  @options.merge!({
35
35
  :key => true
@@ -37,19 +37,19 @@ class ParserTest < Test::Unit::TestCase
37
37
  expected = {
38
38
  '--key' => nil
39
39
  }
40
-
40
+
41
41
  assert_equal expected, Wisepdf::Parser.parse(@options)
42
42
  end
43
-
43
+
44
44
  should 'escape and parse boolean (false) options' do
45
45
  @options.merge!({
46
46
  :key => false
47
47
  })
48
48
  expected = {}
49
-
49
+
50
50
  assert_equal expected, Wisepdf::Parser.parse(@options)
51
51
  end
52
-
52
+
53
53
  should 'escape and parse nested options' do
54
54
  @options.merge!({
55
55
  :key => 'value',
@@ -61,8 +61,8 @@ class ParserTest < Test::Unit::TestCase
61
61
  '--key' => 'value',
62
62
  '--nested-key' => 'value'
63
63
  }
64
-
64
+
65
65
  assert_equal expected, Wisepdf::Parser.parse(@options)
66
- end
66
+ end
67
67
  end
68
- end
68
+ end
data/test/writer_test.rb CHANGED
@@ -6,8 +6,8 @@ class Wisepdf::Writer
6
6
  public :command
7
7
  end
8
8
 
9
- class WriterTest < Test::Unit::TestCase
10
- context "PDF generation" do
9
+ class WriterTest < Test::Unit::TestCase
10
+ context "PDF generation" do
11
11
  should "generate PDF from html document" do
12
12
  writer = Wisepdf::Writer.new
13
13
  pdf = writer.to_pdf(HTML_DOCUMENT)
@@ -29,7 +29,7 @@ class WriterTest < Test::Unit::TestCase
29
29
  writer.to_pdf(HTML_DOCUMENT)
30
30
  end
31
31
  end
32
-
32
+
33
33
  should "raise exception when wkhtmltopdf is not executable" do
34
34
  begin
35
35
  tmp = Tempfile.new('wkhtmltopdf')
@@ -37,14 +37,14 @@ class WriterTest < Test::Unit::TestCase
37
37
  File.chmod 0000, fp
38
38
  assert_raise Wisepdf::WriteError do
39
39
  writer = Wisepdf::Writer.new(fp)
40
- writer.to_pdf(HTML_DOCUMENT)
40
+ writer.to_pdf(HTML_DOCUMENT)
41
41
  end
42
42
  ensure
43
43
  tmp.delete
44
44
  end
45
45
  end
46
46
 
47
-
47
+
48
48
  should "raise exception when pdf generation fails" do
49
49
  begin
50
50
  tmp = Tempfile.new('wkhtmltopdf')
@@ -52,11 +52,11 @@ class WriterTest < Test::Unit::TestCase
52
52
  File.chmod 0777, fp
53
53
  assert_raise Wisepdf::WriteError do
54
54
  writer = Wisepdf::Writer.new(fp)
55
- writer.to_pdf(HTML_DOCUMENT)
55
+ writer.to_pdf(HTML_DOCUMENT)
56
56
  end
57
57
  ensure
58
58
  tmp.delete
59
59
  end
60
- end
61
- end
60
+ end
61
+ end
62
62
  end
data/wisepdf.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wisepdf"
8
- s.version = "1.2.6"
8
+ s.version = "1.2.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Igor Alexandrov"]
12
- s.date = "2012-11-28"
12
+ s.date = "2013-01-10"
13
13
  s.description = "wisepdf uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML. In other words, rather than dealing with a PDF generation DSL of some sort, you simply write an HTML view as you would normally, and let pdf take care of the hard stuff."
14
14
  s.email = "igor.alexandrov@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wisepdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
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-11-28 00:00:00.000000000 Z
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
@@ -201,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  segments:
203
203
  - 0
204
- hash: -4546671269605536200
204
+ hash: -1965210465825970962
205
205
  required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  none: false
207
207
  requirements: