require 'retrospec/plugins/v1' require_relative 'spec_object' require_relative 'version' module Retrospec module Plugins module V1 class <%= capitalized_plugin_name %> < Retrospec::Plugins::V1::Plugin attr_reader :template_dir, :context # retrospec will initilalize this class so its up to you # to set any additional variables you need to get the job done. def initialize(supplied_module_path=nil,config={}) super # below is the Spec Object which serves as a context for template rendering # you will need to initialize this object, so the erb templates can get the binding # the SpecObject can be customized to your liking as its different for every plugin gem. @context = ::<%= capitalized_plugin_name %>::SpecObject.new(module_path, config) end # used to display subcommand options to the cli # the global options are passed in for your usage # http://trollop.rubyforge.org # all options here are available in the config passed into config object def self.run_cli(global_opts, global_config, plugin_config, args=ARGV) # a list of subcommands for this plugin, if any sub_commands = [] if sub_commands.count > 0 sub_command_help = "Subcommands:\n#{sub_commands.join("\n")}\n" else sub_command_help = "" end plugin_opts = Trollop::options do version "#{Retrospec::<%= capitalized_plugin_name %>::VERSION} (c) Your Name" banner <<-EOS A short description of your plugin goes here\n #{sub_command_help} EOS opt :option1, "Some Fancy option", :require => false, :short => '-n', :type => :string, :default => File.basename(File.expand_path(global_opts[:module_path])) stop_on sub_commands end # the passed in options will always override the config file plugin_data = plugin_opts.merge(global_config).merge(global_opts).merge(plugin_config).merge(plugin_opts) # define the default action to use the plugin here, the default is run sub_command = (args.shift || :run).to_sym # create an instance of this plugin plugin = self.new(plugin_data[:module_path],plugin_data) # check if the plugin supports the sub command if plugin.respond_to?(sub_command) plugin.send(sub_command) else puts "The subcommand #{sub_command} is not supported or valid" exit 1 end end # this is the main entry point that retrospec will use to make magic happen # this is called after everything has been initialized def run # the safe_create_module_files will render every file that ends with .retrospec.erb # under the templates/module_files folder in your gem and copy them to the destination. safe_create_module_files(template_dir, module_path, context) # Should you need to change the file name of the copied file you will have to move # the file outside of the module_files directory and # render it using: safe_create_template_file(file_path, template, context) end # the template directory located inside the your retrospec plugin gem # you should not have to modify this unless you move the templates directory # if this directory does not exist please create a directory templates/module_files def template_dir @template_dir ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates')) end end end end end