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 =
<<-EOS Ruby-Processing is a little shim between Processing and JRuby that helps you create sketches of code art. Usage: rp5 [run | watch | live | create | app | applet | unpack] path/to/sketch Examples: rp5 unpack samples rp5 run samples/jwishy.rb rp5 create some_new_sketch --bare 640 480 rp5 watch some_new_sketch.rb rp5 applet some_new_sketch.rb Everything Else: http://wiki.github.com/jashkenas/ruby-processing EOS
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, args) ⇒ 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, args) ⇒ 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, args) ⇒ 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.
90 91 92 |
# File 'lib/ruby-processing/runner.rb', line 90 def app(sketch) Processing::ApplicationExporter.new.export!(sketch) end |
#applet(sketch) ⇒ Object
Generate an applet and HTML page for a given sketch.
95 96 97 |
# File 'lib/ruby-processing/runner.rb', line 95 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.
66 67 68 |
# File 'lib/ruby-processing/runner.rb', line 66 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 @options.action when 'run' then run(@options.path, @options.args) when 'watch' then watch(@options.path, @options.args) when 'live' then live(@options.path, @options.args) when 'create' then create(@options.path, @options.args, @options.) when 'app' then app(@options.path) when 'applet' then applet(@options.path) when 'unpack' then unpack(@options.path) when /-v/ then show_version when /-h/ then show_help else show_help end end |
#live(sketch, args) ⇒ Object
Run a sketch, opening its guts to IRB, letting you play with it.
84 85 86 87 |
# File 'lib/ruby-processing/runner.rb', line 84 def live(sketch, args) ensure_exists(sketch) spin_up('live.rb', sketch, args) end |
#parse_options(args) ⇒ Object
Parse the command-line options. Keep it simple.
55 56 57 58 59 60 61 62 |
# File 'lib/ruby-processing/runner.rb', line 55 def (args) @options = OpenStruct.new @options. = !!args.delete('--bare') @options.jruby = !!args.delete('--jruby') @options.action = args[0] || nil @options.path = args[1] || File.basename(Dir.pwd + '.rb') @options.args = args[2..-1] || [] end |
#run(sketch, args) ⇒ Object
Just simply run a ruby-processing sketch.
71 72 73 74 |
# File 'lib/ruby-processing/runner.rb', line 71 def run(sketch, args) ensure_exists(sketch) spin_up('run.rb', sketch, args) end |
#show_help ⇒ Object
Show the standard help/usage message.
114 115 116 |
# File 'lib/ruby-processing/runner.rb', line 114 def show_help puts HELP_MESSAGE end |
#show_version ⇒ Object
Display the current version of Ruby-Processing.
109 110 111 |
# File 'lib/ruby-processing/runner.rb', line 109 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.
101 102 103 104 105 106 |
# File 'lib/ruby-processing/runner.rb', line 101 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, args) ⇒ Object
Run a sketch, keeping an eye on it’s file, and reloading whenever it changes.
78 79 80 81 |
# File 'lib/ruby-processing/runner.rb', line 78 def watch(sketch, args) ensure_exists(sketch) spin_up('watch.rb', sketch, args) end |