Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentisambart committed Nov 1, 2008
0 parents commit fa5807c
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.app
18 changes: 18 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
task :default => [:run]

task :build do
require 'hotcocoa/application_builder'
ApplicationBuilder.build :file => "config/build.yml"
end

task :run => [:build] do
require 'yaml'
app_name = YAML.load(File.read("config/build.yml"))[:name]
`open "#{app_name}.app"`
end

task :clean do
require 'yaml'
app_name = YAML.load(File.read("config/build.yml"))[:name]
`rm -rf "#{app_name}.app"`
end
8 changes: 8 additions & 0 deletions config/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:name: MacIrb
:load: lib/application.rb
:version: "1.0"
:icon: resources/HotCocoa.icns
:resources:
- resources/**/*.*
:sources:
- lib/**/*.rb
97 changes: 97 additions & 0 deletions lib/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
require 'hotcocoa'
framework 'webkit'

class Application
include HotCocoa

def start
@line_num = 1
@binding = TOPLEVEL_BINDING

def base_html
return <<-HTML
<html>
<body>
<table>
<tr>
<td style="vertical-align: top;">&gt;&gt;</td>
<td style="width: 100%;"><div id="command_line" contentEditable="true"></div></td>
</tr>
</table>
<script type="text/javascript"><!--
var command_line = document.getElementById('command_line');
command_line.focus();
//var selection = window.getSelection();
//selection.setBaseAndExtent(command_line, 0, command_line, command_line.innerText.length);
//selection.deleteFromDocument();
--></script>
</body>
</html>
HTML
end

application :name => "MacIrb" do |app|
app.delegate = self

window :frame => [100, 100, 900, 500], :title => "MacIrb" do |win|
win.will_close { exit }
@web_view = web_view(:layout => {:expand => [:width, :height]})
@web_view.mainFrame.loadHTMLString base_html, baseURL:nil
win << @web_view
end
# @display = label(:text => '', :layout => {:expand => [:width, :height]})
# @command_line = text_field(:layout => {:expand => [:width]})
# win << @command_line
# win << @display
# @command_line.on_action do
# self.perform_action
# end
end
end

def perform_action
@line_num += 1
command = @command_line.to_s
return if command.empty?
eval_file = __FILE__
eval_line = -1
begin
eval_line = __LINE__; value = eval(command, @binding, 'macirb', @line_num-1)
@display.text = value.inspect
rescue Exception => e
backtrace = e.backtrace
i = backtrace.index { |l| l.index("#{eval_file}:#{eval_line}") }
puts "#{eval_file}:#{eval_line}"
puts i
backtrace = backtrace[0..i-1] if i
@display.text = "#{e.class.name}: #{e.message}\n#{backtrace.join("\n")}"
end
@command_line.text = ''
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

Application.new.start
32 changes: 32 additions & 0 deletions lib/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module HotCocoa
def application_menu
menu do |main|
main.submenu :apple do |apple|
apple.item :about, :title => "About #{NSApp.name}"
apple.separator
apple.item :preferences, :key => ","
apple.separator
apple.submenu :services
apple.separator
apple.item :hide, :title => "Hide #{NSApp.name}", :key => "h"
apple.item :hide_others, :title => "Hide Others", :key => "h", :modifiers => [:command, :alt]
apple.item :show_all, :title => "Show All"
apple.separator
apple.item :quit, :title => "Quit #{NSApp.name}", :key => "q"
end
main.submenu :file do |file|
file.item :new, :key => "n"
file.item :open, :key => "o"
end
main.submenu :window do |win|
win.item :minimize, :key => "m"
win.item :zoom
win.separator
win.item :bring_all_to_front, :title => "Bring All to Front", :key => "o"
end
main.submenu :help do |help|
help.item :help, :title => "#{NSApp.name} Help"
end
end
end
end
Binary file added resources/HotCocoa.icns
Binary file not shown.

0 comments on commit fa5807c

Please sign in to comment.