Method: SlideField::Interpreter#run_file

Defined in:
lib/slidefield/interpreter.rb

#run_file(path, parent_obj = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/slidefield/interpreter.rb', line 10

def run_file(path, parent_obj = nil)
  if @files.include? path
    raise SlideField::InterpreterError,
      "File already interpreted: '#{path}'"
  else
    @files << path
  end

  file = Pathname.new path

  begin
    input = file.read
  rescue => e
    raise SlideField::InterpreterError, e.message
  end

  include_path = file.dirname.to_s
  @rootpath = Pathname.new(include_path) if parent_obj.nil? || @rootpath.nil?
  context = file.relative_path_from(@rootpath).to_s

  run_string input, include_path, context, parent_obj
end