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, and unpack
Constant Summary collapse
- HELP_MESSAGE =
" Version: \#{RubyProcessing::VERSION}\n\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 [width height] | app | unpack] path/to/sketch\n\n run: run sketch once\n watch: watch for changes on the file and relaunch it on the fly\n live: launch sketch and give an interactive IRB shell\n create: create new sketch. Use --bare to generate simpler sketches without a class\n app: create an application version of the sketch\n unpack: unpack samples or library\n\n Common options:\n --nojruby: do not use the installed version of jruby, instead use our vendored\n jarred one (required for shader sketches, and some others).\n \n Configuration file:\n A YAML configuration file is located at {Processing::CONFIG_FILE_PATH}\n \n Possible options are:\n\njava_args: pass additionnals arguments to Java VM upon launching. \n Useful for increasing available memory (for example:\n -Xms256m -Xmx256m) or force 32 bits mode (-d32).\nsketchbook_path: specify Processing sketchbook path to load additionnal \n libraries\n\n Examples:\n rp5 unpack samples\n rp5 run samples/contributed/jwishy.rb\n rp5 create some_new_sketch 640 480\n rp5 create some_new_sketch --p3d 640 480\n rp5 watch 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.
-
#create(sketch, args, p3d) ⇒ 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
57 58 59 60 61 |
# File 'lib/ruby-processing/runner.rb', line 57 def self.execute runner = self.new runner.(ARGV) runner.execute! end |
Instance Method Details
#app(sketch) ⇒ Object
Generate a cross-platform application of a given Ruby-Processing sketch.
116 117 118 |
# File 'lib/ruby-processing/runner.rb', line 116 def app(sketch) Processing::ApplicationExporter.new.export!(sketch) end |
#create(sketch, args, p3d) ⇒ Object
Create a fresh Ruby-Processing sketch, with the necessary boilerplate filled out.
92 93 94 |
# File 'lib/ruby-processing/runner.rb', line 92 def create(sketch, args, p3d) Processing::Creator.new.create!(sketch, args, p3d) end |
#execute! ⇒ Object
Dispatch central.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ruby-processing/runner.rb', line 64 def execute! case .action when 'run' then run(.path, .args) when 'watch' then watch(.path, .args) when 'live' then live(.path, .args) when 'create' then create(.path, .args, .p3d) when 'app' then app(.path) when 'unpack' then unpack(.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.
110 111 112 113 |
# File 'lib/ruby-processing/runner.rb', line 110 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.
80 81 82 83 84 85 86 87 88 |
# File 'lib/ruby-processing/runner.rb', line 80 def (args) = OpenStruct.new .p3d = !!args.delete('--p3d') .jruby = !!args.delete('--jruby') .nojruby = !!args.delete('--nojruby') .action = args[0] || nil .path = args[1] || File.basename(Dir.pwd + '.rb') .args = args[2..-1] || [] end |
#run(sketch, args) ⇒ Object
Just simply run a ruby-processing sketch.
97 98 99 100 |
# File 'lib/ruby-processing/runner.rb', line 97 def run(sketch, args) ensure_exists(sketch) spin_up('run.rb', sketch, args) end |
#show_help ⇒ Object
Show the standard help/usage message.
135 136 137 |
# File 'lib/ruby-processing/runner.rb', line 135 def show_help puts HELP_MESSAGE end |
#show_version ⇒ Object
Display the current version of Ruby-Processing.
130 131 132 |
# File 'lib/ruby-processing/runner.rb', line 130 def show_version puts "Ruby-Processing version #{RubyProcessing::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.
122 123 124 125 126 127 |
# File 'lib/ruby-processing/runner.rb', line 122 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.
104 105 106 107 |
# File 'lib/ruby-processing/runner.rb', line 104 def watch(sketch, args) ensure_exists(sketch) spin_up('watch.rb', sketch, args) end |