File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,7 +16,10 @@ class Engine
1616 #
1717 # @param lazy [true, false] immediately loads and initializes the JavaScript
1818 # environment.
19- def initialize ( lazy : false )
19+ # @param path [String, nil] the path to the version of Handlebars to load.
20+ # If `nil`, the contents of `Handlebars::Source.bundled_path` is loaded.
21+ def initialize ( lazy : false , path : nil )
22+ @path = path
2023 init! unless lazy
2124 end
2225
@@ -204,7 +207,7 @@ def init!
204207 return if @init
205208
206209 @context = MiniRacer ::Context . new
207- @context . load ( ::Handlebars ::Source . bundled_path )
210+ @context . load ( @path || ::Handlebars ::Source . bundled_path )
208211 @context . load ( File . absolute_path ( "engine/init.js" , __dir__ ) )
209212
210213 @init = true
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3+ require "tempfile"
4+
35RSpec . describe Handlebars ::Engine do
46 let ( :engine ) { described_class . new ( **engine_options ) }
57 let ( :engine_context ) { engine . instance_variable_get ( :@context ) }
4143 expect ( engine_context ) . to be nil
4244 end
4345 end
46+
47+ context "when `path` is defined" do
48+ let ( :file ) { Tempfile . open }
49+
50+ before do
51+ engine_options [ :path ] = file . path
52+ file . write <<~HANDLEBARS
53+ var Handlebars = {
54+ compile: () => "compile",
55+ precompile: () => "precompile",
56+ template: () => "template",
57+ registerPartial: () => "registerPartial",
58+ unregisterPartial: () => "unregisterPartial",
59+ registerHelper: () => "registerHelper",
60+ unregisterHelper: () => "unregisterHelper",
61+ partials: {},
62+ VERSION: "VERSION",
63+ };
64+ HANDLEBARS
65+ file . rewind
66+ end
67+
68+ after do
69+ file . close
70+ end
71+
72+ it "loads the file contents" do
73+ expect ( engine_context . eval ( "VERSION" ) ) . to eq ( "VERSION" )
74+ end
75+ end
4476 end
4577
4678 ###################################
You can’t perform that action at this time.
0 commit comments