@@ -21,7 +21,8 @@ class Engine
2121 # environment.
2222 # @param path [String, nil] the path to the version of Handlebars to load.
2323 # If `nil`, the contents of `Handlebars::Source.bundled_path` is loaded.
24- def initialize ( lazy : false , path : nil )
24+ def initialize ( lazy : false , logger : nil , path : nil )
25+ @logger = logger
2526 @path = path
2627 init! unless lazy
2728 end
@@ -175,13 +176,16 @@ def version
175176
176177 def attach ( name , &block )
177178 init!
179+ @logger &.debug { "[handlebars] attaching #{ name } " }
178180 @context . attach ( name . to_s , block )
179181 end
180182
181183 def call ( name , args , assign : false , eval : false )
182184 init!
183185 name = name . to_s
184186
187+ @logger &.debug { "[handlebars] calling #{ name } with args #{ args } " }
188+
185189 if assign || eval
186190 call_via_eval ( name , args , assign : assign )
187191 else
@@ -207,6 +211,7 @@ def call_via_eval(name, args, assign: false)
207211 end
208212
209213 def evaluate ( code )
214+ @logger &.debug { "[handlebars] evaluating #{ code } " }
210215 @context . eval ( code )
211216 end
212217
@@ -222,10 +227,18 @@ def helper_missing_name(type)
222227 def init!
223228 return if @init
224229
230+ @logger &.debug { "[handlebars] initializing" }
231+
225232 @context = MiniRacer ::Context . new
233+ @context . attach (
234+ "console.log" ,
235+ -> ( *args ) { @logger &.debug { "[handlebars] #{ args . join ( " " ) } " } } ,
236+ )
226237 @context . load ( @path || ::Handlebars ::Source . bundled_path )
227238 @context . load ( File . absolute_path ( "engine/init.js" , __dir__ ) )
228239
240+ @logger &.debug { "[handlebars] initialized" }
241+
229242 @init = true
230243 end
231244
0 commit comments