diff --git a/projects/gem_plugin/Rakefile b/projects/gem_plugin/Rakefile index 0dbfcf29..528f2951 100644 --- a/projects/gem_plugin/Rakefile +++ b/projects/gem_plugin/Rakefile @@ -23,7 +23,9 @@ setup_gem(name, version) do |spec| spec.summary = "A plugin system based only on rubygems that uses dependencies only" spec.description = spec.summary spec.test_file = "test/test_plugins.rb" - scripts=[] + spec.files += Dir.glob("resources/**/*") + spec.executables=["gpgen"] + spec.add_dependency("rake", ">= 0.7") end task :install => [:test, :package] do diff --git a/projects/gem_plugin/bin/gpgen b/projects/gem_plugin/bin/gpgen new file mode 100755 index 00000000..db77bfdb --- /dev/null +++ b/projects/gem_plugin/bin/gpgen @@ -0,0 +1,60 @@ +require 'erb' +require 'fileutils' +include FileUtils + +if ARGV.length != 1 + STDERR.puts "ERROR: You must give a name for your plugin and directory." + STDERR.puts "usage: gpgen name" + STDERR.puts "example: gpgen mygemplugin" + exit 1 +end + +# setup the required binding variables for erb processing later +project = ARGV.shift +gem_plugin_base = File.expand_path(File.join(File.dirname(__FILE__), "..")) +resources = File.join(gem_plugin_base, "resources") +gem_plugin_version = gem_plugin_base[gem_plugin_base.rindex("-")+1 .. -1] + + +# make the dir if it don't exist +if not File.exist? project + puts "Creating directory #{project}" + mkdir project +else + puts "Directory #{project} exists, skipping." +end + + +# go through all the resource files, erb them, and write them verbatim to output +# do not overwrite if exists already + +Dir.glob("#{resources}/**/*") do |infile| + outfile = File.join(project, infile[resources.length .. -1]) + if File.exist? outfile + puts "File #{outfile} exists, skipping." + else + if File.directory? infile + puts "Creating directory #{outfile}" + mkdir_p outfile + elsif File.file? infile + puts "Creating file #{outfile}" + open(infile) do |content| + template = ERB.new(content.read) + open(outfile,"w") {|f| f.write(template.result(binding)) } + end + else + puts "!!! Resources contains something not a file or directory." + puts "Skipping #{infile}." + end + end +end + +# Finally, move the base init.rb to the right dir +init_file = File.join(project,"lib",project) +if File.exist? init_file + puts "File init.rb already exists, skipping." + puts "WARNING: There might be a junk '#{project}/lib/project/init.rb' file you can delete." +else + puts "Creating proper '#{project}/lib/#{project}/init.rb' file" + mv File.join(project,"lib","project"), init_file +end diff --git a/projects/gem_plugin/resources/COPYING b/projects/gem_plugin/resources/COPYING new file mode 100644 index 00000000..bff74f4d --- /dev/null +++ b/projects/gem_plugin/resources/COPYING @@ -0,0 +1 @@ +No copying restrictions/license given. \ No newline at end of file diff --git a/projects/gem_plugin/resources/LICENSE b/projects/gem_plugin/resources/LICENSE new file mode 100644 index 00000000..5ac4caba --- /dev/null +++ b/projects/gem_plugin/resources/LICENSE @@ -0,0 +1 @@ +No license given. \ No newline at end of file diff --git a/projects/gem_plugin/resources/README b/projects/gem_plugin/resources/README new file mode 100644 index 00000000..6d354aae --- /dev/null +++ b/projects/gem_plugin/resources/README @@ -0,0 +1,5 @@ +== <%= project.capitalize %> GemPlugin + +You should document your project here. + + diff --git a/projects/gem_plugin/resources/Rakefile b/projects/gem_plugin/resources/Rakefile new file mode 100644 index 00000000..a9d6dac9 --- /dev/null +++ b/projects/gem_plugin/resources/Rakefile @@ -0,0 +1,37 @@ +require 'rake' +require 'rake/testtask' +require 'rake/clean' +require 'rake/gempackagetask' +require 'rake/rdoctask' +require 'tools/rakehelp' +require 'fileutils' +include FileUtils + +setup_tests +setup_clean ["pkg", "lib/*.bundle", "*.gem", ".config"] + +setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc'] + +desc "Does a full compile, test run" +task :default => [:test, :package] + +version="0.1" +name="<%= project %>" + +setup_gem(name, version) do |spec| + spec.summary = "The <%= project %> GemPlugin" + spec.description = spec.summary + spec.author="Nobody" + spec.add_dependency('gem_plugin', '>= <%= gem_plugin_version %>') + spec.files += Dir.glob("resources/**/*") +end + + +task :install => [:test, :package] do + sh %{sudo gem install pkg/#{name}-#{version}.gem} +end + +task :uninstall => [:clean] do + sh %{sudo gem uninstall #{name}} +end + diff --git a/projects/gem_plugin/resources/lib/project/init.rb b/projects/gem_plugin/resources/lib/project/init.rb new file mode 100644 index 00000000..7d6544a4 --- /dev/null +++ b/projects/gem_plugin/resources/lib/project/init.rb @@ -0,0 +1,6 @@ +require 'gem_plugin' + +# give this class the name you want for your command <%= project %> +class ChangeME < GemPlugin::Plugin "/somecategory" +end + diff --git a/projects/gem_plugin/resources/resources/defaults.yaml b/projects/gem_plugin/resources/resources/defaults.yaml new file mode 100644 index 00000000..10d2a473 --- /dev/null +++ b/projects/gem_plugin/resources/resources/defaults.yaml @@ -0,0 +1,2 @@ +--- +:debug: false diff --git a/projects/gem_plugin/resources/tools/rakehelp.rb b/projects/gem_plugin/resources/tools/rakehelp.rb new file mode 100644 index 00000000..d8505a25 --- /dev/null +++ b/projects/gem_plugin/resources/tools/rakehelp.rb @@ -0,0 +1,105 @@ + +def make(makedir) + Dir.chdir(makedir) do + sh(PLATFORM =~ /win32/ ? 'nmake' : 'make') + end +end + + +def extconf(dir) + Dir.chdir(dir) do ruby "extconf.rb" end +end + + +def setup_tests + Rake::TestTask.new do |t| + t.libs << "test" + t.test_files = FileList['test/test*.rb'] + t.verbose = true + end +end + + +def setup_clean otherfiles + files = ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log'] + otherfiles + CLEAN.include(files) +end + + +def setup_rdoc files + Rake::RDocTask.new do |rdoc| + rdoc.rdoc_dir = 'doc/rdoc' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.add(files) + end +end + + +def setup_extension(dir, extension) + ext = "ext/#{dir}" + ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}" + ext_files = FileList[ + "#{ext}/*.c", + "#{ext}/*.h", + "#{ext}/extconf.rb", + "#{ext}/Makefile", + "lib" + ] + + task "lib" do + directory "lib" + end + + desc "Builds just the #{extension} extension" + task extension.to_sym => ["#{ext}/Makefile", ext_so ] + + file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do + extconf "#{ext}" + end + + file ext_so => ext_files do + make "#{ext}" + cp ext_so, "lib" + end +end + + +def base_gem_spec(pkg_name, pkg_version) + pkg_version = pkg_version + pkg_name = pkg_name + pkg_file_name = "#{pkg_name}-#{pkg_version}" + Gem::Specification.new do |s| + s.name = pkg_name + s.version = pkg_version + s.platform = Gem::Platform::RUBY + s.has_rdoc = true + s.extra_rdoc_files = [ "README" ] + + s.files = %w(COPYING LICENSE README Rakefile) + + Dir.glob("{bin,doc/rdoc,test,lib}/**/*") + + Dir.glob("ext/**/*.{h,c,rb}") + + Dir.glob("examples/**/*.rb") + + Dir.glob("tools/*.rb") + + s.require_path = "lib" + s.extensions = FileList["ext/**/extconf.rb"].to_a + s.bindir = "bin" + end +end + +def setup_gem(pkg_name, pkg_version) + spec = base_gem_spec(pkg_name, pkg_version) + yield spec if block_given? + + Rake::GemPackageTask.new(spec) do |p| + p.gem_spec = spec + p.need_tar = true + end +end + +def setup_win32_gem(pkg_name, pkg_version) + spec = base_gem_spec(pkg_name, pkg_version) + yield spec if block_given? + + Gem::Builder.new(spec).build +end