This repository has been archived by the owner on Apr 19, 2019. It is now read-only.
forked from gollum/gollum
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,146 @@ | |||
require 'rubygems' | |||
require 'rake' | |||
require 'date' | |||
|
|||
############################################################################# | |||
# | |||
# Helper functions | |||
# | |||
############################################################################# | |||
|
|||
def name | |||
@name ||= Dir['*.gemspec'].first.split('.').first | |||
end | |||
|
|||
def version | |||
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/] | |||
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1] | |||
end | |||
|
|||
def date | |||
Date.today.to_s | |||
end | |||
|
|||
def rubyforge_project | |||
name | |||
end | |||
|
|||
def gemspec_file | |||
"#{name}.gemspec" | |||
end | |||
|
|||
def gem_file | |||
"#{name}-#{version}.gem" | |||
end | |||
|
|||
def replace_header(head, header_name) | |||
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"} | |||
end | |||
|
|||
############################################################################# | |||
# | |||
# Standard tasks | |||
# | |||
############################################################################# | |||
|
|||
task :default => :test | |||
|
|||
require 'rake/testtask' | |||
Rake::TestTask.new(:test) do |test| | |||
test.libs << 'lib' << 'test' | |||
test.pattern = 'test/**/test_*.rb' | |||
test.verbose = true | |||
end | |||
|
|||
desc "Generate RCov test coverage and open in your browser" | |||
task :coverage do | |||
require 'rcov' | |||
sh "rm -fr coverage" | |||
sh "rcov test/test_*.rb" | |||
sh "open coverage/index.html" | |||
end | |||
|
|||
require 'rake/rdoctask' | |||
Rake::RDocTask.new do |rdoc| | |||
rdoc.rdoc_dir = 'rdoc' | |||
rdoc.title = "#{name} #{version}" | |||
rdoc.rdoc_files.include('README*') | |||
rdoc.rdoc_files.include('lib/**/*.rb') | |||
end | |||
|
|||
desc "Open an irb session preloaded with this library" | |||
task :console do | |||
sh "irb -rubygems -r ./lib/#{name}.rb" | |||
end | |||
|
|||
############################################################################# | |||
# | |||
# Custom tasks (add your own tasks here) | |||
# | |||
############################################################################# | |||
|
|||
|
|||
|
|||
############################################################################# | |||
# | |||
# Packaging tasks | |||
# | |||
############################################################################# | |||
|
|||
task :release => :build do | |||
unless `git branch` =~ /^\* master$/ | |||
puts "You must be on the master branch to release!" | |||
exit! | |||
end | |||
sh "git commit --allow-empty -a -m 'Release #{version}'" | |||
sh "git tag v#{version}" | |||
sh "git push origin master" | |||
sh "git push v#{version}" | |||
sh "gem push pkg/#{name}-#{version}.gem" | |||
end | |||
|
|||
task :build => :gemspec do | |||
sh "mkdir -p pkg" | |||
sh "gem build #{gemspec_file}" | |||
sh "mv #{gem_file} pkg" | |||
end | |||
|
|||
task :gemspec => :validate do | |||
# read spec file and split out manifest section | |||
spec = File.read(gemspec_file) | |||
head, manifest, tail = spec.split(" # = MANIFEST =\n") | |||
|
|||
# replace name version and date | |||
replace_header(head, :name) | |||
replace_header(head, :version) | |||
replace_header(head, :date) | |||
#comment this out if your rubyforge_project has a different name | |||
replace_header(head, :rubyforge_project) | |||
|
|||
# determine file list from git ls-files | |||
files = `git ls-files`. | |||
split("\n"). | |||
sort. | |||
reject { |file| file =~ /^\./ }. | |||
reject { |file| file =~ /^(rdoc|pkg)/ }. | |||
map { |file| " #{file}" }. | |||
join("\n") | |||
|
|||
# piece file back together and write | |||
manifest = " s.files = %w[\n#{files}\n ]\n" | |||
spec = [head, manifest, tail].join(" # = MANIFEST =\n") | |||
File.open(gemspec_file, 'w') { |io| io.write(spec) } | |||
puts "Updated #{gemspec_file}" | |||
end | |||
|
|||
task :validate do | |||
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"] | |||
unless libfiles.empty? | |||
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir." | |||
exit! | |||
end | |||
unless Dir['VERSION*'].empty? | |||
puts "A `VERSION` file at root level violates Gem best practices." | |||
exit! | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
Gem::Specification.new do |s| | |||
s.specification_version = 2 if s.respond_to? :specification_version= | |||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | |||
s.rubygems_version = '1.3.5' | |||
|
|||
s.name = 'gollum' | |||
s.version = '0.0.1' | |||
s.date = '2010-04-07' | |||
s.rubyforge_project = 'gollum' | |||
|
|||
s.summary = "Short description used in Gem listings." | |||
s.description = "Long description. Maybe copied from the README." | |||
|
|||
s.authors = ["Tom Preston-Werner"] | |||
s.email = 'tom@github.com' | |||
s.homepage = 'http://github.com/github/gollum' | |||
|
|||
s.require_paths = %w[lib] | |||
|
|||
s.executables = ["gollum"] | |||
s.default_executable = 'gollum' | |||
|
|||
s.rdoc_options = ["--charset=UTF-8"] | |||
s.extra_rdoc_files = %w[README.md LICENSE] | |||
|
|||
s.add_dependency('grit', [">= 2.0.0", "< 3.0.0"]) | |||
|
|||
s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"]) | |||
|
|||
# = MANIFEST = | |||
s.files = %w[ | |||
README.md | |||
Rakefile | |||
gollum.gemspec | |||
lib/gollum.rb | |||
lib/gollum/repo.rb | |||
test/helper.rb | |||
test/test_repo.rb | |||
] | |||
# = MANIFEST = | |||
|
|||
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ } | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
# external | |||
require 'grit' | |||
|
|||
# internal | |||
require 'gollum/repo' | |||
|
|||
module Gollum | |||
VERSION = '0.0.1' | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
module Gollum | |||
class Repo | |||
attr_accessor :path | |||
|
|||
# Initialize a new Gollum Repo. | |||
# | |||
# repo - The String path to the Git repository that holds the Gollum site. | |||
# | |||
# Returns a fresh Gollum::Repo. | |||
def initialize(path) | |||
self.path = path | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,31 @@ | |||
require 'rubygems' | |||
require 'test/unit' | |||
require 'shoulda' | |||
require 'mocha' | |||
|
|||
dir = File.dirname(File.expand_path(__FILE__)) | |||
$LOAD_PATH.unshift(File.join(dir, '..', 'lib')) | |||
$LOAD_PATH.unshift(dir) | |||
|
|||
require 'gollum' | |||
|
|||
## | |||
# test/spec/mini 3 | |||
# http://gist.github.com/25455 | |||
# chris@ozmm.org | |||
# file:lib/test/spec/mini.rb | |||
# | |||
def context(*args, &block) | |||
return super unless (name = args.first) && block | |||
require 'test/unit' | |||
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do | |||
def self.test(name, &block) | |||
define_method("test_#{name.gsub(/\W/,'_')}", &block) if block | |||
end | |||
def self.xtest(*args) end | |||
def self.setup(&block) define_method(:setup, &block) end | |||
def self.teardown(&block) define_method(:teardown, &block) end | |||
end | |||
(class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') } | |||
klass.class_eval &block | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
require 'helper' | |||
|
|||
class RepoTest < Test::Unit::TestCase | |||
def test_repo_creation | |||
repo = Gollum::Repo.new("examples/lotr") | |||
assert_equal "examples/lotr", repo.path | |||
end | |||
end |