Slide 18
Slide 18 text
JavaScript Context
1 require 'v8'
2 # require 'rhino'
3
4 # This service wraps a JS context and allows us to interact with our Javascript
5 # directly in Ruby.
6 class Javascript
7
8 # Our V8 context object
9 attr_reader :context
10
11 # Some delegations
12 delegate :load, :eval, :[], :[]=, to: :context
13
14 def initialize()
15 @context = V8::Context.new
16 #@context = Rhino::Context.new
17
18 # Setup a fake 'window' object
19 @context['window'] = FakeWindow.new( @context )
20 @context['console'] = FakeConsole.new
21
22 # Load our global setup
23 load_coffee Rails.root.join( 'app/assets/javascripts/setup.js.coffee' )
24 end
25
26 # truncated, lots more detracting stuff down below...
27
28 end