load_sketchapps.rb) to SketchUp's
pluginsdirectory. This plugin traverses the user's SketchApps file tree, loading plugins, then sets up a sorted tree of menu items.
$sketchapps.config[:cfcl_dr] && class Draw_Ruby_2_ERb attr_reader :dr2_opts def main(args=nil) $sketchapps.trace_me('Draw_Ruby_2_ERb main') #T dr1_lib = 'CFCL/Public/Plugin/Code/Draw_Ruby_1/support/lib' my_libs = [ [ dr1_lib, :dr1_misc ], :dr2_erb_misc ] my_mods = [ :DR1_Misc, :DR2_ERb_Misc ] $sketchapps.setup_libs(self, my_libs, my_mods, __FILE__) setup @pf.log.info 'Draw_Ruby_2_ERb' setup_ui('dr2_erb_help.rb') end menu_path = [ 'Plugins', 'SketchApps', 'CFCL', 'Toys', 'Draw Ruby 2 (ERb)' ] $sketchapps.register_menu(self, menu_path) endThe code above is concise, but quite a bit is happening. So, a code walkthrough is definitely in order.
sa_config.rb, setting up logging support),
load_sketchapps.rbreads and loads (ie, executes) this plugin file. A bit of
Kernel.loadtrickery lets us avoid adding the
Draw_Ruby_2_ERbclass (etc) to the global namespace:
If the optional wrap parameter is
true, the loaded script will be executed under an anonymous module, protecting the calling program's global namespace.
"Programming Ruby", Dave Thomas
$sketchapps.config[:cfcl_dr]is set (by
Draw_Ruby_2_ERbis defined (in an anonymous module) and registered with SketchApps. Specifically, the plugin's class definition code makes a call to
register_menu, handing it the class (
self) and the desired
menu_path. After all of the plugins have been loaded,
load_sketchapps.rbuses the information to create organized sets of menu items and/or tools. So, for example, this plugin would appear in a sub-menu containing other CFCL toys.
dr2_erb_misc.rb) isn't loaded unless the user invokes the plugin (eg, by selecting its menu item). If and when the plugin is invoked, the class is instantiated and
mainis run (
argsmay be used to pass arguments from another plugin). After setting up any needed libraries and modules,
setup_ui, which set up generic and user interface support.