Class: M4Assets::Processor

Inherits:
Sprockets::Processor
  • Object
show all
Defined in:
lib/m4assets/processor.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(context, locals) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/m4assets/processor.rb', line 3

def evaluate(context, locals)
  stdin, stdout, stderr, wait_thr = Open3.popen3(M4Assets.config.path)
  stdin.puts(data)
  stdin.close

  # Trim dangling newline.
  stdout_output = stdout.read[0..-2]
  stderr_output = stderr.read

  # Need to close these explicitly.
  stdout.close
  stderr.close

  # Exit status is 0 for success, 1 for failure, 63 for frozen file version
  # mismatch, or whatever value was passed to the m4exit macro.
  if exitstatus = wait_thr.value.exitstatus != 0
    raise Error.new("m4 exit status #{exitstatus}. stderr: #{stderr_output}")
  end

  stdout_output
end