Skip to content

Commit

Permalink
Release v2.1.0.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Bruce Williams committed Feb 26, 2009
1 parent 3ec83f6 commit 28e42cb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
15 changes: 12 additions & 3 deletions 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

Expand Down
11 changes: 9 additions & 2 deletions README_RAILS.rdoc
Expand Up @@ -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
Expand All @@ -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.
Expand Down
33 changes: 12 additions & 21 deletions lib/rtex/framework/rails.rb
Expand Up @@ -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

Expand All @@ -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')
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/rtex/version.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 28e42cb

Please sign in to comment.