Class: Processing::Runner
- Inherits:
-
Object
- Object
- Processing::Runner
- Defined in:
- lib/ruby-processing/runner.rb
Overview
Utility class to handle the different commands that the ‘rp5’ command offers. Able to run, watch, live, create, app, applet, and unpack
Constant Summary collapse
- HELP_MESSAGE =
"\n Ruby-Processing is a little shim between Processing and JRuby that helps\n you create sketches of code art.\n \n Usage:\n rp5 [run | watch | live | create | app | applet | unpack] path/to/sketch\n \n Examples:\n rp5 unpack samples\n rp5 run samples/jwishy.rb\n rp5 create some_new_sketch --bare 640 480\n rp5 watch some_new_sketch.rb\n rp5 applet some_new_sketch.rb\n \n Everything Else:\n http://wiki.github.com/jashkenas/ruby-processing \n \n"
Class Method Summary collapse
-
.execute ⇒ Object
Start running a ruby-processing sketch from the passed-in arguments.
Instance Method Summary collapse
-
#app(sketch) ⇒ Object
Generate a cross-platform application of a given Ruby-Processing sketch.
-
#applet(sketch) ⇒ Object
Generate an applet and HTML page for a given sketch.
-
#create(sketch, args, bare) ⇒ Object
Create a fresh Ruby-Processing sketch, with the necessary boilerplate filled out.
-
#execute! ⇒ Object
Dispatch central.
-
#live(sketch) ⇒ Object
Run a sketch, opening its guts to IRB, letting you play with it.
-
#parse_options(args) ⇒ Object
Parse the command-line options.
-
#run(sketch) ⇒ Object
Just simply run a ruby-processing sketch.
-
#show_help ⇒ Object
Show the standard help/usage message.
-
#show_version ⇒ Object
Display the current version of Ruby-Processing.
-
#unpack(dir) ⇒ Object
Install the included samples to a given path, where you can run and alter them to your heart’s content.
-
#watch(sketch) ⇒ Object
Run a sketch, keeping an eye on it’s file, and reloading whenever it changes.
Class Method Details
.execute ⇒ Object
Start running a ruby-processing sketch from the passed-in arguments
31 32 33 34 35 |
# File 'lib/ruby-processing/runner.rb', line 31 def self.execute runner = new runner.(ARGV) runner.execute! end |
Instance Method Details
#app(sketch) ⇒ Object
Generate a cross-platform application of a given Ruby-Processing sketch.
89 90 91 |
# File 'lib/ruby-processing/runner.rb', line 89 def app(sketch) Processing::ApplicationExporter.new.export!(sketch) end |
#applet(sketch) ⇒ Object
Generate an applet and HTML page for a given sketch.
94 95 96 |
# File 'lib/ruby-processing/runner.rb', line 94 def applet(sketch) Processing::AppletExporter.new.export!(sketch) end |
#create(sketch, args, bare) ⇒ Object
Create a fresh Ruby-Processing sketch, with the necessary boilerplate filled out.
65 66 67 |
# File 'lib/ruby-processing/runner.rb', line 65 def create(sketch, args, ) Processing::Creator.new.create!(sketch, args, ) end |
#execute! ⇒ Object
Dispatch central.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby-processing/runner.rb', line 38 def execute! case .action when 'run' then run(.path) when 'watch' then watch(.path) when 'create' then create(.path, .args, .) when 'live' then live(.path) when 'app' then app(.path) when 'applet' then applet(.path) when 'unpack' then unpack(.path) when /-v/ then show_version when /-h/ then show_help else show_help end end |
#live(sketch) ⇒ Object
Run a sketch, opening its guts to IRB, letting you play with it.
83 84 85 86 |
# File 'lib/ruby-processing/runner.rb', line 83 def live(sketch) ensure_exists(sketch) spin_up('live.rb', sketch) end |
#parse_options(args) ⇒ Object
Parse the command-line options. Keep it simple.
55 56 57 58 59 60 61 |
# File 'lib/ruby-processing/runner.rb', line 55 def (args) = OpenStruct.new . = !!args.delete('--bare') .action = args[0] || nil .path = args[1] || File.basename(Dir.pwd + '.rb') .args = args[2..-1] || [] end |
#run(sketch) ⇒ Object
Just simply run a ruby-processing sketch.
70 71 72 73 |
# File 'lib/ruby-processing/runner.rb', line 70 def run(sketch) ensure_exists(sketch) spin_up('run.rb', sketch) end |
#show_help ⇒ Object
Show the standard help/usage message.
113 114 115 |
# File 'lib/ruby-processing/runner.rb', line 113 def show_help puts HELP_MESSAGE end |
#show_version ⇒ Object
Display the current version of Ruby-Processing.
108 109 110 |
# File 'lib/ruby-processing/runner.rb', line 108 def show_version puts "Ruby-Processing version #{Processing.version}" end |
#unpack(dir) ⇒ Object
Install the included samples to a given path, where you can run and alter them to your heart’s content.
100 101 102 103 104 105 |
# File 'lib/ruby-processing/runner.rb', line 100 def unpack(dir) require 'fileutils' usage = "Usage: rp5 unpack [samples | library]" puts usage and return unless dir.match(/\A(samples|library)\Z/) FileUtils.cp_r("#{RP5_ROOT}/#{dir}", "#{Dir.pwd}/#{dir}") end |
#watch(sketch) ⇒ Object
Run a sketch, keeping an eye on it’s file, and reloading whenever it changes.
77 78 79 80 |
# File 'lib/ruby-processing/runner.rb', line 77 def watch(sketch) ensure_exists(sketch) spin_up('watch.rb', sketch) end |