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][mode][flag]: 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 p3d (P3D mode example) rp5 create some_new_sketch 640 480 --wrap (a class wrapped default sketch) 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) ⇒ 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 = new runner.(ARGV) runner.execute! end |
Instance Method Details
#app(sketch) ⇒ Object
Generate a cross-platform application of a given Ruby-Processing sketch.
113 114 115 116 |
# File 'lib/ruby-processing/runner.rb', line 113 def app(sketch) require_relative '../ruby-processing/exporters/application_exporter' Processing::ApplicationExporter.new.export!(sketch) end |
#check(proc_root, installed) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ruby-processing/runner.rb', line 139 def check(proc_root, installed) show_version root = ' PROCESSING_ROOT = Not Set!!!' unless proc_root root ||= " PROCESSING_ROOT = #{Processing::RP_CONFIG['PROCESSING_ROOT']}" jruby = Processing::RP_CONFIG['JRUBY'] x_off = Processing::RP_CONFIG['X_OFF'] y_off = Processing::RP_CONFIG['Y_OFF'] puts root puts " JRUBY = #{jruby}" unless jruby.nil? puts " X_OFF = #{x_off}" unless x_off.nil? puts " Y_OFF = #{y_off}" unless y_off.nil? puts " jruby-complete installed = #{installed}" end |
#create(sketch, args) ⇒ Object
Create a fresh Ruby-Processing sketch, with the necessary boilerplate filled out.
83 84 85 86 87 88 89 90 91 |
# File 'lib/ruby-processing/runner.rb', line 83 def create(sketch, args) require_relative '../ruby-processing/exporters/creator' return Processing::Inner.new.create!(sketch, args) if @options.inner if @options.wrap Processing::ClassSketch.new.create!(sketch, args) else Processing::BasicSketch.new.create!(sketch, args) end 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) 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.
107 108 109 110 |
# File 'lib/ruby-processing/runner.rb', line 107 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 79 |
# File 'lib/ruby-processing/runner.rb', line 70 def (args) @options = OpenStruct.new @options.wrap = !args.delete('--wrap').nil? @options.inner = !args.delete('--inner').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.
94 95 96 97 |
# File 'lib/ruby-processing/runner.rb', line 94 def run(sketch, args) ensure_exists(sketch) spin_up('run.rb', sketch, args) end |
#setup(choice) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ruby-processing/runner.rb', line 118 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" unless 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.
160 161 162 |
# File 'lib/ruby-processing/runner.rb', line 160 def show_help puts HELP_MESSAGE end |
#show_version ⇒ Object
Display the current version of Ruby-Processing.
155 156 157 |
# File 'lib/ruby-processing/runner.rb', line 155 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.
101 102 103 104 |
# File 'lib/ruby-processing/runner.rb', line 101 def watch(sketch, args) ensure_exists(sketch) spin_up('watch.rb', sketch, args) end |