fa_princely 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ tmp
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
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
+ end
22
+ end
23
+ end
24
+
25
+ # Alternatively, you can use make_and_send_pdf to
26
+ # render out a PDF for the action without a
27
+ # respond_to block.
28
+ def pdf
29
+ make_and_send_pdf("file_name")
30
+ end
31
+ end
32
+
33
+ == Render Defaults
34
+
35
+ The defaults for the render options are as follows:
36
+
37
+ layout: false
38
+ template: the template for the current controller/action
39
+ stylesheets: none
40
+
41
+ == Contributors
42
+
43
+ * Gemification and more: Nic Williams
44
+
45
+ == Resources
46
+
47
+ * Copyright (c) 2007-2009 Michael Bleigh and Intridea, Inc., released under the MIT license.
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "princely"
8
+ gem.summary = %Q{A simple Rails wrapper for the PrinceXML PDF generation library.}
9
+ gem.description = %Q{A wrapper for the PrinceXML PDF generation library.}
10
+ gem.email = "michael@intridea.com"
11
+ gem.homepage = "http://github.com/mbleigh/princely"
12
+ gem.authors = ["Michael Bleigh"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ task :default => :test
28
+
29
+ require 'rake/rdoctask'
30
+ Rake::RDocTask.new do |rdoc|
31
+ if File.exist?('VERSION')
32
+ version = File.read('VERSION')
33
+ else
34
+ version = ""
35
+ end
36
+
37
+ rdoc.rdoc_dir = 'rdoc'
38
+ rdoc.title = "princely #{version}"
39
+ rdoc.options << '--line-numbers' << '--inline-source'
40
+ rdoc.rdoc_files.include('README*')
41
+ rdoc.rdoc_files.include('lib/**/*.rb')
42
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.2.5
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/rails/init'
@@ -0,0 +1,97 @@
1
+ # PrinceXML Ruby interface.
2
+ # http://www.princexml.com
3
+ #
4
+ # Library by Subimage Interactive - http://www.subimage.com
5
+ #
6
+ #
7
+ # USAGE
8
+ # -----------------------------------------------------------------------------
9
+ # princely = Princely.new()
10
+ # html_string = render_to_string(:template => 'some_document')
11
+ # send_data(
12
+ # princely.pdf_from_string(html_string),
13
+ # :filename => 'some_document.pdf'
14
+ # :type => 'application/pdf'
15
+ # )
16
+ #
17
+ $:.unshift(File.dirname(__FILE__))
18
+ require 'logger'
19
+
20
+ class Princely
21
+ VERSION = "1.0.0" unless const_defined?("VERSION")
22
+
23
+ attr_accessor :exe_path, :style_sheets, :log_file, :logger
24
+
25
+ # Initialize method
26
+ #
27
+ def initialize()
28
+ # Finds where the application lives, so we can call it.
29
+ @exe_path = `which prince`.chomp
30
+ raise "Cannot find prince command-line app in $PATH" if @exe_path.length == 0
31
+ @style_sheets = ''
32
+ @log_file = "#{RAILS_ROOT}/log/prince.log"
33
+ @logger = RAILS_DEFAULT_LOGGER
34
+ end
35
+
36
+ # Sets stylesheets...
37
+ # Can pass in multiple paths for css files.
38
+ #
39
+ def add_style_sheets(*sheets)
40
+ for sheet in sheets do
41
+ @style_sheets << " -s #{sheet} "
42
+ end
43
+ end
44
+
45
+ # Returns fully formed executable path with any command line switches
46
+ # we've set based on our variables.
47
+ #
48
+ def exe_path
49
+ # Add any standard cmd line arguments we need to pass
50
+ #FA
51
+ @exe_path << " --input=html --server --log=#{@log_file} --fileroot=#{RAILS_ROOT}/public/"
52
+ @exe_path << @style_sheets
53
+ return @exe_path
54
+ end
55
+
56
+ # Makes a pdf from a passed in string.
57
+ #
58
+ # Returns PDF as a stream, so we can use send_data to shoot
59
+ # it down the pipe using Rails.
60
+ #
61
+ def pdf_from_string(string, output_file = '-')
62
+ path = self.exe_path()
63
+ # Don't spew errors to the standard out...and set up to take IO
64
+ # as input and output
65
+ path << ' --silent - -o -'
66
+
67
+ # Show the command used...
68
+ logger.info "\n\nPRINCE XML PDF COMMAND"
69
+ logger.info path
70
+ logger.info ''
71
+
72
+ # Actually call the prince command, and pass the entire data stream back.
73
+ pdf = IO.popen(path, "w+")
74
+ pdf.puts(string)
75
+ pdf.close_write
76
+ result = pdf.gets(nil)
77
+ pdf.close_read
78
+ return result
79
+ end
80
+
81
+ def pdf_from_string_to_file(string, output_file)
82
+ path = self.exe_path()
83
+ # Don't spew errors to the standard out...and set up to take IO
84
+ # as input and output
85
+ path << " --silent - -o #{output_file} >> #{@log_file} 2>> #{@log_file}"
86
+
87
+ # Show the command used...
88
+ logger.info "\n\nPRINCE XML PDF COMMAND"
89
+ logger.info path
90
+ logger.info ''
91
+
92
+ # Actually call the prince command, and pass the entire data stream back.
93
+ pdf = IO.popen(path, "w+")
94
+ pdf.puts(string)
95
+ pdf.close
96
+ end
97
+ end
@@ -0,0 +1,64 @@
1
+ module PdfHelper
2
+ require 'princely'
3
+
4
+ def self.included(base)
5
+ base.class_eval do
6
+ alias_method_chain :render, :princely
7
+ end
8
+ end
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)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def make_pdf(options = {})
22
+ options[:stylesheets] ||= []
23
+ options[:layout] ||= false
24
+ options[:template] ||= File.join(controller_path,action_name)
25
+ options[:html_string] ||= false
26
+
27
+ prince = Princely.new()
28
+ # Sets style sheets on PDF renderer
29
+ prince.add_style_sheets(*options[:stylesheets].collect{|style| stylesheet_file_path(style)})
30
+
31
+ if (options[:html_string])
32
+ html_string = options[:html_string]
33
+ else
34
+ html_string = render_to_string(:template => options[:template], :layout => options[:layout])
35
+ end
36
+
37
+ # Make all paths relative, on disk paths...
38
+ html_string.gsub!(".com:/",".com/") # strip out bad attachment_fu URLs
39
+ html_string.gsub!( /src=["']+([^:]+?)["']/i ) { |m| "src=\"#{RAILS_ROOT}/public/" + $1 + '"' } # re-route absolute paths
40
+
41
+ # Remove asset ids on images with a regex
42
+ html_string.gsub!( /src=["'](\S+\?\d*)["']/i ) { |m| 'src="' + $1.split('?').first + '"' }
43
+
44
+ # Send the generated PDF file from our html string.
45
+ if filename = options[:filename] || options[:file]
46
+ prince.pdf_from_string_to_file(html_string, filename)
47
+ else
48
+ prince.pdf_from_string(html_string)
49
+ end
50
+ end
51
+
52
+ def make_and_send_pdf(pdf_name, options = {})
53
+ send_data(
54
+ make_pdf(options),
55
+ :filename => pdf_name + ".pdf",
56
+ :type => 'application/pdf'
57
+ )
58
+ end
59
+
60
+ def stylesheet_file_path(stylesheet)
61
+ stylesheet = stylesheet.to_s.gsub(".css","")
62
+ File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR,"#{stylesheet}.css")
63
+ end
64
+ end
@@ -0,0 +1,6 @@
1
+ require 'princely'
2
+ require 'princely/pdf_helper'
3
+
4
+ Mime::Type.register 'application/pdf', :pdf
5
+
6
+ ActionController::Base.send(:include, PdfHelper)
@@ -0,0 +1,46 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{fa_princely}
8
+ s.version = "1.2.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael Bleigh","fatangel"]
12
+ s.date = %q{2010-11-03}
13
+ s.description = %q{A wrapper for the PrinceXML PDF generation library. Modded for Radiant}
14
+ s.email = %q{michael@intridea.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "init.rb",
25
+ "lib/princely.rb",
26
+ "lib/princely/pdf_helper.rb",
27
+ "lib/princely/rails.rb",
28
+ "princely.gemspec",
29
+ "rails/init.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/mbleigh/princely}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.3}
35
+ s.summary = %q{A simple Rails wrapper for the PrinceXML PDF generation library.}
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
+ else
43
+ end
44
+ else
45
+ end
46
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/../lib/princely/rails"
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fa_princely
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 5
10
+ version: 1.2.5
11
+ platform: ruby
12
+ authors:
13
+ - Michael Bleigh
14
+ - fatangel
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-11-03 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: A wrapper for the PrinceXML PDF generation library. Modded for Radiant
24
+ email: michael@intridea.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - README.rdoc
31
+ files:
32
+ - .gitignore
33
+ - MIT-LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - VERSION
37
+ - init.rb
38
+ - lib/princely.rb
39
+ - lib/princely/pdf_helper.rb
40
+ - lib/princely/rails.rb
41
+ - princely.gemspec
42
+ - rails/init.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/mbleigh/princely
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.7
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: A simple Rails wrapper for the PrinceXML PDF generation library.
77
+ test_files: []
78
+