0
# sketches to applets that can be viewed online.
0
+require File.join(File.dirname(__FILE__), "base_exporter.rb")
0
+ class AppletExporter
< BaseExporter0
# Check to make sure that the main file exists
0
- main_file_path = ARGV.first
0
- main_file = File.basename(main_file_path)
0
- unless main_file_path && File.exists?(main_file_path)
0
+ @main_file_path, main_file = *get_main_file()
0
+ unless @main_file_path && File.exists?(@main_file_path)
0
The applet generator will generate a web-ready applet for you.
0
@@ -25,46 +23,28 @@ module Processing
0
- # Extract information from main file
0
- source_code = File.open(main_file_path, "r") {|file| file.readlines.join(" ")}
0
- class_name = source_code.match(/(\w+)\s*<\s*Processing::App/)[1]
0
- title = source_code.match(/#{class_name}\.new.*?:title\s=>\s["'](.+)["']/m)
0
- width = source_code.match(/#{class_name}\.new.*?:width\s=>\s(\d+)/m)
0
- height = source_code.match(/#{class_name}\.new.*?:height\s=>\s(\d+)/m)
0
- description = source_code.match(/# Description:(.*?)\n [^#]/m)
0
- code = source_code.dup
0
- matchdata = code.match(/load_\w+_library.+?["':](\S+)["'\s]/)
0
- if File.exists?("library/#{matchdata[1]}")
0
- @opengl = true if matchdata[1].match(/opengl/i)
0
- libs_to_load << matchdata[1]
0
- code = matchdata.post_match
0
+ # Extract all the cool details.
0
+ source_code, class_name, title, width, height, description, libs_to_load = *extract_information()
0
# Make the appropriate directory
0
applet_dir = "applets/#{main_file.sub(".rb", "")}"
0
- FileUtils.remove_entry_secure applet_dir if File.exists?(applet_dir)
0
- FileUtils.mkdir_p applet_dir
0
+ remove_entry_secure applet_dir if File.exists?(applet_dir)
0
# Copy over all the required files
0
- necessary_files = [
main_file_path, "ruby-processing.rb", "core.jar"]
0
+ necessary_files = [
@main_file_path, "ruby-processing.rb", "core.jar"]
0
necessary_files << "data" if File.exists?("data")
0
necessary_files += Dir.glob("script/applet_files/{*,**}") # Exporter files
0
necessary_files += Dir.glob("library/{#{libs_to_load.join(",")}}") if libs_to_load.length > 0
0
-
FileUtils.cp_r(necessary_files, applet_dir)
0
+
cp_r(necessary_files, applet_dir)
0
# Figure out OpenGL replacements, if necessary:
0
@starting_class = @opengl ? "com.sun.opengl.util.JOGLAppletLauncher" : "org.jruby.JRubyApplet"
0
opengl_files = Dir.glob(applet_dir + "/opengl/*.jar")
0
opengl_files += Dir.glob(applet_dir + "/opengl/library/*.jar")
0
- FileUtils.move(opengl_files, applet_dir)
0
- FileUtils.remove_entry_secure(applet_dir + "/opengl")
0
+ move(opengl_files, applet_dir)
0
+ remove_entry_secure(applet_dir + "/opengl")
0
necessary_files.map! {|file| file.match(/^opengl/) ? File.basename(file) : file }
0
@@ -87,7 +67,7 @@ module Processing
0
File.open(applet_dir + "/index.html", "w") do |file|
0
file.print rendered_index
0
-
FileUtils.rm(applet_dir + "/index.html.erb")
0
+
rm(applet_dir + "/index.html.erb")
Comments
No one has commented yet.