historian_ezprint 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 09f56c837830438d94df916514de5a1f0dfa244b
4
+ data.tar.gz: 4d2a43ae0d4b1bb531489f75b82b4f49407ff262
5
+ SHA512:
6
+ metadata.gz: 81972fe09647ebfd9f499cacd030470f4cc0e1ab2c8b978d7d274a7dc0ae18ade7f1b05fbbdc94aebfe7f05230d9778e91777a66fd6523d4ebaf1d569cff6e7d
7
+ data.tar.gz: d16c7a57cf77eecc0552a4f020ff302578cdd74defe6b338fdee1e783b9056b895675a7d0c7ae4df254c530bc23487c4ee625fcb45b5c30107e9635bc06ccae6
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+ *.swo
16
+
17
+ ## PROJECT::GENERAL
18
+ coverage
19
+ rdoc
20
+ pkg
21
+
22
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jason Stewart
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.
data/README ADDED
@@ -0,0 +1,73 @@
1
+ Ezprint
2
+ =======
3
+
4
+ Ezprint is a drop in replacement for the princely plugin. It uses PDFKit
5
+ as the backend instead pf princexml, possibly saving you millions of
6
+ dollars. I recommend using the Rack middleware component of PDFKit to
7
+ print PDFs in rails, but this plugin makes an easy transition from
8
+ prince->PDFKit for those using princely.
9
+
10
+ Historian
11
+ =======
12
+
13
+ gem 'historian_ezprint', '~> 1.0', :require => 'delayed_job_data_mapper'
14
+
15
+
16
+ Installation
17
+ ============
18
+
19
+ Rails 2.x
20
+
21
+ gem install ezprint
22
+ in environment.rb config.gem "ezprint"
23
+
24
+ Rails 3
25
+
26
+ gem 'ezprint', :git => 'git@github.com:jstewart/ezprint.git', :branch => 'rails3', :require => 'ezprint'
27
+ then run "bundle install"
28
+
29
+ Example
30
+ =======
31
+
32
+ The examples here are similar to princely, since the
33
+ plugin is basically a reworking of the princely source
34
+
35
+ class PDFExample < ApplicationController
36
+ def show
37
+ respond_to do |format|
38
+ format.html
39
+ format.pdf do
40
+ render :pdf => "My Awesome PDF",
41
+ :template => "controller/action.pdf.erb",
42
+ :stylesheets => ["application","print"]
43
+ :layout => "pdf"
44
+ end
45
+ end
46
+ end
47
+
48
+ # Alternatively, you can use make_and_send_pdf to
49
+ # render out a PDF for the action without a
50
+ # respond_to block.
51
+ def pdf
52
+ make_and_send_pdf("file_name")
53
+ end
54
+ end
55
+
56
+ Render Defaults
57
+ ===============
58
+
59
+ The defaults for the render options are as follows:
60
+
61
+ layout: false
62
+ template: the template for the current controller/action
63
+ stylesheets: none
64
+
65
+ Credits
66
+ =======
67
+
68
+ Michael Bleigh for writing the awesome princely plugin, which most of the code is reworked from.
69
+
70
+ Resources
71
+ =========
72
+
73
+ Copyright (c) 2010 Jason Stewart, released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rubygems/tasks'
3
+ require 'rake'
4
+
5
+ Gem::Tasks.new
6
+
7
+ require 'rake/testtask'
8
+ Rake::TestTask.new(:test) do |test|
9
+ test.libs << 'lib' << 'test'
10
+ test.pattern = 'test/**/*_test.rb'
11
+ test.verbose = true
12
+ end
13
+
14
+ task :default => :test
data/ezprint.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{historian_ezprint}
3
+ s.version = "0.2.1"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Jason Stewart"]
7
+ s.date = %q{2010-07-26}
8
+ s.description = %q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
9
+ s.email = %q{jstewart@fusionary.com}
10
+ s.extra_rdoc_files = ["LICENSE", "README"]
11
+ s.files = [
12
+ ".gitignore",
13
+ "LICENSE",
14
+ "README",
15
+ "Rakefile",
16
+ "ezprint.gemspec",
17
+ "lib/ezprint.rb",
18
+ "lib/ezprint/pdf_helper.rb",
19
+ "lib/ezprint/railtie.rb"
20
+ ]
21
+ s.homepage = %q{http://github.com/l33t-historian/historian_ezprint}
22
+ s.rdoc_options = ["--charset=UTF-8"]
23
+ s.require_paths = ["lib"]
24
+ s.rubygems_version = %q{1.3.7}
25
+ s.summary = %q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
26
+
27
+ if s.respond_to? :specification_version then
28
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
29
+ s.specification_version = 3
30
+
31
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
32
+ s.add_runtime_dependency(%q<pdfkit>, [">= 0.4.1"])
33
+ else
34
+ s.add_dependency(%q<pdfkit>, [">= 0.4.1"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<pdfkit>, [">= 0.4.1"])
38
+ end
39
+ end
data/lib/ezprint.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ezprint/railtie'
@@ -0,0 +1,52 @@
1
+ require 'pdfkit'
2
+
3
+ module EzPrint
4
+ module PdfHelper
5
+
6
+ include ActionView::Helpers::AssetTagHelper
7
+
8
+ def self.included(base)
9
+ base.class_eval do
10
+ alias_method_chain :render, :ezprint
11
+ end
12
+ end
13
+
14
+ def render_with_ezprint(options = nil, *args, &block)
15
+ if options.is_a?(Symbol) or options.nil? or options[:pdf].nil?
16
+ render_without_ezprint(options, *args, &block)
17
+ else
18
+ options[:name] ||= options.delete(:pdf)
19
+ make_and_send_pdf(options.delete(:name), options)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def make_pdf(options = {})
26
+ options[:layout] ||= false
27
+ options[:template] ||= File.join(controller_path,action_name)
28
+ options[:stylesheets] ||= []
29
+
30
+ # Stop Rails from appending timestamps to assets.
31
+ ENV["RAILS_ASSET_ID"] = ''
32
+ html_string = render_to_string(:template => options[:template], :layout => options[:layout])
33
+
34
+ kit = PDFKit.new(process_html_string(html_string))
35
+ kit.stylesheets = options[:stylesheets].collect{ |style| "#{Rails.root.to_s}/public/stylesheets/#{style}.css" }
36
+
37
+ kit.to_pdf
38
+ end
39
+
40
+ def make_and_send_pdf(pdf_name, options = {})
41
+ send_data(
42
+ make_pdf(options),
43
+ :filename => pdf_name + ".pdf",
44
+ :type => 'application/pdf'
45
+ )
46
+ end
47
+
48
+ def process_html_string(html)
49
+ html.gsub("src=\"/","src=\"#{Rails.root.to_s}/public/") # reroute absolute paths
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ require 'action_controller/base'
2
+ require 'action_dispatch/http/mime_types'
3
+ require 'ezprint/pdf_helper'
4
+
5
+ class Railtie < Rails::Railtie
6
+
7
+ initializer :init_mime_types do
8
+ Mime::Type.register 'application/pdf', :pdf
9
+ end
10
+
11
+ initializer :insert_into_action_controller do
12
+ ActiveSupport.on_load :action_controller do
13
+ ActionController::Base.send(:include, EzPrint::PdfHelper)
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: historian_ezprint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason Stewart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pdfkit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.1
27
+ description: A Rails wrapper for the PDFkit library. Meant to be a drop in replacement
28
+ for princely.
29
+ email: jstewart@fusionary.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ - README
35
+ files:
36
+ - ".gitignore"
37
+ - LICENSE
38
+ - README
39
+ - Rakefile
40
+ - ezprint.gemspec
41
+ - lib/ezprint.rb
42
+ - lib/ezprint/pdf_helper.rb
43
+ - lib/ezprint/railtie.rb
44
+ homepage: http://github.com/l33t-historian/historian_ezprint
45
+ licenses: []
46
+ metadata: {}
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
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.4.8
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: A Rails wrapper for the PDFkit library. Meant to be a drop in replacement
68
+ for princely.
69
+ test_files: []