Sha256: 3487709e4e0e9391e0d216a1e50e66153711f3f64fafeb1725e720beac73e675

Contents?: true

Size: 779 Bytes

Versions: 1

Compression:

Stored size: 779 Bytes

Contents

# frozen_string_literal: true

module Handlebarsjs
  # API for interacting with Javascript while providing native Ruby helpers
  class Javascript
    attr_reader :handlebars_snapshot

    def initialize
      @handlebars_snapshot = HandlebarsSnapshot.new
    end

    def eval(script)
      context.eval(script)
    end

    def attach(script, block)
      context.attach(script, block)
    end

    def call(function_name, *arguments)
      context.call(function_name, *arguments)
    end

    private

    def context
      puts 'Snapshot and context are out of date, calls to snapshot should happen before any calls to context' if !@context.nil? && handlebars_snapshot.dirty?
      @context ||= MiniRacer::Context.new(snapshot: handlebars_snapshot.snapshot)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
handlebarsjs-0.3.0 lib/handlebarsjs/javascript.rb