diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13d94f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.app diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..4cd1286 --- /dev/null +++ b/Rakefile @@ -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 diff --git a/config/build.yml b/config/build.yml new file mode 100644 index 0000000..fc07370 --- /dev/null +++ b/config/build.yml @@ -0,0 +1,8 @@ +:name: MacIrb +:load: lib/application.rb +:version: "1.0" +:icon: resources/HotCocoa.icns +:resources: + - resources/**/*.* +:sources: + - lib/**/*.rb diff --git a/lib/application.rb b/lib/application.rb new file mode 100644 index 0000000..180a0eb --- /dev/null +++ b/lib/application.rb @@ -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 + 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 diff --git a/lib/menu.rb b/lib/menu.rb new file mode 100644 index 0000000..be16f5c --- /dev/null +++ b/lib/menu.rb @@ -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 diff --git a/resources/HotCocoa.icns b/resources/HotCocoa.icns new file mode 100644 index 0000000..36e449c Binary files /dev/null and b/resources/HotCocoa.icns differ