Module: ErbLatex::File

Defined in:
lib/erb_latex/file_access.rb

Class Method Summary collapse

Class Method Details

.evaluate(file, context_binding, directory = nil) ⇒ Object



24
25
26
# File 'lib/erb_latex/file_access.rb', line 24

def self.evaluate(file, context_binding, directory = nil)
    ::ERB.new( self.read(file, directory), 0, '-' ).result( context_binding )
end

.read(requested_file, in_directory = nil) ⇒ Object

simualar to File.read, except:

* Will search in_directory for file if given, otherwise expects file to be an absolute path
* appends ErbLatex.config.file_extension to the file if it's not found as-is.


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/erb_latex/file_access.rb', line 8

def self.read(requested_file, in_directory = nil)
    file = requested_file
    if in_directory
        file = Pathname.new(in_directory.to_s).join(file)
    end
    if file.to_s !~ /#{ErbLatex.config.file_extension}$/ && !file.exist?
        file = Pathname.new(file.to_s + ErbLatex.config.file_extension)
    end
    unless file.exist?
        msg = "Unable to read from #{requested_file}."
        msg << " Also tried extension #{file}" if file != requested_file
        raise LatexError.new(msg)
    end
    file.read
end