Class: Baren::PjsTemplate

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/baren.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/baren.rb', line 27

def evaluate(scope, locals, &block)
  require "tempfile"
  dataURL = Tempfile.open("pjs2png") do |f|
    f.print Tilt.new(PhantomJs.pjs2png_path).render(nil, :pjs => data.inspect, :processingjs => File.read(ProcessingJs.path).inspect)
    f.flush
    case RUBY_PLATFORM
    when /linux/
      cmd = "xvfb-run #{PhantomJs.path} #{f.path}"
    else
      cmd = "#{PhantomJs.path} #{f.path}"
    end
    `#{cmd}`
  end
  if encodedImage = dataURL[%r"data:image/png;base64,(.*)",1]
    require "base64"
    @output ||= Base64.decode64(encodedImage)
  else
    raise Baren::ProcessingJsError, dataURL
  end
end

#prepareObject

self.default_mime_type = ‘image/png’



24
25
# File 'lib/baren.rb', line 24

def prepare
end