diff --git a/CHANGELOG b/CHANGELOG index 05626d0..282045f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,11 +1,20 @@ +v2.1.0 + + Merge in rails-2.2.2 branch, modify to make sure Prawn isn't trampled and + 2.3.0 is supported. + Simplify tagging of templates for later processing (+ ensure it works + with compiled templates). + Update README_RAILS + v2.0.5 - Fix issue with Echoe being ultra-sensitive on RubyGems versions (v2.0.4 was RubyGems 1.2 only, - and 1.3 just came out) + Fix issue with Echoe being ultra-sensitive on RubyGems versions (v2.0.4 + was RubyGems 1.2 only, and 1.3 just came out) v2.0.4 - Support for TeX escaping (via l()) calling to_s on the argument. This should handle nils. + Support for TeX escaping (via l()) calling to_s on the argument. + This should handle nils. v2.0.3 diff --git a/README_RAILS.rdoc b/README_RAILS.rdoc index 64441e2..ba80c04 100644 --- a/README_RAILS.rdoc +++ b/README_RAILS.rdoc @@ -26,15 +26,22 @@ Create files +pdf.rtex+ extensions (eg, +index.pdf.rtex+) using standard LaTeX m With the following: + # In config/initializers/mime_types.rb (or environment.rb in older Rails) + Mime::Type.register "application/pdf", :pdf + # app/controllers/items_controller.rb def index @items = Item.find(:all) + respond_to do |format| + format.html # We support the normal HTML view as well + format.pdf + end end # app/views/items/index.pdf.rtex \section*{Items} \begin{itemize} - <%= render :partial => @items %> + <%= render :partial => @items %> \end{itemize} # app/views/items/_item.pdf.rtex @@ -43,7 +50,7 @@ With the following: # app/layouts/application.pdf.rtex \documentclass[12pt]{article} \begin{document} - <%= yield %> + <%= yield %> \end{document} If you hit +http://the.server.url/items.pdf+, you end up with a nice PDF listing of items. diff --git a/lib/rtex/framework/rails.rb b/lib/rtex/framework/rails.rb index 6ea8823..c518ec5 100644 --- a/lib/rtex/framework/rails.rb +++ b/lib/rtex/framework/rails.rb @@ -7,30 +7,21 @@ module Rails #:nodoc: def self.setup RTeX::Document.options[:tempdir] = File.expand_path(File.join(RAILS_ROOT, 'tmp')) if ActionView::Base.respond_to?(:register_template_handler) - ActionView::Base.register_template_handler(:rtex, Template) + ActionView::Base.register_template_handler(:rtex, TemplateHandler) else - # Rails 2.1 - ActionView::Template.register_template_handler(:rtex, Template) + ActionView::Template.register_template_handler(:rtex, TemplateHandler) end ActionController::Base.send(:include, ControllerMethods) ActionView::Base.send(:include, HelperMethods) end - class Template < ::ActionView::TemplateHandlers::ERB - def initialize(*args) - super - # Support Rails render API before: - # commit d2ccb852d4e1f6f1b01e43f32213053ae3bef408 - # Date: Fri Jul 18 16:00:20 2008 -0500 - if @view - @view.template_format = :pdf - end - # Tag for RTeX - # TODO: Move options into TemplateHandler from Controller - # (need to handle send_file) - def @view.rendered_with_rtex - true - end + class TemplateHandler < ::ActionView::TemplateHandlers::ERB + # Due to significant changes in ActionView over the lifespan of Rails, + # tagging compiled templates to set a thread local variable flag seems + # to be the least brittle approach. + def compile(template) + # Insert assignment, but not before the #coding: line, if present + super.sub(/^(?!#)/m, "Thread.current[:_rendering_rtex] = true;\n") end end @@ -41,7 +32,7 @@ def self.included(base) def render_with_rtex(options=nil, *args, &block) result = render_without_rtex(options, *args, &block) - if result.is_a?(String) && @template.template_format.to_s == 'pdf' + if result.is_a?(String) && Thread.current[:_rendering_rtex] options ||= {} ::RTeX::Document.new(result, options.merge(:processed => true)).to_pdf do |filename| serve_file = Tempfile.new('rtex-pdf') @@ -54,13 +45,13 @@ def render_with_rtex(options=nil, *args, &block) :length => File.size(serve_file.path) serve_file.close end - else - result end + end end module HelperMethods + # Similar to h() def latex_escape(s) RTeX::Document.escape(s) end diff --git a/lib/rtex/version.rb b/lib/rtex/version.rb index 272b8ea..b6d3da3 100644 --- a/lib/rtex/version.rb +++ b/lib/rtex/version.rb @@ -64,8 +64,8 @@ def to_a end MAJOR = 2 - MINOR = 0 - TINY = 5 + MINOR = 1 + TINY = 0 # The current version as a Version instance CURRENT = new(MAJOR, MINOR, TINY)