Sha256: 16260727c8d5c73d78f094825e666414a2f911681884bc6575a47de2713b91b4

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# Render using a NodeJS helper program. The Handlebars.rb bindings are tied to an old version of libv8; they render
# REALLY slowly as a result.
# This renderer calls out to a NodeJS helper program instead - so all the templating is handled in JavaScript.
module Piccle
  class JsRenderer < Renderer
    def initialize(*args)
      @renderer = IO.popen(["node", "js-renderer/renderer.js", Piccle.config.output_dir], "r+")
      super(*args)
    end

    def render_main_index
      call_nodejs("index", render_main_index_template_vars)
    end

    def render_index(selector)
      call_nodejs("index", render_index_template_vars(selector))
    end

    def render_photo(hash, selector = [])
      call_nodejs("show", render_photo_template_vars(hash, selector))
    end

    protected

    def call_nodejs(template, template_vars)
      @renderer.write("render_#{template}\n")
      @renderer.write("#{JSON.dump(template_vars)}\n")
      buffer = ""
      loop do
        line = @renderer.readline
        break if line.strip == "\x1C"
        buffer += line
      end
      buffer
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
piccle-0.1.0.rc1 lib/piccle/js_renderer.rb