Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit a2b08236d927257bf8a96e7aee0582e973d2a377 @TwP TwP committed Dec 29, 2007
4 History.txt
@@ -0,0 +1,4 @@
+== 1.0.0 /
+
+* 1 major enhancement
+ * Birthday!
23 Manifest.txt
@@ -0,0 +1,23 @@
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+bin/bones
+data/Manifest.txt
+data/tasks/doc.rake
+data/tasks/gem.rake
+data/tasks/manifest.rake
+data/tasks/rubyforge.rake
+data/tasks/setup.rb
+data/tasks/spec.rake
+data/tasks/test.rake
+data/tasks/website.rake
+lib/bones.rb
+tasks/doc.rake
+tasks/gem.rake
+tasks/manifest.rake
+tasks/rubyforge.rake
+tasks/setup.rb
+tasks/spec.rake
+tasks/test.rake
+tasks/website.rake
108 README.txt
@@ -0,0 +1,108 @@
+Mr. Bones
+ by Tim Pease
+ FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+* rubyforge
+* rcov
+* spec
+
+== INSTALL:
+
+* sudo gem install bones
+
+== MANUAL:
+
+Bag of rake tasks for easing the pain of project management. The tasks are controlled through options defined in the Rakefile. The tasks themselves are defined as '.rake' files in the tasks diectory.
+
+Use a Manifest.txt to control which files are included in the gem
+
+Use "depend_on" to declare dependencies
+
+ depend_on 'rake', '0.8.1'
+
+name = nil
+summary = nil
+description = nil
+changes = nil
+authors = nil
+email = nil
+url = nil
+version = ENV['VERSION'] || '0.0.0'
+rubyforge_name = nil
+exclude = %w(tmp$ bak$ ~$ CVS \.svn)
+extensions = FileList['ext/**/extconf.rb']
+ruby_opts = %w(-w)
+libs = []
+
+RDoc Options
+
+rdoc_opts = []
+rdoc_include = %w(^lib ^bin ^ext txt$)
+rdoc_exclude = %w(extconf\.rb$ ^Manifest\.txt$)
+rdoc_main = 'README.txt'
+rdoc_dir = 'doc'
+rdoc_remote_dir = nil
+
+Test::Unit Options
+
+tests = FileList['test/**/test_*.rb']
+test_file = 'test/all.rb'
+test_opts = []
+
+RSpec Options
+
+specs = FileList['spec/**/*_spec.rb']
+spec_opts = []
+
+RCov Options
+
+rcov_opts = ['--sort', 'coverage', '-T']
+
+Gem Options
+
+files = [] (from Manifest.txt)
+executables = PROJ.files.find_all {|fn| fn =~ %r/^bin/}
+dependencies = []
+need_tar = true
+need_zip = false
+
+
+== LICENSE:
+
+MIT License
+Copyright (c) 2007 - 2008
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Rakefile
@@ -0,0 +1,25 @@
+# $Id$
+
+load 'tasks/setup.rb'
+
+ensure_in_path 'lib'
+require 'bones'
+
+task :default => 'spec:run'
+
+PROJ.name = 'bones'
+PROJ.summary = ''
+PROJ.authors = 'Tim Pease'
+PROJ.email = 'tim.pease@gmail.com'
+PROJ.url = 'http://bones.rubyforge.org/'
+PROJ.description = paragraphs_of('README.txt', 3).join("\n\n")
+PROJ.changes = paragraphs_of('History.txt', 0..1).join("\n\n")
+PROJ.rubyforge_name = 'bones'
+PROJ.version = Bones::VERSION
+
+PROJ.exclude << '^doc'
+PROJ.rdoc_exclude << '^data'
+
+PROJ.spec_opts << '--color'
+
+# EOF
7 bin/bones
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(
+ File.join(File.dirname(__FILE__), '..', 'lib', 'bones'))
+Bones::Main.run ARGV
+
+# EOF
4 data/History.txt.erb
@@ -0,0 +1,4 @@
+== 1.0.0 / <%= Time.now.strftime("%Y-%m-%d") %>
+
+* 1 major enhancement
+ * Birthday!
0 data/Manifest.txt
No changes.
48 data/README.txt.erb
@@ -0,0 +1,48 @@
+<%= name %>
+ by FIX (your name)
+ FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2007 FIX
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 data/Rakefile.erb
@@ -0,0 +1,23 @@
+# Look in the tasks/setup.rb file for the various options that can be
+# configured in this Rakefile. The .rake files in the tasks directory
+# are where the options are used.
+
+load 'tasks/setup.rb'
+
+ensure_in_path 'lib'
+require '<%= name %>'
+
+task :default => 'spec:run'
+
+PROJ.name = '<%= name %>'
+PROJ.summary = 'FIX'
+PROJ.authors = 'FIX'
+PROJ.email = 'FIX'
+PROJ.url = 'FIX'
+PROJ.description = paragraphs_of('README.txt', 3).join("\n\n")
+PROJ.changes = paragraphs_of('History.txt', 0..1).join("\n\n")
+PROJ.rubyforge_name = '<%= name %>'
+
+PROJ.spec_opts << '--color'
+
+# EOF
8 data/bin/NAME.erb
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(
+ File.join(File.dirname(__FILE__), '..', 'lib', '<%= name %>'))
+
+# Put your code here
+
+# EOF
7 data/lib/NAME.rb.erb
@@ -0,0 +1,7 @@
+# $Id$
+
+class <%= classname %>
+ VERSION = '1.0.0'
+end
+
+# EOF
0 data/spec/NAME_spec.rb
No changes.
43 data/tasks/doc.rake
@@ -0,0 +1,43 @@
+# $Id: doc.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+require 'rake/rdoctask'
+
+namespace :doc do
+
+ desc 'Generate RDoc documentation'
+ Rake::RDocTask.new do |rd|
+ rd.main = PROJ.rdoc_main
+ rd.options << '-d' if !WIN32 and `which dot` =~ %r/\/dot/
+ rd.rdoc_dir = PROJ.rdoc_dir
+
+ incl = Regexp.new(PROJ.rdoc_include.join('|'))
+ excl = Regexp.new(PROJ.rdoc_exclude.join('|'))
+ files = PROJ.files.find_all do |fn|
+ case fn
+ when excl; false
+ when incl; true
+ else false end
+ end
+ rd.rdoc_files.push(*files)
+
+ title = "#{PROJ.name}-#{PROJ.version} Documentation"
+ title = "#{PROJ.rubyforge_name}'s " + title if PROJ.rubyforge_name != title
+
+ rd.options << "-t #{title}"
+ end
+
+ desc 'Generate ri locally for testing'
+ task :ri => :clobber_ri do
+ sh "#{RDOC} --ri -o ri ."
+ end
+
+ desc 'Remove ri products'
+ task :clobber_ri do
+ rm_r 'ri' rescue nil
+ end
+
+end # namespace :doc
+
+task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
+
+# EOF
85 data/tasks/gem.rake
@@ -0,0 +1,85 @@
+# $Id: gem.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+require 'rake/gempackagetask'
+
+namespace :gem do
+
+ PROJ.spec = Gem::Specification.new do |s|
+ s.name = PROJ.name
+ s.version = PROJ.version
+ s.summary = PROJ.summary
+ s.authors = Array(PROJ.authors)
+ s.email = PROJ.email
+ s.homepage = Array(PROJ.url).first
+ s.rubyforge_project = PROJ.rubyforge_name
+
+ s.description = PROJ.description
+
+ PROJ.dependencies.each do |dep|
+ s.add_dependency(*dep)
+ end
+ s.add_dependency('rake', ">= #{RAKEVERSION}")
+
+ s.files = PROJ.files
+ s.executables = PROJ.executables.map {|fn| File.basename(fn)}
+ s.extensions = PROJ.files.grep %r/extconf\.rb$/
+
+ s.bindir = 'bin'
+ dirs = Dir["{#{PROJ.libs.join(',')}}"]
+ s.require_paths = dirs unless dirs.empty?
+
+ incl = Regexp.new(PROJ.rdoc_include.join('|'))
+ excl = PROJ.rdoc_exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
+ excl = Regexp.new(excl.join('|'))
+ rdoc_files = PROJ.files.find_all do |fn|
+ case fn
+ when excl; false
+ when incl; true
+ else false end
+ end
+ s.rdoc_options = PROJ.rdoc_opts + ['--main', PROJ.rdoc_main]
+ s.extra_rdoc_files = rdoc_files
+ s.has_rdoc = true
+
+ if test ?f, PROJ.test_file
+ s.test_file = PROJ.test_file
+ else
+ s.test_files = PROJ.tests.to_a
+ end
+
+ # Do any extra stuff the user wants
+# spec_extras.each do |msg, val|
+# case val
+# when Proc
+# val.call(s.send(msg))
+# else
+# s.send "#{msg}=", val
+# end
+# end
+ end
+
+ desc 'Show information about the gem'
+ task :debug do
+ puts PROJ.spec.to_ruby
+ end
+
+ Rake::GemPackageTask.new(PROJ.spec) do |pkg|
+ pkg.need_tar = PROJ.need_tar
+ pkg.need_zip = PROJ.need_zip
+ end
+
+ desc 'Install the gem'
+ task :install => [:clobber, :package] do
+ sh "#{SUDO} #{GEM} install pkg/#{PROJ.spec.file_name}"
+ end
+
+ desc 'Uninstall the gem'
+ task :uninstall do
+ sh "#{SUDO} #{GEM} uninstall -v '#{PROJ.version}' #{PROJ.name}"
+ end
+
+end # namespace :gem
+
+task :clobber => 'gem:clobber_package'
+
+# EOF
39 data/tasks/manifest.rake
@@ -0,0 +1,39 @@
+# $Id: manifest.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+require 'find'
+
+namespace :manifest do
+
+ desc 'Verify the manfiest'
+ task :check do
+ fn = 'Manifest.tmp'
+ files = []
+ exclude = Regexp.new(PROJ.exclude.join('|'))
+ Find.find '.' do |path|
+ next unless test ?f, path
+ next if path =~ exclude
+ files << path[2..-1]
+ end
+
+ File.open(fn, 'w') {|fp| fp.puts files.sort}
+ system "#{DIFF} -du Manifest.txt #{fn}"
+ rm fn rescue nil
+ end
+
+ desc 'Create a new manifest'
+ task :create do
+ fn = 'Manifest.txt'
+ files = []
+ exclude = Regexp.new(PROJ.exclude.join('|'))
+ Find.find '.' do |path|
+ next unless test ?f, path
+ next if path =~ exclude
+ files << path[2..-1]
+ end
+
+ files << fn unless test ?f, fn
+ File.open(fn, 'w') {|fp| fp.puts files.sort}
+ end
+end
+
+# EOF
57 data/tasks/rubyforge.rake
@@ -0,0 +1,57 @@
+# $Id: rubyforge.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+if PROJ.rubyforge_name && HAVE_RUBYFORGE
+
+require 'rubyforge'
+require 'rake/contrib/sshpublisher'
+
+namespace :gem do
+ desc 'Package and upload to RubyForge'
+ task :release => [:clobber, :package] do |t|
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
+ pkg = "pkg/#{PROJ.spec.full_name}"
+
+ if $DEBUG then
+ puts "release_id = rf.add_release #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
+ puts "rf.add_file #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
+ end
+
+ rf = RubyForge.new
+ puts 'Logging in'
+ rf.login
+
+ c = rf.userconfig
+ c['release_notes'] = PROJ.description if PROJ.description
+ c['release_changes'] = PROJ.changes if PROJ.changes
+ c['preformatted'] = true
+
+ files = [(PROJ.need_tar ? "#{pkg}.tgz" : nil),
+ (PROJ.need_zip ? "#{pkg}.zip" : nil),
+ "#{pkg}.gem"].compact
+
+ puts "Releasing #{PROJ.name} v. #{PROJ.version}"
+ rf.add_release PROJ.rubyforge_name, PROJ.name, PROJ.version, *files
+ end
+end # namespace :gem
+
+
+namespace :doc do
+ desc "Publish RDoc to RubyForge"
+ task :release => %w(doc:clobber_rdoc doc:rdoc) do
+ config = YAML.load(
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
+ )
+
+ host = "#{config['username']}@rubyforge.org"
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge_name}/"
+ remote_dir << PROJ.rdoc_remote_dir || PROJ.name
+ local_dir = PROJ.rdoc_dir
+
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
+ end
+end # namespace :doc
+
+end # if HAVE_RUBYFORGE
+
+# EOF
129 data/tasks/setup.rb
@@ -0,0 +1,129 @@
+# $Id$
+
+require 'rubygems'
+require 'rake'
+require 'fileutils'
+require 'ostruct'
+
+PROJ = OpenStruct.new
+
+PROJ.name = nil
+PROJ.summary = nil
+PROJ.description = nil
+PROJ.changes = nil
+PROJ.authors = nil
+PROJ.email = nil
+PROJ.url = nil
+PROJ.version = ENV['VERSION'] || '0.0.0'
+PROJ.rubyforge_name = nil
+PROJ.exclude = %w(tmp$ bak$ ~$ CVS \.svn)
+
+# Rspec
+PROJ.specs = FileList['spec/**/*_spec.rb']
+PROJ.spec_opts = []
+
+# Test::Unit
+PROJ.tests = FileList['test/**/test_*.rb']
+PROJ.test_file = 'test/all.rb'
+PROJ.test_opts = []
+
+# Rcov
+PROJ.rcov_opts = ['--sort', 'coverage', '-T']
+
+# Rdoc
+PROJ.rdoc_opts = []
+PROJ.rdoc_include = %w(^lib ^bin ^ext txt$)
+PROJ.rdoc_exclude = %w(extconf\.rb$ ^Manifest\.txt$)
+PROJ.rdoc_main = 'README.txt'
+PROJ.rdoc_dir = 'doc'
+PROJ.rdoc_remote_dir = nil
+
+# Extensions
+PROJ.extensions = FileList['ext/**/extconf.rb']
+PROJ.ruby_opts = %w(-w)
+PROJ.libs = []
+%w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
+
+# Gem Packaging
+PROJ.files =
+ if test ?f, 'Manifest.txt'
+ files = File.readlines('Manifest.txt').map {|fn| fn.chomp.strip}
+ files.delete ''
+ files
+ else [] end
+PROJ.executables = PROJ.files.find_all {|fn| fn =~ %r/^bin/}
+PROJ.dependencies = []
+PROJ.need_tar = true
+PROJ.need_zip = false
+
+# Load the other rake files in the tasks folder
+Dir.glob('tasks/*.rake').sort.each {|fn| import fn}
+
+# Setup some constants
+WIN32 = %r/win32/ =~ RUBY_PLATFORM unless defined? WIN32
+
+DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
+
+def quiet( &block )
+ io = [STDOUT.dup, STDERR.dup]
+ STDOUT.reopen DEV_NULL
+ STDERR.reopen DEV_NULL
+ block.call
+ensure
+ STDOUT.reopen io.first
+ STDERR.reopen io.last
+end
+
+DIFF = if WIN32 then 'diff.exe'
+ else
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
+ else 'diff' end
+ end unless defined? DIFF
+
+SUDO = if WIN32 then ''
+ else
+ if quiet {system 'which sudo'} then 'sudo'
+ else '' end
+ end
+
+RCOV = WIN32 ? 'rcov.cmd' : 'rcov'
+GEM = WIN32 ? 'gem.cmd' : 'gem'
+
+%w(rcov spec rubyforge).each do |lib|
+ begin
+ require lib
+ Object.instance_eval {const_set "HAVE_#{lib.upcase}", true}
+ rescue LoadError
+ Object.instance_eval {const_set "HAVE_#{lib.upcase}", false}
+ end
+end
+
+# Reads a file at +path+ and spits out an array of the +paragraphs+
+# specified.
+#
+# changes = paragraphs_of('History.txt', 0..1).join("\n\n")
+# summary, *description = paragraphs_of('README.txt', 3, 3..8)
+#
+def paragraphs_of(path, *paragraphs)
+ File.read(path).delete("\r").split(/\n\n+/).values_at(*paragraphs)
+end
+
+# Adds the given gem _name_ to the current project's dependency list. An
+# optional gem _version_ can be given. If omitted, the newest gem version
+# will be used.
+#
+def depend_on( name, version = nil )
+ spec = Gem.source_index.find_name(name).last
+ version = spec.version.to_s if version.nil? and !spec.nil?
+
+ PROJ.dependencies << (version.nil? ? [name] : [name, ">= #{version}"])
+end
+
+# Adds the given _path_ to the include path if it is not already there
+#
+def ensure_in_path( path )
+ path = File.expand_path(path)
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
+end
+
+# EOF
37 data/tasks/spec.rake
@@ -0,0 +1,37 @@
+# $Id: spec.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+if HAVE_SPEC
+
+require 'spec/rake/spectask'
+
+namespace :spec do
+
+ desc 'Run all specs with basic output'
+ Spec::Rake::SpecTask.new(:run) do |t|
+ t.spec_opts = PROJ.spec_opts
+ t.spec_files = PROJ.specs
+ end
+
+ desc 'Run all specs with text output'
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
+ t.spec_opts = PROJ.spec_opts + ['--format', 'specdoc']
+ t.spec_files = PROJ.specs
+ end
+
+ if HAVE_RCOV
+ desc 'Run all specs with RCov'
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_opts = PROJ.spec_opts
+ t.spec_files = PROJ.specs
+ t.rcov = true
+ t.rcov_opts = PROJ.rcov_opts + ['--exclude', 'spec']
+ end
+ end
+
+end # namespace :spec
+
+task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
+
+end # if HAVE_SPEC
+
+# EOF
35 data/tasks/test.rake
@@ -0,0 +1,35 @@
+# $Id$
+
+require 'rake/testtask'
+
+namespace :test do
+
+ Rake::TestTask.new(:run) do |t|
+ t.libs = PROJ.libs
+ t.test_files = if test ?f, PROJ.test_file then [PROJ.test_file]
+ else PROJ.tests end
+ t.ruby_opts += PROJ.ruby_opts
+ t.ruby_opts += PROJ.test_opts
+ end
+
+ if HAVE_RCOV
+ desc 'Run rcov on the unit tests'
+ task :rcov => :clobber_rcov do
+ opts = PROJ.rcov_opts.join(' ')
+ files = if test ?f, PROJ.test_file then [PROJ.test_file]
+ else PROJ.tests end
+ files = files.join(' ')
+ sh "#{RCOV} #{files} #{opts}"
+ end
+
+ desc 'Remove rcov products'
+ task :clobber_rcov do
+ rm_r 'coverage' rescue nil
+ end
+ end
+
+end # namespace :test
+
+task :clobber => 'test:clobber_rcov' if HAVE_RCOV
+
+# EOF
38 data/tasks/website.rake
@@ -0,0 +1,38 @@
+# $Id: website.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+namespace :website do
+
+ desc 'Build the Webby website'
+ task :build do
+ begin
+ olddir = pwd
+ chdir 'examples/webby'
+ sh 'rake build'
+ cp_r 'output/.', olddir + '/doc'
+ ensure
+ chdir olddir
+ end
+ end
+
+ desc 'Remove the Webby website'
+ task :clobber do
+ rm_r 'doc' rescue nil
+ end
+
+ desc 'Publish the website to RubyForge'
+ task :release => %w(website:clobber doc:rdoc website:build) do
+ config = YAML.load(
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
+ )
+
+ host = "#{config['username']}@rubyforge.org"
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge_name}/"
+
+ sh "rsync --delete -rulptzCF doc/ #{host}:#{remote_dir}"
+ end
+
+end # namespace :website
+
+task :clobber => 'website:clobber'
+
+# EOF
0 data/test/test_NAME.rb
No changes.
177 lib/bones.rb
@@ -0,0 +1,177 @@
+# $Id$
+
+require 'fileutils'
+require 'optparse'
+require 'erb'
+
+module Bones
+
+ VERSION = '0.1.0' # :nodoc:
+ PATH = File.expand_path(File.join(File.dirname(__FILE__), '..')) # :nodoc:
+
+ class Main
+
+ attr_writer :update
+ attr_accessor :name, :data
+
+ # Create a new instance of Main, and run the +bones+ application given
+ # the command line _args_.
+ #
+ def self.run( args )
+ bones = self.new
+ bones.parse args
+
+ if bones.update? then bones.update
+ else bones.create end
+ end
+
+ # Parse the command line arguments and store the values for later use by
+ # the +create+ and +update+ methods.
+ #
+ def parse( args )
+ self.data = File.join(::Bones::PATH, 'data')
+ self.update = false
+
+ opts = OptionParser.new
+ opts.banner << ' project_name'
+
+ opts.separator ''
+ opts.on('-u', '--update',
+ 'update the rake tasks for the project') {self.update = true}
+
+ opts.separator ''
+ opts.separator 'common options:'
+
+ opts.on_tail( '-h', '--help', 'show this message' ) {puts opts; exit}
+ opts.on_tail( '--version', 'show version' ) do
+ puts "Bones #{::Bones::VERSION}"
+ exit
+ end
+
+ # parse the command line arguments
+ opts.parse! args
+ self.name = args.shift
+
+ if name.nil?
+ puts opts
+ ::Kernel.abort
+ end
+ nil
+ end
+
+ # Returns +true+ if we are updating an already existing project. Returns
+ # +false+ if we are creating a new project.
+ #
+ def update?
+ @update
+ end
+
+ # Returns the project name but converted to be useable as a Ruby class
+ # name.
+ #
+ def classname
+ name.split('_').map {|x| x.capitalize}.join
+ end
+
+ #
+ #
+ def create
+ # see if the directory already exists
+ abort "'#{name}' already exists" if test ?e, name
+
+ files_to_copy.each {|fn| cp fn}
+
+ pwd = File.expand_path(FileUtils.pwd)
+ begin
+ FileUtils.cd name
+ system "rake manifest:create 2>&1 > /dev/null"
+ ensure
+ FileUtils.cd pwd
+ end
+
+ # * copy files from either
+ # 1) the user's '.bones/data' directory or
+ # 2) the Bones 'data' directory
+ #
+ # TODO - figure out if this really is the best way of doing this
+ # should I just use either the .bones data or the gem data, not
+ # both
+ end
+
+ # Archive any existing tasks in the project's tasks folder, and then
+ # copy in new tasks from the bones/data directory.
+ #
+ def update
+ abort "'#{name}' does no exist" unless test ?e, name
+
+ task_dir = File.join(name, 'tasks')
+ abort "no tasks directory found in '#{name}'" unless test ?d, task_dir
+
+ archive_dir = File.join(task_dir, 'archive')
+ FileUtils.rm_rf archive_dir
+ FileUtils.mkdir archive_dir
+
+ Dir.glob(File.join(task_dir, '*')).each do |fn|
+ next if fn == archive_dir
+ FileUtils.mv fn, archive_dir
+ end
+
+ files_to_copy.each do |fn|
+ next unless 'tasks' == File.basename(File.dirname(fn))
+ cp fn
+ end
+ end
+
+
+ private
+
+ # Copy a file from the Bones prototype project location to the user
+ # specified project location. A message will be displayed to the screen
+ # indicating tha the file is being created.
+ #
+ def cp( file )
+ dir = File.join(name, File.dirname(file))
+ dst = File.join(dir, File.basename(file, '.erb').sub('NAME', name))
+ src = File.join(data, file)
+
+ FileUtils.mkdir_p(dir)
+
+ if '.erb' == File.extname(file)
+ txt = ERB.new(File.read(src), nil, '-').result(binding)
+ File.open(dst, 'w') {|fd| fd.write(txt)}
+ else
+ FileUtils.cp src, dst
+ end
+
+ FileUtils.chmod(File.stat(src).mode, dst)
+ end
+
+ # Prints an abort _msg_ to the screen and then exits the Ruby interpreter.
+ #
+ def abort( msg )
+ STDERR.puts msg
+ exit 1
+ end
+
+ # Returns a list of the files to copy from the bones/data directory to
+ # the new project directory
+ #
+ def files_to_copy
+ rgxp = %r/\A#{data}\/?/o
+ exclude = %r/tmp$|bak$|~$|CVS|\.svn/o
+
+ ary = Dir.glob(File.join(data, '**', '*')).map do |filename|
+ next if exclude =~ filename
+ next if test(?d, filename)
+ filename.sub rgxp, ''
+ end
+
+ ary.compact!
+ ary.sort!
+ ary
+ end
+
+ end # class Main
+end # module Bones
+
+# EOF
43 tasks/doc.rake
@@ -0,0 +1,43 @@
+# $Id: doc.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+require 'rake/rdoctask'
+
+namespace :doc do
+
+ desc 'Generate RDoc documentation'
+ Rake::RDocTask.new do |rd|
+ rd.main = PROJ.rdoc_main
+ rd.options << '-d' if !WIN32 and `which dot` =~ %r/\/dot/
+ rd.rdoc_dir = PROJ.rdoc_dir
+
+ incl = Regexp.new(PROJ.rdoc_include.join('|'))
+ excl = Regexp.new(PROJ.rdoc_exclude.join('|'))
+ files = PROJ.files.find_all do |fn|
+ case fn
+ when excl; false
+ when incl; true
+ else false end
+ end
+ rd.rdoc_files.push(*files)
+
+ title = "#{PROJ.name}-#{PROJ.version} Documentation"
+ title = "#{PROJ.rubyforge_name}'s " + title if PROJ.rubyforge_name != title
+
+ rd.options << "-t #{title}"
+ end
+
+ desc 'Generate ri locally for testing'
+ task :ri => :clobber_ri do
+ sh "#{RDOC} --ri -o ri ."
+ end
+
+ desc 'Remove ri products'
+ task :clobber_ri do
+ rm_r 'ri' rescue nil
+ end
+
+end # namespace :doc
+
+task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
+
+# EOF
84 tasks/gem.rake
@@ -0,0 +1,84 @@
+# $Id: gem.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+require 'rake/gempackagetask'
+
+namespace :gem do
+
+ PROJ.spec = Gem::Specification.new do |s|
+ s.name = PROJ.name
+ s.version = PROJ.version
+ s.summary = PROJ.summary
+ s.authors = Array(PROJ.authors)
+ s.email = PROJ.email
+ s.homepage = Array(PROJ.url).first
+ s.rubyforge_project = PROJ.rubyforge_name
+
+ s.description = PROJ.description
+
+ PROJ.dependencies.each do |dep|
+ s.add_dependency(*dep)
+ end
+
+ s.files = PROJ.files
+ s.executables = PROJ.executables.map {|fn| File.basename(fn)}
+ s.extensions = PROJ.files.grep %r/extconf\.rb$/
+
+ s.bindir = 'bin'
+ dirs = Dir["{#{PROJ.libs.join(',')}}"]
+ s.require_paths = dirs unless dirs.empty?
+
+ incl = Regexp.new(PROJ.rdoc_include.join('|'))
+ excl = PROJ.rdoc_exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
+ excl = Regexp.new(excl.join('|'))
+ rdoc_files = PROJ.files.find_all do |fn|
+ case fn
+ when excl; false
+ when incl; true
+ else false end
+ end
+ s.rdoc_options = PROJ.rdoc_opts + ['--main', PROJ.rdoc_main]
+ s.extra_rdoc_files = rdoc_files
+ s.has_rdoc = true
+
+ if test ?f, PROJ.test_file
+ s.test_file = PROJ.test_file
+ else
+ s.test_files = PROJ.tests.to_a
+ end
+
+ # Do any extra stuff the user wants
+# spec_extras.each do |msg, val|
+# case val
+# when Proc
+# val.call(s.send(msg))
+# else
+# s.send "#{msg}=", val
+# end
+# end
+ end
+
+ desc 'Show information about the gem'
+ task :debug do
+ puts PROJ.spec.to_ruby
+ end
+
+ Rake::GemPackageTask.new(PROJ.spec) do |pkg|
+ pkg.need_tar = PROJ.need_tar
+ pkg.need_zip = PROJ.need_zip
+ end
+
+ desc 'Install the gem'
+ task :install => [:clobber, :package] do
+ sh "#{SUDO} #{GEM} install pkg/#{PROJ.spec.file_name}"
+ end
+
+ desc 'Uninstall the gem'
+ task :uninstall do
+ sh "#{SUDO} #{GEM} uninstall -v '#{PROJ.version}' #{PROJ.name}"
+ end
+
+end # namespace :gem
+
+task :clobber => 'gem:clobber_package'
+
+# EOF
41 tasks/manifest.rake
@@ -0,0 +1,41 @@
+# $Id: manifest.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+require 'find'
+
+namespace :manifest do
+
+ desc 'Verify the manfiest'
+ task :check do
+ fn = 'Manifest.tmp'
+ files = []
+ exclude = Regexp.new(PROJ.exclude.join('|'))
+ Find.find '.' do |path|
+ path.sub! %r/^(\.\/|\/)/o, ''
+ next unless test ?f, path
+ next if path =~ exclude
+ files << path
+ end
+
+ File.open(fn, 'w') {|fp| fp.puts files.sort}
+ system "#{DIFF} -du Manifest.txt #{fn}"
+ rm fn rescue nil
+ end
+
+ desc 'Create a new manifest'
+ task :create do
+ fn = 'Manifest.txt'
+ files = []
+ exclude = Regexp.new(PROJ.exclude.join('|'))
+ Find.find '.' do |path|
+ path.sub! %r/^(\.\/|\/)/o, ''
+ next unless test ?f, path
+ next if path =~ exclude
+ files << path
+ end
+
+ files << fn unless test ?f, fn
+ File.open(fn, 'w') {|fp| fp.puts files.sort}
+ end
+end
+
+# EOF
57 tasks/rubyforge.rake
@@ -0,0 +1,57 @@
+# $Id: rubyforge.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+if PROJ.rubyforge_name && HAVE_RUBYFORGE
+
+require 'rubyforge'
+require 'rake/contrib/sshpublisher'
+
+namespace :gem do
+ desc 'Package and upload to RubyForge'
+ task :release => [:clobber, :package] do |t|
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
+ pkg = "pkg/#{PROJ.spec.full_name}"
+
+ if $DEBUG then
+ puts "release_id = rf.add_release #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
+ puts "rf.add_file #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
+ end
+
+ rf = RubyForge.new
+ puts 'Logging in'
+ rf.login
+
+ c = rf.userconfig
+ c['release_notes'] = PROJ.description if PROJ.description
+ c['release_changes'] = PROJ.changes if PROJ.changes
+ c['preformatted'] = true
+
+ files = [(PROJ.need_tar ? "#{pkg}.tgz" : nil),
+ (PROJ.need_zip ? "#{pkg}.zip" : nil),
+ "#{pkg}.gem"].compact
+
+ puts "Releasing #{PROJ.name} v. #{PROJ.version}"
+ rf.add_release PROJ.rubyforge_name, PROJ.name, PROJ.version, *files
+ end
+end # namespace :gem
+
+
+namespace :doc do
+ desc "Publish RDoc to RubyForge"
+ task :release => %w(doc:clobber_rdoc doc:rdoc) do
+ config = YAML.load(
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
+ )
+
+ host = "#{config['username']}@rubyforge.org"
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge_name}/"
+ remote_dir << PROJ.rdoc_remote_dir || PROJ.name
+ local_dir = PROJ.rdoc_dir
+
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
+ end
+end # namespace :doc
+
+end # if HAVE_RUBYFORGE
+
+# EOF
129 tasks/setup.rb
@@ -0,0 +1,129 @@
+# $Id$
+
+require 'rubygems'
+require 'rake'
+require 'fileutils'
+require 'ostruct'
+
+PROJ = OpenStruct.new
+
+PROJ.name = nil
+PROJ.summary = nil
+PROJ.description = nil
+PROJ.changes = nil
+PROJ.authors = nil
+PROJ.email = nil
+PROJ.url = nil
+PROJ.version = ENV['VERSION'] || '0.0.0'
+PROJ.rubyforge_name = nil
+PROJ.exclude = %w(tmp$ bak$ ~$ CVS \.svn)
+
+# Rspec
+PROJ.specs = FileList['spec/**/*_spec.rb']
+PROJ.spec_opts = []
+
+# Test::Unit
+PROJ.tests = FileList['test/**/test_*.rb']
+PROJ.test_file = 'test/all.rb'
+PROJ.test_opts = []
+
+# Rcov
+PROJ.rcov_opts = ['--sort', 'coverage', '-T']
+
+# Rdoc
+PROJ.rdoc_opts = []
+PROJ.rdoc_include = %w(^lib ^bin ^ext txt$)
+PROJ.rdoc_exclude = %w(extconf\.rb$ ^Manifest\.txt$)
+PROJ.rdoc_main = 'README.txt'
+PROJ.rdoc_dir = 'doc'
+PROJ.rdoc_remote_dir = nil
+
+# Extensions
+PROJ.extensions = FileList['ext/**/extconf.rb']
+PROJ.ruby_opts = %w(-w)
+PROJ.libs = []
+%w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
+
+# Gem Packaging
+PROJ.files =
+ if test ?f, 'Manifest.txt'
+ files = File.readlines('Manifest.txt').map {|fn| fn.chomp.strip}
+ files.delete ''
+ files
+ else [] end
+PROJ.executables = PROJ.files.find_all {|fn| fn =~ %r/^bin/}
+PROJ.dependencies = []
+PROJ.need_tar = true
+PROJ.need_zip = false
+
+# Load the other rake files in the tasks folder
+Dir.glob('tasks/*.rake').sort.each {|fn| import fn}
+
+# Setup some constants
+WIN32 = %r/win32/ =~ RUBY_PLATFORM unless defined? WIN32
+
+DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
+
+def quiet( &block )
+ io = [STDOUT.dup, STDERR.dup]
+ STDOUT.reopen DEV_NULL
+ STDERR.reopen DEV_NULL
+ block.call
+ensure
+ STDOUT.reopen io.first
+ STDERR.reopen io.last
+end
+
+DIFF = if WIN32 then 'diff.exe'
+ else
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
+ else 'diff' end
+ end unless defined? DIFF
+
+SUDO = if WIN32 then ''
+ else
+ if quiet {system 'which sudo'} then 'sudo'
+ else '' end
+ end
+
+RCOV = WIN32 ? 'rcov.cmd' : 'rcov'
+GEM = WIN32 ? 'gem.cmd' : 'gem'
+
+%w(rcov spec rubyforge).each do |lib|
+ begin
+ require lib
+ Object.instance_eval {const_set "HAVE_#{lib.upcase}", true}
+ rescue LoadError
+ Object.instance_eval {const_set "HAVE_#{lib.upcase}", false}
+ end
+end
+
+# Reads a file at +path+ and spits out an array of the +paragraphs+
+# specified.
+#
+# changes = paragraphs_of('History.txt', 0..1).join("\n\n")
+# summary, *description = paragraphs_of('README.txt', 3, 3..8)
+#
+def paragraphs_of(path, *paragraphs)
+ File.read(path).delete("\r").split(/\n\n+/).values_at(*paragraphs)
+end
+
+# Adds the given gem _name_ to the current project's dependency list. An
+# optional gem _version_ can be given. If omitted, the newest gem version
+# will be used.
+#
+def depend_on( name, version = nil )
+ spec = Gem.source_index.find_name(name).last
+ version = spec.version.to_s if version.nil? and !spec.nil?
+
+ PROJ.dependencies << (version.nil? ? [name] : [name, ">= #{version}"])
+end
+
+# Adds the given _path_ to the include path if it is not already there
+#
+def ensure_in_path( path )
+ path = File.expand_path(path)
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
+end
+
+# EOF
37 tasks/spec.rake
@@ -0,0 +1,37 @@
+# $Id: spec.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+if HAVE_SPEC
+
+require 'spec/rake/spectask'
+
+namespace :spec do
+
+ desc 'Run all specs with basic output'
+ Spec::Rake::SpecTask.new(:run) do |t|
+ t.spec_opts = PROJ.spec_opts
+ t.spec_files = PROJ.specs
+ end
+
+ desc 'Run all specs with text output'
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
+ t.spec_opts = PROJ.spec_opts + ['--format', 'specdoc']
+ t.spec_files = PROJ.specs
+ end
+
+ if HAVE_RCOV
+ desc 'Run all specs with RCov'
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_opts = PROJ.spec_opts
+ t.spec_files = PROJ.specs
+ t.rcov = true
+ t.rcov_opts = PROJ.rcov_opts + ['--exclude', 'spec']
+ end
+ end
+
+end # namespace :spec
+
+task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
+
+end # if HAVE_SPEC
+
+# EOF
35 tasks/test.rake
@@ -0,0 +1,35 @@
+# $Id$
+
+require 'rake/testtask'
+
+namespace :test do
+
+ Rake::TestTask.new(:run) do |t|
+ t.libs = PROJ.libs
+ t.test_files = if test ?f, PROJ.test_file then [PROJ.test_file]
+ else PROJ.tests end
+ t.ruby_opts += PROJ.ruby_opts
+ t.ruby_opts += PROJ.test_opts
+ end
+
+ if HAVE_RCOV
+ desc 'Run rcov on the unit tests'
+ task :rcov => :clobber_rcov do
+ opts = PROJ.rcov_opts.join(' ')
+ files = if test ?f, PROJ.test_file then [PROJ.test_file]
+ else PROJ.tests end
+ files = files.join(' ')
+ sh "#{RCOV} #{files} #{opts}"
+ end
+
+ desc 'Remove rcov products'
+ task :clobber_rcov do
+ rm_r 'coverage' rescue nil
+ end
+ end
+
+end # namespace :test
+
+task :clobber => 'test:clobber_rcov' if HAVE_RCOV
+
+# EOF
38 tasks/website.rake
@@ -0,0 +1,38 @@
+# $Id: website.rake 77 2007-12-22 21:26:09Z tim_pease $
+
+namespace :website do
+
+ desc 'Build the Webby website'
+ task :build do
+ begin
+ olddir = pwd
+ chdir 'examples/webby'
+ sh 'rake build'
+ cp_r 'output/.', olddir + '/doc'
+ ensure
+ chdir olddir
+ end
+ end
+
+ desc 'Remove the Webby website'
+ task :clobber do
+ rm_r 'doc' rescue nil
+ end
+
+ desc 'Publish the website to RubyForge'
+ task :release => %w(website:clobber doc:rdoc website:build) do
+ config = YAML.load(
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
+ )
+
+ host = "#{config['username']}@rubyforge.org"
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge_name}/"
+
+ sh "rsync --delete -rulptzCF doc/ #{host}:#{remote_dir}"
+ end
+
+end # namespace :website
+
+task :clobber => 'website:clobber'
+
+# EOF

0 comments on commit a2b0823

Please sign in to comment.
Something went wrong with that request. Please try again.