all repos — markup @ b7cabb1c81ea30035dd63a508a67a949c1846f4c

The code we use to render README.your_favorite_markup

Rakefile (view raw)

  1require 'rubygems'
  2require 'rake'
  3require 'date'
  4
  5#############################################################################
  6#
  7# Helper functions
  8#
  9#############################################################################
 10
 11def name
 12  @name ||= Dir['*.gemspec'].first.split('.').first
 13end
 14
 15def version
 16  line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
 17  line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
 18end
 19
 20def date
 21  Date.today.to_s
 22end
 23
 24def rubyforge_project
 25  name
 26end
 27
 28def gemspec_file
 29  "#{name}.gemspec"
 30end
 31
 32def gem_file
 33  "#{name}-#{version}.gem"
 34end
 35
 36def replace_header(head, header_name)
 37  head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
 38end
 39
 40#############################################################################
 41#
 42# Standard tasks
 43#
 44#############################################################################
 45
 46task :default => :test
 47
 48require 'rake/testtask'
 49Rake::TestTask.new(:test) do |test|
 50  test.libs << 'lib' << 'test'
 51  test.pattern = 'test/**/*_test.rb'
 52  test.verbose = true
 53end
 54
 55desc "Open an irb session preloaded with this library"
 56task :console do
 57  sh "irb -rubygems -r ./lib/#{name}.rb"
 58end
 59
 60#############################################################################
 61#
 62# Custom tasks (add your own tasks here)
 63#
 64#############################################################################
 65
 66desc "Kick it"
 67task :kick do
 68  exec "kicker -e rake test lib"
 69end
 70
 71#############################################################################
 72#
 73# Packaging tasks
 74#
 75#############################################################################
 76
 77desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
 78task :release => :build do
 79  unless `git branch` =~ /^\* master$/
 80    puts "You must be on the master branch to release!"
 81    exit!
 82  end
 83  sh "git commit --allow-empty -a -m 'Release #{version}'"
 84  sh "git tag v#{version}"
 85  sh "git push origin master"
 86  sh "git push origin v#{version}"
 87  sh "gem push pkg/#{name}-#{version}.gem"
 88end
 89
 90desc "Build #{gem_file} into the pkg directory"
 91task :build => :gemspec do
 92  sh "mkdir -p pkg"
 93  sh "gem build #{gemspec_file}"
 94  sh "mv #{gem_file} pkg"
 95end
 96
 97desc "Generate #{gemspec_file}"
 98task :gemspec => :validate do
 99  # read spec file and split out manifest section
100  spec = File.read(gemspec_file)
101  head, manifest, tail = spec.split("  # = MANIFEST =\n")
102
103  # replace name version and date
104  replace_header(head, :name)
105  replace_header(head, :version)
106  replace_header(head, :date)
107  #comment this out if your rubyforge_project has a different name
108  replace_header(head, :rubyforge_project)
109
110  # determine file list from git ls-files
111  files = `git ls-files`.
112    split("\n").
113    sort.
114    reject { |file| file =~ /^\./ }.
115    reject { |file| file =~ /^(rdoc|pkg)/ }.
116    map { |file| "    #{file}" }.
117    join("\n")
118
119  # piece file back together and write
120  manifest = "  s.files = %w[\n#{files}\n  ]\n"
121  spec = [head, manifest, tail].join("  # = MANIFEST =\n")
122  File.open(gemspec_file, 'w') { |io| io.write(spec) }
123  puts "Updated #{gemspec_file}"
124end
125
126desc "Validate #{gemspec_file}"
127task :validate do
128  unless Dir['VERSION*'].empty?
129    puts "A `VERSION` file at root level violates Gem best practices."
130    exit!
131  end
132end
133