gem building machinery

This commit is contained in:
Ryan Tomayko 2010-03-08 17:45:52 -08:00
parent 3234f7013f
commit cf10e21b30
4 changed files with 117 additions and 0 deletions

18
COPYING Normal file
View File

@ -0,0 +1,18 @@
Copyright (c) 2010 Ryan Tomayko <http://tomayko.com/about>
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 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.

59
Rakefile Normal file
View File

@ -0,0 +1,59 @@
require 'rake/testtask'
task :default => :test
desc 'Run tests (default)'
Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/*_test.rb']
t.ruby_opts = ['-rubygems'] if defined? Gem
end
# PACKAGING =================================================================
if defined?(Gem)
SPEC = eval(File.read('rocco.gemspec'))
def package(ext='')
"pkg/rocco-#{SPEC.version}" + ext
end
desc 'Build packages'
task :package => %w[.gem .tar.gz].map {|e| package(e)}
desc 'Build and install as local gem'
task :install => package('.gem') do
sh "gem install #{package('.gem')}"
end
directory 'pkg/'
file package('.gem') => %w[pkg/ rocco.gemspec] + SPEC.files do |f|
sh "gem build rocco.gemspec"
mv File.basename(f.name), f.name
end
file package('.tar.gz') => %w[pkg/] + SPEC.files do |f|
sh "git archive --format=tar HEAD | gzip > #{f.name}"
end
end
# GEMSPEC ===================================================================
file 'rocco.gemspec' => FileList['{lib,test,bin}/**','Rakefile'] do |f|
# read version from tilt.rb
version = File.read('lib/rocco.rb')[/VERSION = '(.*)'/] && $1
# read spec file and split out manifest section
spec = File.
read(f.name).
sub(/s\.version\s*=\s*'.*'/, "s.version = '#{version}'")
parts = spec.split(" # = MANIFEST =\n")
# determine file list from git ls-files
files = `git ls-files`.
split("\n").sort.reject{ |file| file =~ /^\./ }.
map{ |file| " #{file}" }.join("\n")
# piece file back together and write...
parts[1] = " s.files = %w[\n#{files}\n ]\n"
spec = parts.join(" # = MANIFEST =\n")
spec.sub!(/s.date = '.*'/, "s.date = '#{Time.now.strftime("%Y-%m-%d")}'")
File.open(f.name, 'w') { |io| io.write(spec) }
puts "updated #{f.name}"
end

View File

@ -51,6 +51,8 @@ end
# whatever means necessary and return it as a string. With no `block`, the # whatever means necessary and return it as a string. With no `block`, the
# file is read to retrieve data. # file is read to retrieve data.
class Rocco class Rocco
VERSION = '0.1'
def initialize(filename, &block) def initialize(filename, &block)
@file = filename @file = filename
@data = @data =

38
rocco.gemspec Normal file
View File

@ -0,0 +1,38 @@
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.name = 'rocco'
s.version = '0.1'
s.date = '2010-03-08'
s.description = "Docco in Ruby"
s.summary = s.description
s.authors = ["Ryan Tomayko"]
s.email = "r@tomayko.com"
# = MANIFEST =
s.files = %w[
COPYING
README.md
Rakefile
bin/rocco
lib/rocco.rb
lib/rocco/layout.mustache
lib/rocco/layout.rb
rocco.gemspec
]
# = MANIFEST =
s.executables = ["rocco"]
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
s.add_dependency 'rdiscount'
s.add_dependency 'mustache'
s.has_rdoc = false
s.homepage = "http://rtomayko.github.com/rocco/"
s.require_paths = %w[lib]
s.rubygems_version = '1.1.1'
end