-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplicationController.rb
executable file
·42 lines (35 loc) · 1.34 KB
/
ApplicationController.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# ApplicationController.rb
# WebKitTest
#
# Created by Larry Staton Jr. on 10/20/10.
# Copyright 2010 Sweetpea Software. All rights reserved.
require "Cat"
class ApplicationController < NSObject
attr_accessor :window, :webView
def applicationDidFinishLaunching(notification)
NSLog("Application did finish launching")
page_url = NSURL.URLWithString('http://jquery.com')
@webView.mainFrame.loadRequest(NSURLRequest.requestWithURL(page_url))
@window.orderFrontRegardless
end
# WebView delegate methods
def webView(view, didFinishLoadForFrame:frame)
NSLog("Finished loading frame")
@kitty = Cat.new("Moose", 12)
jsc = view.windowScriptObject
# Call JavaScript from MacRuby
# Using jQuery (we're on their page)
puts jsc.evaluateWebScript("$('#jq-intro > h2').text()")
jsc.evaluateWebScript("$('#jq-intro > h2').css('color', 'yellow')")
# Call Ruby from JavaScript
# Set the JavaScript variable "animal" to our Cat instance
jsc.setValue(@kitty, forKey: "animal")
# Tell JavaScript that our Cat instance responds to age method
# No colon at end of selector because no arguments
@kitty.respondsToSelector("age")
# Call the age method on our Cat instance from JavaScript
puts jsc.evaluateWebScript("animal.age()")
# Execute Ruby code from the DOM
jsc.evaluateWebScript("$('#jq-intro > h2').append(animal.age())")
end
end