Skip to content

Instantly share code, notes, and snippets.

@HHRy
Created October 11, 2011 22:04
Show Gist options
  • Select an option

  • Save HHRy/1279601 to your computer and use it in GitHub Desktop.

Select an option

Save HHRy/1279601 to your computer and use it in GitHub Desktop.
Appatra musings
=begin
Appatra is a new and simple framework for building surprisingly agnostic
desktop (and maybe even mobile) applications in Ruby.
It'll even try to generate a native application for your target platform
too because I know how much people really like that.
Appatra is by Ryan Stenhouse. If you want to know more about it or get
involved, please email ryan@stenhou.se
Appatra follows a familiar MVC pattern for no reason other than I like it,
the only difference is everything is a Ruby file.
Directory Structure:
APP_ROOT
|
+--controllers/
+--models/
+--views/
+--config/
+--lib/
+--test/
+--Gemfile
+--Rakefile
Appatra will only work under Ruby 1.9 expects you to use mintiest for your tests
but is Bundler aware and will let you include all manner of gems into your apps
if you so choose.
=end
# config/myapp.rb
require 'appatra'
require 'appatra/curses'
class MyApp < Appatra::CursesApplication
# Options are:
# :compile_and_fallback Default, tries to build, if it fails it will
# try to use the :interpret method before giving
# up.
# :compile Only tries to build native app for the platform
# you've targeted.
# :interpret Interpret the Ruby code that makes up this app
# don't try to build.
#
build_mode :compile_and_fallback
# Target is important, we'll be generating an honest-to-goodness
# native app here (if we can), and if we can't, hopefully portable
# Ruby will be used instead.
#
# If the application type you've picked doesn't support your target
# you'll get a TargetUnavailableException unless you specify a value
# to callback to. The target can take more than one target.
#
target :osx, :fallback => :ruby
end
# views/hello_world/main.rb
window :title => 'Hello World' do
text_label 'Hello World', :mode => :size_to_fit
button 'Close', :id => :close_button
end
# controllers/hello_world_controller.rb
action 'index' do
handle_click :close_button do
MyApp.close
end
end
=begin
To Run your app, you can use:
$ bundle exec appatra run
And to build it:
$ rake build
Running rake with no arguments will run your test suite just like you'd
expect it to.
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment