ezprint 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -17,7 +17,7 @@ in environment.rb config.gem "ezprint"
17
17
 
18
18
  Rails 3
19
19
 
20
- gem 'ezprint', :git => 'git@github.com:jstewart/ezprint.git', :branch => 'rails3', :require => 'ezprint'
20
+ gem 'ezprint'
21
21
  then run "bundle install"
22
22
 
23
23
  Example
data/README.rdoc CHANGED
@@ -16,7 +16,7 @@ in environment.rb config.gem "ezprint"
16
16
 
17
17
  == Rails 3
18
18
 
19
- gem 'ezprint', :git => 'git@github.com:jstewart/ezprint.git', :branch => 'rails3', :require => 'ezprint'
19
+ gem 'ezprint'
20
20
 
21
21
  then run "bundle install"
22
22
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/ezprint.gemspec CHANGED
@@ -1,37 +1,35 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ezprint}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jason Stewart"]
12
- s.date = %q{2010-11-08}
12
+ s.date = %q{2011-01-04}
13
13
  s.description = %q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
14
14
  s.email = %q{jstewart@fusionary.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "MIT-LICENSE",
23
- "README",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "ezprint.gemspec",
28
- "init.rb",
29
- "lib/ezprint.rb",
30
- "lib/ezprint/pdf_helper.rb",
31
- "rails/init.rb"
21
+ "MIT-LICENSE",
22
+ "README",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "ezprint.gemspec",
27
+ "init.rb",
28
+ "lib/ezprint.rb",
29
+ "lib/ezprint/pdf_helper.rb",
30
+ "lib/ezprint/railtie.rb"
32
31
  ]
33
32
  s.homepage = %q{http://github.com/jstewart/ezprint}
34
- s.rdoc_options = ["--charset=UTF-8"]
35
33
  s.require_paths = ["lib"]
36
34
  s.rubygems_version = %q{1.3.7}
37
35
  s.summary = %q{A Rails wrapper for the PDFkit library. Meant to be a drop in replacement for princely.}
data/init.rb CHANGED
@@ -1 +1 @@
1
- require File.dirname(__FILE__) + '/rails/init'
1
+ require File.join(File.dirname(__FILE__), "lib", "ezprint")
data/lib/ezprint.rb CHANGED
@@ -1 +1,9 @@
1
1
  require 'ezprint/pdf_helper'
2
+
3
+ if defined?(::Rails::Railtie)
4
+ require 'ezprint/railtie'
5
+ else
6
+ # Rails 2.x
7
+ Mime::Type.register 'application/pdf', :pdf
8
+ ActionController::Base.send(:include, EzPrint::PdfHelper)
9
+ end
@@ -1,52 +1,58 @@
1
- module PdfHelper
2
- require 'pdfkit'
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- alias_method_chain :render, :ezprint
7
- end
8
- end
9
-
10
- def render_with_ezprint(options = nil, *args, &block)
11
- if options.is_a?(Symbol) or options.nil? or options[:pdf].nil?
12
- render_without_ezprint(options, *args, &block)
13
- else
14
- options[:name] ||= options.delete(:pdf)
15
- make_and_send_pdf(options.delete(:name), options)
1
+ module EzPrint
2
+ module PdfHelper
3
+ require 'pdfkit'
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ alias_method_chain :render, :ezprint
8
+ end
16
9
  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
10
 
26
- # Stop Rails from appending timestamps to assets.
27
- ENV["RAILS_ASSET_ID"] = ''
28
- html_string = render_to_string(:template => options[:template], :layout => options[:layout])
11
+ def render_with_ezprint(options = nil, *args, &block)
12
+ if options.is_a?(Symbol) or options.nil? or options[:pdf].nil?
13
+ render_without_ezprint(options, *args, &block)
14
+ else
15
+ options[:name] ||= options.delete(:pdf)
16
+ make_and_send_pdf(options.delete(:name), options)
17
+ end
18
+ end
29
19
 
30
- kit = PDFKit.new(process_html_string(html_string))
31
- kit.stylesheets = options[:stylesheets].collect{ |style| stylesheet_file_path(style) }
20
+ private
32
21
 
33
- kit.to_pdf
34
- end
22
+ def make_pdf(options = {})
23
+ options[:stylesheets] ||= []
24
+ options[:layout] ||= false
25
+ options[:template] ||= File.join(controller_path,action_name)
35
26
 
36
- def make_and_send_pdf(pdf_name, options = {})
37
- send_data(
38
- make_pdf(options),
39
- :filename => pdf_name + ".pdf",
40
- :type => 'application/pdf'
41
- )
42
- end
43
-
44
- def stylesheet_file_path(stylesheet)
45
- stylesheet = stylesheet.to_s.gsub(".css","")
46
- File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR,"#{stylesheet}.css")
47
- end
27
+ # Stop Rails from appending timestamps to assets.
28
+ ENV["RAILS_ASSET_ID"] = ''
29
+ html_string = render_to_string(:template => options[:template], :layout => options[:layout])
48
30
 
49
- def process_html_string(html)
50
- html.gsub!("src=\"/","src=\"#{RAILS_ROOT}/public/") # reroute absolute paths
31
+ kit = PDFKit.new(process_html_string(html_string))
32
+ kit.stylesheets = options[:stylesheets].collect{ |style| stylesheet_file_path(style) }
33
+
34
+ kit.to_pdf
35
+ end
36
+
37
+ def make_and_send_pdf(pdf_name, options = {})
38
+ send_data(
39
+ make_pdf(options),
40
+ :filename => pdf_name + ".pdf",
41
+ :type => 'application/pdf'
42
+ )
43
+ end
44
+
45
+ def stylesheet_file_path(stylesheet)
46
+ stylesheet = stylesheet.to_s.gsub(".css","")
47
+ File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR,"#{stylesheet}.css")
48
+ end
49
+
50
+ def process_html_string(html)
51
+ # reroute absolute paths
52
+ html.gsub!("src=\"/", "src=\"#{RAILS_ROOT}/public/")
53
+ html.gsub!("href=\"/", "src=\"#{RAILS_ROOT}/public/")
54
+ html.gsub!("url(/", "url(#{RAILS_ROOT}/public/")
55
+ html
56
+ end
51
57
  end
52
58
  end
@@ -0,0 +1,18 @@
1
+ require 'action_controller/base'
2
+ require 'action_dispatch/http/mime_types'
3
+ require 'ezprint/pdf_helper'
4
+
5
+ module EzPrint
6
+ class Railtie < Rails::Railtie
7
+
8
+ initializer :init_mime_types do
9
+ Mime::Type.register 'application/pdf', :pdf
10
+ end
11
+
12
+ initializer :insert_into_action_controller do
13
+ ActiveSupport.on_load :action_controller do
14
+ ActionController::Base.send(:include, EzPrint::PdfHelper)
15
+ end
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezprint
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Stewart
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-08 00:00:00 -05:00
18
+ date: 2011-01-04 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,7 +45,6 @@ extra_rdoc_files:
45
45
  - README.rdoc
46
46
  files:
47
47
  - .document
48
- - .gitignore
49
48
  - MIT-LICENSE
50
49
  - README
51
50
  - README.rdoc
@@ -55,14 +54,14 @@ files:
55
54
  - init.rb
56
55
  - lib/ezprint.rb
57
56
  - lib/ezprint/pdf_helper.rb
58
- - rails/init.rb
57
+ - lib/ezprint/railtie.rb
59
58
  has_rdoc: true
60
59
  homepage: http://github.com/jstewart/ezprint
61
60
  licenses: []
62
61
 
63
62
  post_install_message:
64
- rdoc_options:
65
- - --charset=UTF-8
63
+ rdoc_options: []
64
+
66
65
  require_paths:
67
66
  - lib
68
67
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,22 +0,0 @@
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/rails/init.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'ezprint/pdf_helper'
2
-
3
- Mime::Type.register 'application/pdf', :pdf
4
- ActionController::Base.send(:include, PdfHelper)