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 =
<<-EOS Version: #{RubyProcessing::VERSION} Ruby-Processing is a little shim between Processing and JRuby that helps you create sketches of code art. Usage: rp5 [choice] path/to/sketch choice:- run: run sketch once watch: watch for changes on the file and relaunch it on the fly live: launch sketch and give an interactive IRB shell create [width height]: create a new sketch. app: create an application version of the sketch setup: check setup, install jruby-complete, unpack samples Common options: --nojruby: use jruby-complete in place of an installed version of jruby (Set [JRUBY: 'false'] in .rp5rc to make using jruby-complete default) Examples: rp5 setup unpack_samples rp5 run samples/contributed/jwishy.rb rp5 create some_new_sketch 640 480 rp5 create some_new_sketch --p3d 640 480 rp5 watch 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.
- #check(proc_root, installed) ⇒ Object
-
#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.
- #setup(choice) ⇒ Object
-
#show_help ⇒ Object
Show the standard help/usage message.
-
#show_version ⇒ Object
Display the current version of Ruby-Processing.
-
#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
47 48 49 50 51 |
# File 'lib/ruby-processing/runner.rb', line 47 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.
107 108 109 110 |
# File 'lib/ruby-processing/runner.rb', line 107 def app(sketch) require_relative '../ruby-processing/exporters/application_exporter' Processing::ApplicationExporter.new.export!(sketch) end |
#check(proc_root, installed) ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/ruby-processing/runner.rb', line 133 def check(proc_root, installed) show_version root = ' PROCESSING_ROOT = Not Set!!!' unless proc_root root ||= " PROCESSING_ROOT = #{Processing::RB_CONFIG['PROCESSING_ROOT']}" puts root puts " JRUBY = #{Processing::RB_CONFIG['JRUBY']}" puts " jruby-complete installed = #{installed}" end |
#create(sketch, args, p3d) ⇒ Object
Create a fresh Ruby-Processing sketch, with the necessary boilerplate filled out.
82 83 84 85 |
# File 'lib/ruby-processing/runner.rb', line 82 def create(sketch, args, p3d) require_relative '../ruby-processing/exporters/creator' Processing::Creator.new.create!(sketch, args, p3d) end |
#execute! ⇒ Object
Dispatch central.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby-processing/runner.rb', line 54 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.p3d) when 'app' then app(@options.path) when 'setup' then setup(@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.
101 102 103 104 |
# File 'lib/ruby-processing/runner.rb', line 101 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.
70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby-processing/runner.rb', line 70 def (args) @options = OpenStruct.new @options.p3d = !args.delete('--p3d').nil? @options.jruby = !args.delete('--jruby').nil? @options.nojruby = !args.delete('--nojruby').nil? @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.
88 89 90 91 |
# File 'lib/ruby-processing/runner.rb', line 88 def run(sketch, args) ensure_exists(sketch) spin_up('run.rb', sketch, args) end |
#setup(choice) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ruby-processing/runner.rb', line 112 def setup(choice) usage = 'Usage: rp5 setup [check | install | unpack_samples]' installed = File.exist?("#{RP5_ROOT}/lib/ruby/jruby-complete.jar") proc_root = File.exist?("#{ENV['HOME']}/.rp5rc") case choice when /check/ check(proc_root, installed) when /install/ system "cd #{RP5_ROOT}/vendors && rake" if !proc_root set_processing_root warn 'PROCESSING_ROOT set optimistically, run check to confirm' end when /unpack_samples/ require 'fileutils' FileUtils.cp_r("#{RP5_ROOT}/samples", "#{Dir.pwd}/rp_samples") else puts usage end end |
#show_help ⇒ Object
Show the standard help/usage message.
149 150 151 |
# File 'lib/ruby-processing/runner.rb', line 149 def show_help puts HELP_MESSAGE end |
#show_version ⇒ Object
Display the current version of Ruby-Processing.
144 145 146 |
# File 'lib/ruby-processing/runner.rb', line 144 def show_version puts "Ruby-Processing version #{RubyProcessing::VERSION}" end |
#watch(sketch, args) ⇒ Object
Run a sketch, keeping an eye on it’s file, and reloading whenever it changes.
95 96 97 98 |
# File 'lib/ruby-processing/runner.rb', line 95 def watch(sketch, args) ensure_exists(sketch) spin_up('watch.rb', sketch, args) end |