Skip to content

Commit

Permalink
added tidy support for cleanup html
Browse files Browse the repository at this point in the history
  • Loading branch information
Amar Daxini committed Oct 19, 2011
1 parent 7dc228f commit 41c23a1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ It accepts the same options as ActionController::Base#render plus the following
:password attach password for generated pdf

:debug_html - (boolean expected) generates html output to the browser for debugging purposes

:clean It cleans up html using tidy (It uses tidy_ffi gem)

class FooController < ActionController::Base
acts_as_flying_saucer
Expand Down
1 change: 1 addition & 0 deletions acts_as_flying_saucer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Gem::Specification.new do |s|
s.summary = %q{XHTML to PDF using Flying Saucer java library}
s.description = %q{XHTML to PDF using Flying Saucer java library}
s.add_dependency "nailgun"
s.add_dependency "tidy_ffi"
s.rubyforge_project = "acts_as_flying_saucer"

s.files = `git ls-files`.split("\n")
Expand Down
1 change: 1 addition & 0 deletions lib/acts_as_flying_saucer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'acts_as_flying_saucer/xhtml2pdf'
require 'acts_as_flying_saucer/acts_as_flying_saucer_controller'
require 'nailgun'
require 'tidy_ffi'
if defined?(Rails)
ActionController::Base.send(:include, ActsAsFlyingSaucer::Controller)
elsif defined?(Sinatra)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def render_pdf(options = {})
# ActionController::Base.asset_host = request.protocol + request.host_with_port if host.blank?
#
# logger.debug("#{host} - #{host.nil?} - #{ActionController::Base.asset_host}")

tidy_clean = options[:clean] || false
self.pdf_mode = :create
if defined?(Rails)
html = render_to_string options
Expand All @@ -55,6 +55,7 @@ def render_pdf(options = {})
end
# saving the file
tmp_dir = ActsAsFlyingSaucer::Config.options[:tmp_path]
html = TidyFFI::Tidy.new(html).clean if tidy_clean
html_digest = Digest::MD5.hexdigest(html)
input_file =File.join(File.expand_path("#{tmp_dir}"),"#{html_digest}.html")

Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_flying_saucer/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActsAsFlyingSaucer
VERSION = "0.0.4"
VERSION = "0.0.5"
end

0 comments on commit 41c23a1

Please sign in to comment.