princely 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +58 -0
- data/lib/princely.rb +18 -104
- data/lib/princely/asset_support.rb +22 -0
- data/lib/princely/executable.rb +28 -0
- data/lib/princely/logging.rb +18 -0
- data/lib/princely/pdf.rb +124 -0
- data/lib/princely/pdf_helper.rb +53 -72
- data/lib/princely/rails.rb +4 -3
- data/lib/princely/stdout_logger.rb +7 -0
- data/lib/princely/version.rb +12 -2
- metadata +19 -26
- data/README.rdoc +0 -49
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60c51f575db0737a9fc6a0d57d14902048f6c504
|
4
|
+
data.tar.gz: 375ee87716da9847bae4c95dd526347196708c9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 82a6b39938457b082524721e5bc631810917bfd4b0252b35c786699054c79604380fc8f62bc40a83fb284cf5f8c86d54a9eaa1d74fa73a573507aa61d4700105
|
7
|
+
data.tar.gz: 8fdd1d1d74c77590e1d23fcd4edb4acde4e720045e9cf92becf18ebff907349e552df2fcc5e72cf4bc7a2aa86f7fcdef029633e3a184775ec39e5099e4f6045c
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Princely
|
2
|
+
|
3
|
+
Princely is a simple wrapper for the [Prince XML PDF generation library](http://www.princexml.com).
|
4
|
+
The plugin will also automatically register the PDF MimeType so that you can use
|
5
|
+
pdf as a format in Rails controller `respond_to` blocks.
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class Provider::EstimatesController < Provider::BaseController
|
11
|
+
# You can render PDF templates simply by
|
12
|
+
# using the :pdf option on render templates.
|
13
|
+
def show
|
14
|
+
respond_to do |format|
|
15
|
+
format.html
|
16
|
+
format.pdf do
|
17
|
+
render :pdf => 'file_name',
|
18
|
+
:template => 'controller/action',
|
19
|
+
:handlers => %w[erb],
|
20
|
+
:formats => %w[pdf],
|
21
|
+
:stylesheets => %w[application prince],
|
22
|
+
:layout => 'pdf',
|
23
|
+
:disposition => 'inline', # PDF will be sent inline, means you can load it inside an iFrame or Embed
|
24
|
+
:relative_paths => true # Modify asset paths to make them relative. See [the AssetSupport module](/lib/princely/asset_support.rb)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Alternatively, you can use make_and_send_pdf to render out a PDF for the
|
30
|
+
# action without a respond_to block.
|
31
|
+
def pdf
|
32
|
+
make_and_send_pdf "file_name"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Render Defaults
|
38
|
+
|
39
|
+
The defaults for the render options are as follows:
|
40
|
+
|
41
|
+
layout: false
|
42
|
+
template: the template for the current controller/action
|
43
|
+
stylesheets: none
|
44
|
+
disposition: attachment (created PDF file will be sent as download)
|
45
|
+
relative_paths: true
|
46
|
+
server_flag: true
|
47
|
+
javascript_flag: false
|
48
|
+
timeout: none
|
49
|
+
|
50
|
+
## Contributors
|
51
|
+
|
52
|
+
* Maintainer: Jared Fraser ([modsognir](https://github.com/modsognir))
|
53
|
+
* Gemification and more: Nic Williams
|
54
|
+
* [Other Contributors](https://github.com/mbleigh/princely/contributors)
|
55
|
+
|
56
|
+
## Resources
|
57
|
+
|
58
|
+
* Copyright (c) 2007-2013 Michael Bleigh and Intridea, Inc., released under the MIT license.
|
data/lib/princely.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
#
|
7
7
|
# USAGE
|
8
8
|
# -----------------------------------------------------------------------------
|
9
|
-
# princely = Princely.new
|
9
|
+
# princely = Princely.new
|
10
10
|
# html_string = render_to_string(:template => 'some_document')
|
11
11
|
# send_data(
|
12
12
|
# princely.pdf_from_string(html_string),
|
@@ -15,117 +15,31 @@
|
|
15
15
|
# )
|
16
16
|
#
|
17
17
|
require 'logger'
|
18
|
+
require 'pathname'
|
18
19
|
require 'princely/rails' if defined?(Rails)
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
module Princely
|
22
|
+
autoload :StdoutLogger, 'princely/stdout_logger'
|
23
|
+
autoload :AssetSupport, 'princely/asset_support'
|
24
|
+
autoload :Pdf, 'princely/pdf'
|
25
|
+
autoload :Logging, 'princely/logging'
|
26
|
+
autoload :Executable, 'princely/executable'
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
# Finds where the application lives, so we can call it.
|
27
|
-
@exe_path = options[:path] || find_prince_executable
|
28
|
-
raise "Cannot find prince command-line app in $PATH" if @exe_path.length == 0
|
29
|
-
raise "Cannot find prince command-line app at #{@exe_path}" if @exe_path && !File.executable?(@exe_path)
|
30
|
-
@style_sheets = ''
|
31
|
-
@cmd_args = ''
|
32
|
-
@log_file = options[:log_file]
|
33
|
-
@logger = options[:logger]
|
34
|
-
end
|
35
|
-
|
36
|
-
def logger
|
37
|
-
@logger ||= defined?(Rails) ? Rails.logger : StdoutLogger
|
38
|
-
end
|
39
|
-
|
40
|
-
def log_file
|
41
|
-
@log_file ||= defined?(Rails) ?
|
42
|
-
Rails.root.join("log/prince.log") :
|
43
|
-
File.expand_path(File.dirname(__FILE__) + "/log/prince.log")
|
44
|
-
end
|
45
|
-
|
46
|
-
def ruby_platform
|
47
|
-
RUBY_PLATFORM
|
48
|
-
end
|
49
|
-
|
50
|
-
def find_prince_executable
|
51
|
-
if ruby_platform =~ /mswin32/
|
52
|
-
"C:/Program Files/Prince/Engine/bin/prince"
|
53
|
-
else
|
54
|
-
`which prince`.chomp
|
28
|
+
class << self
|
29
|
+
def executable
|
30
|
+
@custom_executable || Princely::Executable.new
|
55
31
|
end
|
56
|
-
end
|
57
32
|
|
58
|
-
|
59
|
-
|
60
|
-
#
|
61
|
-
def add_style_sheets(*sheets)
|
62
|
-
for sheet in sheets do
|
63
|
-
@style_sheets << " -s #{sheet} "
|
33
|
+
def executable=(custom_executable)
|
34
|
+
@custom_executable = custom_executable
|
64
35
|
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Sets arbitrary command line arguments
|
68
|
-
def add_cmd_args(str)
|
69
|
-
@cmd_args << " #{str} "
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns fully formed executable path with any command line switches
|
73
|
-
# we've set based on our variables.
|
74
|
-
#
|
75
|
-
def exe_path
|
76
|
-
# Add any standard cmd line arguments we need to pass
|
77
|
-
@exe_path << " --input=html --server --log=#{log_file} "
|
78
|
-
@exe_path << @cmd_args
|
79
|
-
@exe_path << @style_sheets
|
80
|
-
return @exe_path
|
81
|
-
end
|
82
36
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
# it down the pipe using Rails.
|
87
|
-
#
|
88
|
-
def pdf_from_string(string, output_file = '-')
|
89
|
-
path = self.exe_path()
|
90
|
-
# Don't spew errors to the standard out...and set up to take IO
|
91
|
-
# as input and output
|
92
|
-
path << ' --silent - -o -'
|
93
|
-
|
94
|
-
# Show the command used...
|
95
|
-
logger.info "\n\nPRINCE XML PDF COMMAND"
|
96
|
-
logger.info path
|
97
|
-
logger.info ''
|
98
|
-
|
99
|
-
# Actually call the prince command, and pass the entire data stream back.
|
100
|
-
pdf = IO.popen(path, "w+")
|
101
|
-
pdf.puts(string)
|
102
|
-
pdf.close_write
|
103
|
-
result = pdf.gets(nil)
|
104
|
-
pdf.close_read
|
105
|
-
result.force_encoding('BINARY') if RUBY_VERSION >= "1.9"
|
106
|
-
return result
|
107
|
-
end
|
108
|
-
|
109
|
-
def pdf_from_string_to_file(string, output_file)
|
110
|
-
path = self.exe_path()
|
111
|
-
# Don't spew errors to the standard out...and set up to take IO
|
112
|
-
# as input and output
|
113
|
-
path << " --silent - -o '#{output_file}' >> '#{log_file}' 2>> '#{log_file}'"
|
114
|
-
|
115
|
-
# Show the command used...
|
116
|
-
logger.info "\n\nPRINCE XML PDF COMMAND"
|
117
|
-
logger.info path
|
118
|
-
logger.info ''
|
119
|
-
|
120
|
-
# Actually call the prince command, and pass the entire data stream back.
|
121
|
-
pdf = IO.popen(path, "w+")
|
122
|
-
pdf.puts(string)
|
123
|
-
pdf.close
|
124
|
-
end
|
37
|
+
def root
|
38
|
+
Pathname.new(File.expand_path('../', __FILE__))
|
39
|
+
end
|
125
40
|
|
126
|
-
|
127
|
-
|
128
|
-
puts msg
|
41
|
+
def ruby_platform
|
42
|
+
RUBY_PLATFORM
|
129
43
|
end
|
130
44
|
end
|
131
45
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Princely
|
2
|
+
module AssetSupport
|
3
|
+
def localize_html_string(html_string, asset_path = nil)
|
4
|
+
html_string = html_string.to_str
|
5
|
+
# Make all paths relative, on disk paths...
|
6
|
+
html_string.gsub!(".com:/",".com/") # strip out bad attachment_fu URLs
|
7
|
+
html_string.gsub!( /src=["']+([^:]+?)["']/i ) do |m|
|
8
|
+
asset_src = asset_path ? "#{asset_path}/#{$1}" : asset_file_path($1)
|
9
|
+
%Q{src="#{asset_src}"} # re-route absolute paths
|
10
|
+
end
|
11
|
+
|
12
|
+
# Remove asset ids on images with a regex
|
13
|
+
html_string.gsub!( /src=["'](\S+\?\d*)["']/i ) { |m| %Q{src="#{$1.split('?').first}"} }
|
14
|
+
html_string
|
15
|
+
end
|
16
|
+
|
17
|
+
def asset_file_path(asset)
|
18
|
+
# Remove /assets/ from generated names and try and find a matching asset
|
19
|
+
Rails.application.assets.find_asset(asset.gsub(%r{/assets/}, "")).try(:pathname) || asset
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Princely
|
2
|
+
class Executable
|
3
|
+
attr_reader :path
|
4
|
+
|
5
|
+
def initialize(path=nil)
|
6
|
+
@path = path || default_executable_path
|
7
|
+
|
8
|
+
check_for_executable
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_for_executable
|
12
|
+
raise "Cannot find prince command-line app in $PATH" if !@path || @path.length == 0
|
13
|
+
raise "Cannot find prince command-line app at #{@exe_path}" unless File.executable?(@path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_executable_path
|
17
|
+
if Princely.ruby_platform =~ /mswin32|minigw32/
|
18
|
+
"C:/Program Files/Prince/Engine/bin/prince"
|
19
|
+
else
|
20
|
+
`which prince`.chomp
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def join(options)
|
25
|
+
([path] + Array(options)).join(' ')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Princely
|
2
|
+
module Logging
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :logger, :filename
|
6
|
+
|
7
|
+
def logger
|
8
|
+
@logger ||= defined?(Rails) ? Rails.logger : StdoutLogger
|
9
|
+
end
|
10
|
+
|
11
|
+
def filename
|
12
|
+
pathname = defined?(Rails) ? Rails.root : Princely.root
|
13
|
+
@filename ||= pathname.join 'log', 'prince.log'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/princely/pdf.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
3
|
+
module Princely
|
4
|
+
class Pdf
|
5
|
+
attr_accessor :executable, :style_sheets, :logger, :log_file, :server_flag, :media, :javascript_flag, :timeout, :license_path
|
6
|
+
|
7
|
+
# Initialize method
|
8
|
+
#
|
9
|
+
def initialize(options={})
|
10
|
+
options = {
|
11
|
+
:path => nil,
|
12
|
+
:executable => Princely.executable,
|
13
|
+
:log_file => nil,
|
14
|
+
:logger => nil,
|
15
|
+
:server_flag => true,
|
16
|
+
:media => nil,
|
17
|
+
:javascript_flag => false,
|
18
|
+
:license_path => nil
|
19
|
+
}.merge(options)
|
20
|
+
@executable = options[:path] ? Princely::Executable.new(options[:path]) : options[:executable]
|
21
|
+
@style_sheets = ''
|
22
|
+
@log_file = options[:log_file]
|
23
|
+
@logger = options[:logger]
|
24
|
+
@license_path = options[:license_path]
|
25
|
+
@server_flag = options[:server_flag]
|
26
|
+
@media = options[:media]
|
27
|
+
@javascript_flag = options[:javascript_flag]
|
28
|
+
@timeout = options[:timeout]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the instance logger or Princely default logger
|
32
|
+
def logger
|
33
|
+
@logger || Princely::Logging.logger
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the instance log file or Princely default log file
|
37
|
+
def log_file
|
38
|
+
@log_file || Princely::Logging.filename
|
39
|
+
end
|
40
|
+
|
41
|
+
# Sets stylesheets...
|
42
|
+
# Can pass in multiple paths for css files.
|
43
|
+
#
|
44
|
+
def add_style_sheets(*sheets)
|
45
|
+
@style_sheets << sheets.map { |sheet| " -s #{sheet} " }.join(' ')
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns fully formed executable path with any command line switches
|
49
|
+
# we've set based on our variables.
|
50
|
+
#
|
51
|
+
def exe_path
|
52
|
+
@executable.join(executable_options)
|
53
|
+
end
|
54
|
+
|
55
|
+
def executable_options
|
56
|
+
options = []
|
57
|
+
options << "--input=html"
|
58
|
+
options << "--server" if @server_flag
|
59
|
+
options << "--log=#{log_file}"
|
60
|
+
options << "--media=#{media}" if media
|
61
|
+
options << "--javascript" if @javascript_flag
|
62
|
+
options << @style_sheets
|
63
|
+
options
|
64
|
+
end
|
65
|
+
|
66
|
+
# Makes a pdf from a passed in string.
|
67
|
+
#
|
68
|
+
# Returns PDF as a stream, so we can use send_data to shoot
|
69
|
+
# it down the pipe using Rails.
|
70
|
+
#
|
71
|
+
def pdf_from_string(string, output_file = '-')
|
72
|
+
with_timeout do
|
73
|
+
pdf = initialize_pdf_from_string(string, output_file, {:output_to_log_file => false})
|
74
|
+
pdf.close_write
|
75
|
+
result = pdf.gets(nil)
|
76
|
+
pdf.close_read
|
77
|
+
result.force_encoding('BINARY') if RUBY_VERSION >= "1.9"
|
78
|
+
|
79
|
+
result
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def pdf_from_string_to_file(string, output_file)
|
84
|
+
with_timeout do
|
85
|
+
pdf = initialize_pdf_from_string(string, output_file)
|
86
|
+
pdf.close
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
def with_timeout(&block)
|
93
|
+
if timeout
|
94
|
+
Timeout.timeout(timeout, &block)
|
95
|
+
else
|
96
|
+
block.call
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def initialize_pdf_from_string(string, output_file, options = {})
|
101
|
+
options = {:log_command => true, :output_to_log_file => true}.merge(options)
|
102
|
+
path = exe_path
|
103
|
+
# Don't spew errors to the standard out...and set up to take IO
|
104
|
+
# as input and output
|
105
|
+
path << " --media=#{media}" if media
|
106
|
+
path << " --silent - -o #{output_file}"
|
107
|
+
path << " --license-file=#{}" if license_path
|
108
|
+
path << " >> '#{log_file}' 2>> '#{log_file}'" if options[:output_to_log_file]
|
109
|
+
|
110
|
+
log_command path if options[:log_command]
|
111
|
+
|
112
|
+
# Actually call the prince command, and pass the entire data stream back.
|
113
|
+
pdf = IO.popen(path, "w+")
|
114
|
+
pdf.puts string
|
115
|
+
pdf
|
116
|
+
end
|
117
|
+
|
118
|
+
def log_command(path)
|
119
|
+
logger.info "\n\nPRINCE XML PDF COMMAND"
|
120
|
+
logger.info path
|
121
|
+
logger.info ''
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/lib/princely/pdf_helper.rb
CHANGED
@@ -1,84 +1,65 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def render_with_princely(options = nil, *args, &block)
|
11
|
-
if options.is_a?(Hash) && options.has_key?(:pdf)
|
12
|
-
options[:name] ||= options.delete(:pdf)
|
13
|
-
make_and_send_pdf(options.delete(:name), options)
|
14
|
-
else
|
15
|
-
render_without_princely(options, *args, &block)
|
1
|
+
require 'princely'
|
2
|
+
require 'princely/asset_support'
|
3
|
+
|
4
|
+
module Princely
|
5
|
+
module PdfHelper
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.send :alias_method_chain, :render, :princely
|
16
9
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
prince = Princely.new()
|
27
|
-
# Sets style sheets on PDF renderer
|
28
|
-
prince.add_style_sheets(*options[:stylesheets].collect{|style| asset_file_path(style)})
|
29
|
-
|
30
|
-
html_string = render_to_string(:template => options[:template], :layout => options[:layout])
|
31
|
-
|
32
|
-
html_string = localize_html_string(html_string)
|
33
|
-
|
34
|
-
# Send the generated PDF file from our html string.
|
35
|
-
if filename = options[:filename] || options[:file]
|
36
|
-
prince.pdf_from_string_to_file(html_string, filename)
|
37
|
-
else
|
38
|
-
prince.pdf_from_string(html_string)
|
10
|
+
|
11
|
+
def render_with_princely(options = nil, *args, &block)
|
12
|
+
if options.is_a?(Hash) && options.has_key?(:pdf)
|
13
|
+
options[:name] ||= options.delete(:pdf)
|
14
|
+
make_and_send_pdf(options.delete(:name), options)
|
15
|
+
else
|
16
|
+
render_without_princely(options, *args, &block)
|
17
|
+
end
|
39
18
|
end
|
40
|
-
end
|
41
19
|
|
42
|
-
|
43
|
-
# Make all paths relative, on disk paths...
|
44
|
-
html_string.gsub!(".com:/",".com/") # strip out bad attachment_fu URLs
|
45
|
-
html_string.gsub!( /src=["']+([^:]+?)["']/i ) { |m| "src=\"#{Rails.public_path}/#{$1}\"" } # re-route absolute paths
|
46
|
-
|
47
|
-
# Remove asset ids on images with a regex
|
48
|
-
html_string.gsub!( /src=["'](\S+\?\d*)["']/i ) { |m| "src=\"#{$1.split('?').first}\"" }
|
49
|
-
html_string
|
50
|
-
end
|
20
|
+
private
|
51
21
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
22
|
+
def make_pdf(options = {})
|
23
|
+
options = {
|
24
|
+
:stylesheets => [],
|
25
|
+
:layout => false,
|
26
|
+
:template => File.join(controller_path, action_name),
|
27
|
+
:relative_paths => true,
|
28
|
+
:server_flag => true,
|
29
|
+
:media => nil,
|
30
|
+
:javascript_flag => false
|
31
|
+
}.merge(options)
|
57
32
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
:type => 'application/pdf',
|
64
|
-
:disposition => options[:disposition]
|
65
|
-
)
|
66
|
-
end
|
33
|
+
prince = Princely::Pdf.new(options.slice(:server_flag, :javascript_flag, :media))
|
34
|
+
# Sets style sheets on PDF renderer
|
35
|
+
prince.add_style_sheets(*options[:stylesheets].collect{|style| asset_file_path(style)})
|
36
|
+
|
37
|
+
html_string = render_to_string(options.slice(:template, :layout, :handlers, :formats))
|
67
38
|
|
68
|
-
|
69
|
-
|
70
|
-
#
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
html_string
|
39
|
+
html_string = localize_html_string(html_string, Rails.public_path) if options[:relative_paths]
|
40
|
+
|
41
|
+
# Send the generated PDF file from our html string.
|
42
|
+
if filename = options[:filename] || options[:file]
|
43
|
+
prince.pdf_from_string_to_file(html_string, filename)
|
44
|
+
else
|
45
|
+
prince.pdf_from_string(html_string)
|
46
|
+
end
|
77
47
|
end
|
78
48
|
|
79
49
|
def asset_file_path(asset)
|
80
|
-
|
81
|
-
|
50
|
+
asset = asset.to_s.gsub('.css', '')
|
51
|
+
File.join(config.stylesheets_dir, "#{asset}.css")
|
52
|
+
end
|
53
|
+
alias_method :stylesheet_file_path, :asset_file_path
|
54
|
+
|
55
|
+
def make_and_send_pdf(pdf_name, options = {})
|
56
|
+
options = {:disposition => 'attachment'}.merge(options)
|
57
|
+
send_data(
|
58
|
+
make_pdf(options),
|
59
|
+
:filename => "#{pdf_name}.pdf",
|
60
|
+
:type => 'application/pdf',
|
61
|
+
:disposition => options[:disposition]
|
62
|
+
)
|
82
63
|
end
|
83
64
|
end
|
84
65
|
end
|
data/lib/princely/rails.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'princely/pdf_helper'
|
2
|
+
require 'princely/view_helpers'
|
2
3
|
|
3
4
|
if Mime::Type.lookup_by_extension(:pdf) != 'application/pdf'
|
4
5
|
Mime::Type.register 'application/pdf', :pdf
|
5
6
|
end
|
6
7
|
|
7
|
-
ActionController::Base.send(:include, PdfHelper)
|
8
|
-
ActionController::Base.send(:include,
|
8
|
+
ActionController::Base.send(:include, Princely::PdfHelper)
|
9
|
+
ActionController::Base.send(:include, Princely::AssetSupport) if
|
9
10
|
(Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0) ||
|
10
|
-
(Rails::VERSION::MAJOR >= 4)
|
11
|
+
(Rails::VERSION::MAJOR >= 4)
|
data/lib/princely/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: princely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael Bleigh
|
@@ -15,33 +14,29 @@ dependencies:
|
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rspec
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - ">="
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: '0'
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - ">="
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '0'
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: rake
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - ">="
|
37
33
|
- !ruby/object:Gem::Version
|
38
34
|
version: '0'
|
39
35
|
type: :development
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - ">="
|
45
40
|
- !ruby/object:Gem::Version
|
46
41
|
version: '0'
|
47
42
|
description: A wrapper for the PrinceXML PDF generation library.
|
@@ -50,44 +45,42 @@ email:
|
|
50
45
|
- dev@jsf.io
|
51
46
|
executables: []
|
52
47
|
extensions: []
|
53
|
-
extra_rdoc_files:
|
54
|
-
- README.rdoc
|
48
|
+
extra_rdoc_files: []
|
55
49
|
files:
|
56
50
|
- MIT-LICENSE
|
57
|
-
- README.
|
51
|
+
- README.md
|
58
52
|
- Rakefile
|
59
53
|
- lib/princely.rb
|
54
|
+
- lib/princely/asset_support.rb
|
55
|
+
- lib/princely/executable.rb
|
56
|
+
- lib/princely/logging.rb
|
57
|
+
- lib/princely/pdf.rb
|
60
58
|
- lib/princely/pdf_helper.rb
|
61
59
|
- lib/princely/rails.rb
|
60
|
+
- lib/princely/stdout_logger.rb
|
62
61
|
- lib/princely/version.rb
|
63
62
|
homepage: http://github.com/mbleigh/princely
|
64
|
-
licenses:
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
65
66
|
post_install_message:
|
66
67
|
rdoc_options: []
|
67
68
|
require_paths:
|
68
69
|
- lib
|
69
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
hash: -2291531356337878395
|
78
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
76
|
requirements:
|
81
|
-
- -
|
77
|
+
- - ">="
|
82
78
|
- !ruby/object:Gem::Version
|
83
79
|
version: '0'
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
hash: -2291531356337878395
|
87
80
|
requirements: []
|
88
81
|
rubyforge_project:
|
89
|
-
rubygems_version:
|
82
|
+
rubygems_version: 2.4.8
|
90
83
|
signing_key:
|
91
|
-
specification_version:
|
84
|
+
specification_version: 4
|
92
85
|
summary: A simple Rails wrapper for the PrinceXML PDF generation library.
|
93
86
|
test_files: []
|
data/README.rdoc
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
= Princely
|
2
|
-
|
3
|
-
Princely is a simple wrapper for the Prince XML PDF generation library
|
4
|
-
(http://www.princexml.com). The plugin will also automatically registers
|
5
|
-
the PDF MimeType so that you can use pdf as a format in controller
|
6
|
-
respond_to blocks.
|
7
|
-
|
8
|
-
== Example
|
9
|
-
|
10
|
-
class Provider::EstimatesController < Provider::BaseController
|
11
|
-
# You can render PDF templates simply by
|
12
|
-
# using the :pdf option on render templates.
|
13
|
-
def show
|
14
|
-
respond_to do |format|
|
15
|
-
format.html
|
16
|
-
format.pdf do
|
17
|
-
render :pdf => "file_name",
|
18
|
-
:template => "controller/action.pdf.erb",
|
19
|
-
:stylesheets => ["application","prince"],
|
20
|
-
:layout => "pdf",
|
21
|
-
:disposition => "inline" # PDF will be sent inline, means you can load it inside an iFrame or Embed
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Alternatively, you can use make_and_send_pdf to
|
27
|
-
# render out a PDF for the action without a
|
28
|
-
# respond_to block.
|
29
|
-
def pdf
|
30
|
-
make_and_send_pdf("file_name")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
== Render Defaults
|
35
|
-
|
36
|
-
The defaults for the render options are as follows:
|
37
|
-
|
38
|
-
layout: false
|
39
|
-
template: the template for the current controller/action
|
40
|
-
stylesheets: none
|
41
|
-
disposition: attachment (created PDF file will be sent as download)
|
42
|
-
|
43
|
-
== Contributors
|
44
|
-
|
45
|
-
* Gemification and more: Nic Williams
|
46
|
-
|
47
|
-
== Resources
|
48
|
-
|
49
|
-
* Copyright (c) 2007-2009 Michael Bleigh and Intridea, Inc., released under the MIT license.
|