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



29
30
31
# File 'lib/rtex/framework/rails.rb', line 29

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

Instance Method Details

#render_with_rtex(options = nil, *args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rtex/framework/rails.rb', line 33

def render_with_rtex(options=nil, *args, &block)
  result = render_without_rtex(options, *args, &block)
  if result.is_a?(String) && Thread.current[:_rendering_rtex]
    Thread.current[:_rendering_rtex] = false
    options ||= {}
    ::RTeX::Document.new(result, options.merge(:processed => true)).to_pdf do |filename|
      serve_file = Tempfile.new('rtex-pdf')
      FileUtils.mv filename, serve_file.path
      send_file serve_file.path,
        :disposition => (options[:disposition] rescue nil) || 'inline',
        :url_based_filename => true,
        :filename => (options[:filename] rescue nil),
        :type => "application/pdf",
        :length => File.size(serve_file.path)
      serve_file.close
    end
  else
    result
  end
  
end