Skip to content

Instantly share code, notes, and snippets.

@makevoid
Forked from reborg/open_local_html_hotcocoa_webview.rb
Created August 27, 2011 02:23
Show Gist options
  • Save makevoid/1174866 to your computer and use it in GitHub Desktop.
Save makevoid/1174866 to your computer and use it in GitHub Desktop.
Hotcocoa basic WebView hello world (to embed a webpp in a native one basically)

Run

if you don't have macruby and hotcocoa already:

rvm use macruby
gem i hotcocoa

ok then you can run:

hotcocoa webviewbasic

this will generate a blank app copy application.rb in your lib/application.rb

and create an index.html file like this and put in "resources" dir:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <h1>yo!</h1>
    <p>  awesome webapp bundled in osx</p>
  </body>
</html>


rake run

enjoy!

require 'rubygems' # disable this for a deployed application
require 'hotcocoa'
framework 'webkit'
HOME_PATH = File.join(
NSBundle.mainBundle.resourcePath.fileSystemRepresentation,
'index.html')
class WebViewBasic
include HotCocoa
def start
app_name = self.class.name
application name: app_name do |app|
app.delegate = self
application do |app|
window frame: [100, 100, 600, 400], title: app_name do |win|
win << web_view(
layout: { expand: [:width, :height] },
url: NSURL.alloc.initFileURLWithPath(HOME_PATH)
)
# win.will_close { exit }
end
end
end
end
# file/open
def on_open(menu)
end
# file/new
def on_new(menu)
end
# help menu item
def on_help(menu)
end
# This is commented out, so the minimize menu item is disabled
#def on_minimize(menu)
#end
# window/zoom
def on_zoom(menu)
end
# window/bring_all_to_front
def on_bring_all_to_front(menu)
end
end
WebViewBasic.new.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment