diff --git a/Gemfile b/Gemfile index d713361e..d1aa7add 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem 'jquery-rails' gem 'mysql2' gem "fastercsv" gem "prawn", '<=0.6.3' +gem 'prawnto_2', :require => "prawnto" # Used for prawn view templates gem 'haml-rails' gem "will_paginate", "~> 3.0.pre2" gem 'client_side_validations' diff --git a/Gemfile.lock b/Gemfile.lock index cb7d2cd9..59307ee9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,6 +100,9 @@ GEM prawn-core prawn-layout (0.3.2) prawn-security (0.1.1) + prawnto_2 (0.2.5) + prawn (>= 0.6.0) + rails (>= 3.1) rack (1.4.1) rack-cache (1.2) rack (>= 0.4) @@ -174,6 +177,7 @@ DEPENDENCIES meta_search mysql2 prawn (<= 0.6.3) + prawnto_2 rails (= 3.2.8) rails3_acts_as_paranoid (~> 0.1.4) sass-rails (~> 3.2.3) diff --git a/vendor/plugins/prawnto/.gitignore b/vendor/plugins/prawnto/.gitignore deleted file mode 100644 index 02a5d1a8..00000000 --- a/vendor/plugins/prawnto/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.DS_Store -**/*.swp -reference_pdfs diff --git a/vendor/plugins/prawnto/MIT-LICENSE b/vendor/plugins/prawnto/MIT-LICENSE deleted file mode 100644 index 497d7c5a..00000000 --- a/vendor/plugins/prawnto/MIT-LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2008 cracklabs.com - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/plugins/prawnto/README b/vendor/plugins/prawnto/README deleted file mode 100644 index 6593a690..00000000 --- a/vendor/plugins/prawnto/README +++ /dev/null @@ -1,12 +0,0 @@ -Prawnto -======= - -a rails (2.1) plugin, providing templating abilities -for generating pdf files leveraging the new kick-ass prawn library - -full documentation/demos at: http://cracklabs.com/prawnto - - - - -Copyright (c) 2008 cracklabs.com, released under the MIT license diff --git a/vendor/plugins/prawnto/Rakefile b/vendor/plugins/prawnto/Rakefile deleted file mode 100644 index 9d998d11..00000000 --- a/vendor/plugins/prawnto/Rakefile +++ /dev/null @@ -1,22 +0,0 @@ -require 'rake' -require 'rake/testtask' -require 'rake/rdoctask' - -desc 'Default: run unit tests.' -task :default => :test - -desc 'Test the prawnto plugin.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.pattern = 'test/**/*_test.rb' - t.verbose = true -end - -desc 'Generate documentation for the prawnto plugin.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'Prawnto' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('lib/**/*.rb') -end diff --git a/vendor/plugins/prawnto/init.rb b/vendor/plugins/prawnto/init.rb deleted file mode 100644 index c8cf1dd9..00000000 --- a/vendor/plugins/prawnto/init.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'prawnto' - -Mime::Type.register "application/pdf", :pdf -ActionView::Template.register_template_handler 'prawn', Prawnto::TemplateHandlers::Base -ActionView::Template.register_template_handler 'prawn_dsl', Prawnto::TemplateHandlers::Dsl -ActionView::Template.register_template_handler 'prawn_xxx', Prawnto::TemplateHandlers::Raw - diff --git a/vendor/plugins/prawnto/lib/prawnto.rb b/vendor/plugins/prawnto/lib/prawnto.rb deleted file mode 100644 index d065deee..00000000 --- a/vendor/plugins/prawnto/lib/prawnto.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'action_controller' -require 'action_view' - -require 'prawn' -require 'prawnto/action_controller' -require 'prawnto/action_view' - -require 'prawnto/template_handler/compile_support' - -require 'prawnto/template_handlers/base' -require 'prawn/layout' # Added by benni -#require 'prawnto/template_handlers/raw' - -# for now applying to all Controllers -# however, could reduce footprint by letting user mixin (i.e. include) only into controllers that need it -# but does it really matter performance wise to include in a controller that doesn't need it? doubtful-- depends how much of a hit the before_filter is i guess.. -# - -class ActionController::Base - include Prawnto::ActionController -end - -class ActionView::Base - include Prawnto::ActionView -end - - - diff --git a/vendor/plugins/prawnto/lib/prawnto/action_controller.rb b/vendor/plugins/prawnto/lib/prawnto/action_controller.rb deleted file mode 100644 index ed33d146..00000000 --- a/vendor/plugins/prawnto/lib/prawnto/action_controller.rb +++ /dev/null @@ -1,45 +0,0 @@ -module Prawnto - module ActionController - - DEFAULT_PRAWNTO_OPTIONS = {:inline=>true} - - def self.included(base) - base.extend ClassMethods - end - - module ClassMethods - def prawnto(options) - prawn_options, prawnto_options = breakdown_prawnto_options options - write_inheritable_hash(:prawn, prawn_options) - write_inheritable_hash(:prawnto, prawnto_options) - end - - private - - def breakdown_prawnto_options(options) - prawnto_options = options.dup - prawn_options = (prawnto_options.delete(:prawn) || {}).dup - [prawn_options, prawnto_options] - end - end - - def prawnto(options) - @prawnto_options ||= DEFAULT_PRAWNTO_OPTIONS.dup - @prawnto_options.merge! options - end - - - private - - def compute_prawnto_options - @prawnto_options ||= DEFAULT_PRAWNTO_OPTIONS.dup - @prawnto_options[:prawn] ||= {} - @prawnto_options[:prawn].merge!(self.class.read_inheritable_attribute(:prawn) || {}) {|k,o,n| o} - @prawnto_options.merge!(self.class.read_inheritable_attribute(:prawnto) || {}) {|k,o,n| o} - @prawnto_options - end - - end -end - - diff --git a/vendor/plugins/prawnto/lib/prawnto/action_view.rb b/vendor/plugins/prawnto/lib/prawnto/action_view.rb deleted file mode 100644 index a3a77f3d..00000000 --- a/vendor/plugins/prawnto/lib/prawnto/action_view.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Prawnto - module ActionView - - private - def _prawnto_compile_setup(dsl_setup = false) - compile_support = Prawnto::TemplateHandler::CompileSupport.new(controller) - @prawnto_options = compile_support.options - end - - end -end - diff --git a/vendor/plugins/prawnto/lib/prawnto/template_handler/compile_support.rb b/vendor/plugins/prawnto/lib/prawnto/template_handler/compile_support.rb deleted file mode 100644 index 3a45b8b6..00000000 --- a/vendor/plugins/prawnto/lib/prawnto/template_handler/compile_support.rb +++ /dev/null @@ -1,72 +0,0 @@ -module Prawnto - module TemplateHandler - - class CompileSupport - extend ActiveSupport::Memoizable - - attr_reader :options - - def initialize(controller) - @controller = controller - @options = pull_options - set_headers - end - - def pull_options - @controller.send :compute_prawnto_options || {} - end - - def set_headers - set_pragma - set_cache_control - set_content_type - set_disposition - end - - # TODO: kept around from railspdf-- maybe not needed anymore? should check. - def ie_request? - @controller.request.env['HTTP_USER_AGENT'] =~ /msie/i - end - memoize :ie_request? - - # added to make ie happy with ssl pdf's (per naisayer) - def ssl_request? - @controller.request.env['SERVER_PROTOCOL'].downcase == "https" - end - memoize :ssl_request? - - # TODO: kept around from railspdf-- maybe not needed anymore? should check. - def set_pragma - if ssl_request? && ie_request? - @controller.headers['Pragma'] = 'public' # added to make ie ssl pdfs work (per naisayer) - else - @controller.headers['Pragma'] ||= ie_request? ? 'no-cache' : '' - end - end - - # TODO: kept around from railspdf-- maybe not needed anymore? should check. - def set_cache_control - if ssl_request? && ie_request? - @controller.headers['Cache-Control'] = 'maxage=1' # added to make ie ssl pdfs work (per naisayer) - else - @controller.headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : '' - end - end - - def set_content_type - @controller.response.content_type ||= Mime::PDF - end - - def set_disposition - inline = options[:inline] ? 'inline' : 'attachment' - filename = options[:filename] ? "filename=#{options[:filename]}" : nil - @controller.headers["Content-Disposition"] = [inline,filename].compact.join(';') - end - - end - - end -end - - - diff --git a/vendor/plugins/prawnto/lib/prawnto/template_handlers/base.rb b/vendor/plugins/prawnto/lib/prawnto/template_handlers/base.rb deleted file mode 100644 index 0f148afb..00000000 --- a/vendor/plugins/prawnto/lib/prawnto/template_handlers/base.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Prawnto - module TemplateHandlers - class Base < ::ActionView::TemplateHandler - include ::ActionView::TemplateHandlers::Compilable - - def compile(template) - "_prawnto_compile_setup;" + - "pdf = Prawn::Document.new(@prawnto_options[:prawn]);" + - "#{template.source}\n" + - "pdf.render;" - end - end - end -end - - diff --git a/vendor/plugins/prawnto/lib/prawnto/template_handlers/dsl.rb b/vendor/plugins/prawnto/lib/prawnto/template_handlers/dsl.rb deleted file mode 100644 index f8458f32..00000000 --- a/vendor/plugins/prawnto/lib/prawnto/template_handlers/dsl.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Prawnto - module TemplateHandlers - class Dsl < Base - - def compile(template) - "_prawnto_compile_setup(true);" + - "pdf = Prawn::Document.new(@prawnto_options[:prawn]);" + - "pdf.instance_eval do; #{template.source}\nend;" + - "pdf.render;" - end - - end - end -end - - diff --git a/vendor/plugins/prawnto/lib/prawnto/template_handlers/raw.rb b/vendor/plugins/prawnto/lib/prawnto/template_handlers/raw.rb deleted file mode 100644 index ef2f7e01..00000000 --- a/vendor/plugins/prawnto/lib/prawnto/template_handlers/raw.rb +++ /dev/null @@ -1,64 +0,0 @@ -module Prawnto - module TemplateHandlers - class Raw < Base - - def compile(template) - #TODO: what's up with filename here? not used is it? - source,filename = massage_template_source(template) - "_prawnto_compile_setup;" + -# (filename ? "@prawnto_options[:filename] = filename" : "") + - source - end - -# attr_reader :run_environment - - GENERATE_REGULAR_EXPRESSION = /^\s*Prawn\:\:Document\.generate(\(?)(.*?)(\,(.*))?(\s*\)?\s+do(.*?))$/m - RENDER_FILE_REGULAR_EXPRESSION = /(\w+)\.render_file\(?(.*?)\)?\s*$/ - -=begin - def render(template) - setup_run_environment - pull_prawnto_options - source,filename = massage_template_source(template) - @prawnto_options[:filename] = filename if filename - build_headers - @run_environment.instance_eval(source, template.filename, 0) #run in anonymous class - end - - - protected - - def setup_run_environment - @run_environment = Object.new - end - -=end - protected - def massage_template_source(template) - source = template.source.dup - variable_name = '_pdf' - filename = nil - - source.gsub! /^(\s*?)(\$LOAD_PATH)/, '\1#\2' - source.gsub! /^(\s*?)(require\(?\s*['"]rubygems['"]\s*\)?\s*)$/, '\1#\2' - source.gsub! /^(\s*?)(require\(?\s*['"]prawn['"]\s*\)?\s*)$/, '\1#\2' - - if (source =~ GENERATE_REGULAR_EXPRESSION) - filename = $2 - source.sub! GENERATE_REGULAR_EXPRESSION, "#{variable_name} = Prawn::Document.new\\1\\4\\5" - elsif (source =~ RENDER_FILE_REGULAR_EXPRESSION) - variable_name = $1 - filename = $2 - source.sub! RENDER_FILE_REGULAR_EXPRESSION, '#\0' - end - source.gsub! /^(\s*)(class\s|def\s).*?\n\1end/m do |match| - eval "class <<@run_environment; #{match}; end;" - "\n" * match.count("\n") - end - source += "\n[#{variable_name}.render,#{filename}]\n" - source - end - - end - end -end diff --git a/vendor/plugins/prawnto/tasks/prawnto_tasks.rake b/vendor/plugins/prawnto/tasks/prawnto_tasks.rake deleted file mode 100644 index e02240d1..00000000 --- a/vendor/plugins/prawnto/tasks/prawnto_tasks.rake +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :prawnto do -# # Task goes here -# end diff --git a/vendor/plugins/prawnto/test/action_controller_test.rb b/vendor/plugins/prawnto/test/action_controller_test.rb deleted file mode 100644 index 29718cf7..00000000 --- a/vendor/plugins/prawnto/test/action_controller_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'rubygems' -require 'action_controller' -require 'action_controller/test_process' -require 'action_view' - -require 'test/unit' -require File.dirname(__FILE__) + '/../lib/prawnto' - - -class ActionControllerTest < Test::Unit::TestCase - class PrawntoController < ActionController::Base - prawnto :inline=>true, :prawn=>{:page_orientation=>:landscape} - - def test - prawnto :inline=>false, :prawn=>{:page_size=>'A4'} - end - end - - def test_inheritable_options - assert_equal({:page_orientation=>:landscape}, PrawntoController.read_inheritable_attribute(:prawn)) - assert_equal({:inline=>true}, PrawntoController.read_inheritable_attribute(:prawnto)) - end - - def test_computed_options - controller = PrawntoController.new - test_process(controller) - assert_equal({:inline=>false, :prawn=>{:page_orientation=>:landscape, :page_size=>'A4'}}, controller.send(:compute_prawnto_options)) - end - -protected - def test_process(controller, action = "test") - request = ActionController::TestRequest.new - request.action = action - controller.process(request, ActionController::TestResponse.new) - end - -end - diff --git a/vendor/plugins/prawnto/test/base_template_handler_test.rb b/vendor/plugins/prawnto/test/base_template_handler_test.rb deleted file mode 100644 index 9b30f52d..00000000 --- a/vendor/plugins/prawnto/test/base_template_handler_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'rubygems' -require 'test/unit' -require File.dirname(__FILE__) + '/template_handler_test_mocks' -require File.dirname(__FILE__) + '/../lib/prawnto' -#require File.dirname(__FILE__) + '/../init' - - -#TODO: ruby1.9: pull same testing scheme from Raw once we're on 1.9 -class BaseTemplateHandlerTest < Test::Unit::TestCase - include TemplateHandlerTestMocks - - def setup - @view = ActionView.new - @handler = Prawnto::TemplateHandlers::Base.new(@view) - @controller = @view.controller - end - - def test_headers_disposition_inline_and_filename - @controller.prawnto :filename=>'xxx.pdf', :inline=>true - @handler.pull_prawnto_options - @handler.set_disposition - assert_equal 'inline;filename=xxx.pdf', @view.headers['Content-Disposition'] - end - - def test_headers_disposition_attachment_and_filename - @controller.prawnto :filename=>'xxx.pdf', :inline=>false - @handler.pull_prawnto_options - @handler.set_disposition - assert_equal 'attachment;filename=xxx.pdf', @view.headers['Content-Disposition'] - end - - def test_headers_disposition_default - @handler.pull_prawnto_options - @handler.set_disposition - assert_equal 'inline', @view.headers['Content-Disposition'] - end - -end - diff --git a/vendor/plugins/prawnto/test/dsl_template_handler_test.rb b/vendor/plugins/prawnto/test/dsl_template_handler_test.rb deleted file mode 100644 index 6033e215..00000000 --- a/vendor/plugins/prawnto/test/dsl_template_handler_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'rubygems' -require 'test/unit' -require File.dirname(__FILE__) + '/template_handler_test_mocks' -require File.dirname(__FILE__) + '/../lib/prawnto' -#require File.dirname(__FILE__) + '/../init' - - -#TODO: ruby1.9: pull same testing scheme from Raw once we're on 1.9 -class DslTemplateHandlerTest < Test::Unit::TestCase - include TemplateHandlerTestMocks - - def setup - @view = ActionView.new - @handler = Prawnto::TemplateHandlers::Dsl.new(@view) - @controller = @view.controller - end - - def test_prawnto_options_dsl_hash - @y = 3231; @x = 5322 - @controller.prawnto :dsl=> {'x'=>:@x, :y=>'@y'} - @handler.pull_prawnto_options - source = @handler.build_source_to_establish_locals(Template.new("")) - - assert_equal @x, eval(source + "\nx") - assert_equal @y, eval(source + "\ny") - end - - def test_prawnto_options_dsl_array - @y = 3231; @x = 5322 - @controller.prawnto :dsl=> ['x', :@y] - @handler.pull_prawnto_options - source = @handler.build_source_to_establish_locals(Template.new("")) - - assert_equal @x, eval(source + "\nx") - assert_equal @y, eval(source + "\ny") - end - - -end - diff --git a/vendor/plugins/prawnto/test/raw_template_handler_test.rb b/vendor/plugins/prawnto/test/raw_template_handler_test.rb deleted file mode 100644 index ba44c772..00000000 --- a/vendor/plugins/prawnto/test/raw_template_handler_test.rb +++ /dev/null @@ -1,163 +0,0 @@ -# uncomment and edit below if you want to get off gem version -#$LOAD_PATH.unshift '~/cracklabs/vendor/gems/prawn-0.0.0.1/lib/' #to force picup of latest prawn (instead of stable gem) - -require 'rubygems' -require 'action_controller' -require 'action_view' - -require 'test/unit' -require File.dirname(__FILE__) + '/../lib/prawnto' -require File.dirname(__FILE__) + '/template_handler_test_mocks' - - -class RawTemplateHandlerTest < Test::Unit::TestCase - include TemplateHandlerTestMocks - class ::ApplicationHelper - end - - def setup - @view = ActionView.new - @handler = Prawnto::TemplateHandlers::Raw.new(@view) - end - - - def test_massage_template_source_header_comments - expected_commented_lines = [0,2,3] - source = <true - INPUTS.each do |path| - pre_brood = INPUT_PATH.children - cd INPUT_PATH - system("ruby #{path.basename}") - post_brood = INPUT_PATH.children - new_kids = post_brood - pre_brood - new_kids.each {|p| mv p, REFERENCE_PATH + p.basename} - cd CURRENT_PATH - end - cp head_version, current_version - end - else - puts "\n reference pdfs are current-- continuing...\n" - end - end - - #TODO: ruby 1.9: uncomment below line when on 1.9 - #ensure_reference_pdfs_are_recent - - - def assert_renders_correctly(name, path) - input_source = path.read - output_source = @handler.compile(Template.new(input_source)) - value = @view.instance_eval output_source - reference = (REFERENCE_PATH + @view.prawnto_options[:filename]).read - - message = "template: #{name}\n" - message += ">"*30 + " original template: " + ">"*20 + "\n" - message += input_source + "\n"*2 - message += ">"*30 + " manipulated template: " + ">"*20 + "\n" - message += output_source + "\n" + "<"*60 + "\n" - - assert_equal reference, value, message - end - - #!!! Can't actually verify pdf equality until ruby 1.9 - # (cuz hash orders are messed up otherwise and no other way to test equality at the moment) - INPUTS.each do |path| - name = path.basename('.rb') - define_method "test_template_should_render_correctly [template: #{name}] " do - # assert_renders_correctly name, path - assert true - end - end - - - - -end - diff --git a/vendor/plugins/prawnto/test/template_handler_test_mocks.rb b/vendor/plugins/prawnto/test/template_handler_test_mocks.rb deleted file mode 100644 index c7b0ed41..00000000 --- a/vendor/plugins/prawnto/test/template_handler_test_mocks.rb +++ /dev/null @@ -1,77 +0,0 @@ -require 'rubygems' -require File.dirname(__FILE__) + '/../lib/prawnto' - -module TemplateHandlerTestMocks - - class Template - attr_reader :source, :locals, :filename - - def initialize(source, locals={}) - @source = source - @locals = locals - @filename = "blah.pdf" - end - end - - - class Response - def initialize - @headers = {} - end - - def headers - @headers - end - - def content_type=(value) - end - end - - class Request - def env - {} - end - end - - class ActionController - - include Prawnto::ActionController - - def response - @response ||= Response.new - end - - def request - @request ||= Request.new - end - - def headers - response.headers - end - end - - class ActionView - def controller - @controller ||= ActionController.new - end - - def response - controller.response - end - - def request - controller.request - end - - def headers - controller.headers - end - - def prawnto_options - controller.get_instance_variable(:@prawnto_options) - end - end - - -end -