Module: RTeX::Framework::Rails::ControllerMethods

Defined in:
lib/rtex/framework/rails.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



32
33
34
# File 'lib/rtex/framework/rails.rb', line 32

def self.included(base) #:nodoc:
  base.alias_method_chain :render, :rtex
end

Instance Method Details

#render_with_rtex(options = nil, extra_options = {}, &block) ⇒ Object

Extends the base ActionController#render method by checking whether the template is RTeX-capable and creating an RTeX::Document in that case.

If you have view templates saved, for example, as “show.html.erb” and “show.pdf.rtex” in an ItemsController, one could write the controller action like this:

def show
  # set up instance variables
  # ...
  respond_to do |format|
    format.html
    format.pdf { render :filename => "Item Information.pdf" }
  end
end

As well as the options available to a new RTeX::Document, the following may be supplied here:

:disposition

‘inline’ (default) or ‘attachment’

:filename

nil (default) results in the final part of the request URL being used.

To see the underlying LaTeX code that generated the PDF, create another view called “show.tex.rtex” which includes the single line

<%= include_template_from "items/show.pdf.rtex" -%>

and include the following in the controller action

format.tex { render :filename => "item_information_source.tex" }

This may be helpful during debugging or for saving pre-compiled parts of LaTeX documents for later processing into PDFs.



72
73
74
75
76
77
78
# File 'lib/rtex/framework/rails.rb', line 72

def render_with_rtex(options=nil, extra_options={}, &block)
  if conditions_for_rtex(options)
    render_rtex(default_template, options, extra_options, &block)
  else
    render_without_rtex(options, extra_options, &block)
  end
end