Module: RTeX::Framework::Rails::HelperMethods

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rtex_dirObject (readonly)

Obtain the temporary directory RTeX is currently using



150
151
152
# File 'lib/rtex/framework/rails.rb', line 150

def rtex_dir
  @rtex_dir
end

Instance Method Details

#graphics_data(data) ⇒ Object

Save the supplied image data to the RTeX temporary directory and return the filename for inclusion in the current document.

\includegraphics{<%= graphics_data(object.to_png) -%>}


191
192
193
194
195
# File 'lib/rtex/framework/rails.rb', line 191

def graphics_data(data)
  destination = Pathname.new(@rtex_dir) + latex_safe_filename(filename)
  File.open(destination, "w") { |f| f.write data }
  dst.to_s
end

#graphics_file(file, reference_original_file = false) ⇒ Object

Include an image file into the current LaTeX document.

For example,

\includegraphics{<%= graphics_file("some file.png") -%>}

will copy “public/images/some file.png” to a the current RTeX temporary directory (with a LaTeX-safe filename) and reference it in the document like this:

\includegraphics{/tmp/rtex/rtex-random-number/image-file.png}


173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/rtex/framework/rails.rb', line 173

def graphics_file(file, reference_original_file=false)
  source = Pathname.new file
  source = Pathname.new(ActionView::Helpers::ASSETS_DIR) + "images" + source unless source.absolute?
  
  if reference_original_file
    source.to_s
  else
    destination = Pathname.new(@rtex_dir) + latex_safe_filename(source.basename)
    FileUtils.copy source, destination
    destination.to_s
  end
end

#include_template_from(from) ⇒ Object

Copy the contents of another template into the current one, like rendering a partial but without have to add an underscore to the filename.



156
157
158
159
# File 'lib/rtex/framework/rails.rb', line 156

def include_template_from(from)
  other_file = @template.view_paths.find_template(from).relative_path
  render(:inline => File.read(other_file))
end

#latex_escape(*args) ⇒ Object Also known as: l

Make the supplied text safe for the LaTeX processor, in the same way that h() works for HTML documents.



137
138
139
140
141
142
143
144
145
146
# File 'lib/rtex/framework/rails.rb', line 137

def latex_escape(*args)
  # Since Rails' I18n implementation aliases l() to localize(), LaTeX
  # escaping should only be done if RTeX is doing the rendering.
  # Otherwise, control should be be passed to localize().
  if Thread.current[:_rendering_rtex]
    RTeX::Document.escape(*args)
  else
    localize(*args)
  end
end