saucerly-r3 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ pkg
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tim Riley
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,46 @@
1
+ Saucerly
2
+ ========
3
+
4
+ Saucerly provides PDF rendering for your Rails app using the Java-based [FlyingSaucer](https://xhtmlrenderer.dev.java.net/) library.
5
+
6
+ It is based on [Princely](http://github.com/mbleigh/princely/). The benefit of Saucerly is that it provides competent XHTML to PDF rendering without the $4k PrinceXML pricetag.
7
+
8
+ Example
9
+ -------
10
+
11
+ Rendering from a template:
12
+
13
+ class ExamplesController < ApplicationController::Base
14
+ def show
15
+ @document = Document.find(params[:id])
16
+
17
+ respond_to do |format|
18
+ format.html
19
+ format.pdf { render :pdf => 'file_name', :template => 'controller/action.pdf.haml', :layout => 'pdf' }
20
+ end
21
+ end
22
+ end
23
+
24
+ Rendering from an inline string:
25
+
26
+ render :pdf => 'file_name', :inline => 'XHTML goes here'
27
+
28
+ Installation
29
+ ------------
30
+
31
+ First, set up the dependencies:
32
+
33
+ 1. Install [JRuby](http://jruby.org/)
34
+ 2. Register the flying_saucer gem dependency: add `config.gem 'flying_saucer'` to `config/environment.rb`
35
+ 3. Install flying_saucer: `jruby -S rake gems:install`
36
+
37
+ Then, install Saucerly:
38
+
39
+ * As a gem, add `config.gem 'joelwreed-saucerly-r3', :source => 'http://gems.github.com/', :lib => 'saucerly'` to `config/environment.rb` and run `jruby -S rake gems:install`
40
+ * As a plugin, run `jruby script/plugin install git://github.com/joelwreed/saucerly-r3`
41
+
42
+ Now you're ready to go! Add some code to your controllers like the examples above.
43
+
44
+ If you're developing on OS X and you don't want a Java icon to appear in your dock, put `java.lang.System.set_property("java.awt.headless", "true")` in `environment.rb` or an initializer
45
+
46
+ Copyright (c) 2009 Tim Riley & RentMonkey Pty Ltd, released under the MIT license
@@ -0,0 +1,38 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "saucerly-r3"
9
+ gemspec.summary = "PDF rending plugin for Rails using FlyingSaucer originally from Tim Riley, changes from Nick Sieger and Yehuda Katz for rails3."
10
+ gemspec.email = "joelwreed@gmail.com"
11
+ gemspec.homepage = "http://github.com/joelwreed/saucerly"
12
+ gemspec.authors = ["Joel Reed"]
13
+
14
+ gemspec.add_dependency('flying_saucer')
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ desc 'Default: run unit tests.'
21
+ task :default => :test
22
+
23
+ desc 'Test the saucerly plugin.'
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = true
29
+ end
30
+
31
+ desc 'Generate documentation for the saucerly plugin.'
32
+ Rake::RDocTask.new(:rdoc) do |rdoc|
33
+ rdoc.rdoc_dir = 'rdoc'
34
+ rdoc.title = 'Saucerly'
35
+ rdoc.options << '--line-numbers' << '--inline-source'
36
+ rdoc.rdoc_files.include('README')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ - turn into a gemplugin
2
+ - stop flying_saucer from polluting the logs
3
+ - add support for saving the pdf to a file?
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.1
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
@@ -0,0 +1,46 @@
1
+ require 'java'
2
+ require 'flying_saucer'
3
+ require "action_controller"
4
+ Mime::Type.register 'application/pdf', :pdf
5
+
6
+ module Saucerly
7
+ java_import org.xhtmlrenderer.pdf.ITextRenderer
8
+
9
+ module Render
10
+ def render_pdf(pdf_name, options = {})
11
+ send_data_options = {:filename => pdf_name + ".pdf", :type => 'application/pdf'}
12
+ send_data_options.merge!(options.slice(:disposition))
13
+ html_string = render_to_string(options)
14
+ send_data(Saucerly::Pdf.new(html_string).to_pdf, send_data_options)
15
+ end
16
+ end
17
+
18
+ ::ActionController::Base.send :include, Saucerly::Render
19
+ ::ActionController.add_renderer :pdf do |pdf_name, options|
20
+ render_pdf(pdf_name, options)
21
+ end if ::ActionController.respond_to?(:add_renderer)
22
+
23
+ class Pdf
24
+ def initialize(str)
25
+ @contents = str
26
+ end
27
+
28
+ def normalize!
29
+ @contents.gsub!(".com:/", ".com/") # strip out bad attachment_fu URLs
30
+ @contents.gsub!(/src=["']+([^:]+?)["']/i, %{src="#{Rails.root}/public/\\1"}) # reroute absolute paths
31
+ @contents.gsub!(/(src=["']\S+)(\?\d*)?(["'])/i, '\1\3') # remove asset ids
32
+ end
33
+
34
+ def to_pdf
35
+ normalize!
36
+ io = StringIO.new
37
+ str = @contents
38
+ ITextRenderer.new.instance_eval do
39
+ set_document_from_string(str)
40
+ layout
41
+ create_pdf(io.to_outputstream)
42
+ end
43
+ io.string
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{saucerly}
8
+ s.version = "0.5.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Joel Reed"]
12
+ s.date = %q{2010-10-20}
13
+ s.email = %q{joelwreed@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "README.md",
16
+ "TODO"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "TODO",
24
+ "VERSION",
25
+ "init.rb",
26
+ "lib/saucerly.rb",
27
+ "saucerly.gemspec"
28
+ ]
29
+ s.homepage = %q{http://github.com/joelwreed/saucerly}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.6}
33
+ s.summary = %q{PDF rending plugin for Rails using FlyingSaucer originally from Tim Riley.}
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<flying_saucer>, [">= 0"])
41
+ else
42
+ s.add_dependency(%q<flying_saucer>, [">= 0"])
43
+ end
44
+ else
45
+ s.add_dependency(%q<flying_saucer>, [">= 0"])
46
+ end
47
+ end
48
+
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: saucerly-r3
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 1
9
+ version: 0.5.1
10
+ platform: ruby
11
+ authors:
12
+ - Joel Reed
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-20 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: flying_saucer
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ description:
33
+ email: joelwreed@gmail.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - README.md
40
+ - TODO
41
+ files:
42
+ - .gitignore
43
+ - MIT-LICENSE
44
+ - README.md
45
+ - Rakefile
46
+ - TODO
47
+ - VERSION
48
+ - init.rb
49
+ - lib/saucerly.rb
50
+ - saucerly.gemspec
51
+ has_rdoc: true
52
+ homepage: http://github.com/joelwreed/saucerly
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.6
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: PDF rending plugin for Rails using FlyingSaucer originally from Tim Riley, changes from Nick Sieger and Yehuda Katz for rails3.
81
+ test_files: []
82
+