Permalink
Browse files

initial skeleton for color_routes gem

  • Loading branch information...
0 parents commit f4a00798950ea0a1dbb74289116f61efec7b3b81 @nicooga committed Jan 13, 2012
Showing with 269 additions and 0 deletions.
  1. +21 −0 LICENSE
  2. +69 −0 README.md
  3. +150 −0 Rakefile
  4. +26 −0 color_routes.gemspec
  5. +3 −0 lib/color_routes.rb
21 LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) Nicolas Oga
+
+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.
69 README.md
@@ -0,0 +1,69 @@
+RakeGem
+=======
+
+# DESCRIPTION
+
+Ever wanted to manage your RubyGem in a sane way without having to resort to
+external dependencies like Jeweler or Hoe? Ever thought that Rake and a hand
+crafted gemspec should be enough to deal with these problems? If so, then
+RakeGem is here to make your life awesome!
+
+RakeGem is not a library. It is just a few simple file templates that you can
+copy into your project and easily customize to match your specific needs. It
+ships with a few Rake tasks to help you keep your gemspec up-to-date, build
+a gem, and release your library and gem to the world.
+
+RakeGem assumes you are using Git. This makes the Rake tasks easy to write. If
+you are using something else, you should be able to get RakeGem up and running
+with your system without too much editing.
+
+The RakeGem tasks were inspired by the
+[Sinatra](http://github.com/sinatra/sinatra) project.
+
+# INSTALLATION
+
+Take a look at `Rakefile` and `NAME.gemspec`. For new projects, you can start
+with these files and edit a few lines to make them fit into your library. If
+you have an existing project, you'll probably want to take the RakeGem
+versions and copy any custom stuff from your existing Rakefile and gemspec
+into them. As long as you're careful, the rake tasks should keep working.
+
+# ASSUMPTIONS
+
+RakeGem makes a few assumptions. You will either need to satisfy these
+assumptions or modify the rake tasks to work with your setup.
+
+You should have a file named `lib/NAME.rb` (where NAME is the name of your
+library) that contains a version line. It should look something like this:
+
+ module NAME
+ VERSION = '0.1.0'
+ end
+
+It is important that you use the constant `VERSION` and that it appear on a
+line by itself.
+
+# UPDATING THE VERSION
+
+In order to make a new release, you'll want to update the version. With
+RakeGem, you only need to do that in the `lib/NAME.rb` file. Everything else
+will use this find the canonical version of the library.
+
+# TASKS
+
+RakeGem provides three rake tasks:
+
+`rake gemspec` will update your gemspec with the latest version (taken from
+the `lib/NAME.rb` file) and file list (as reported by `git ls-files`).
+
+`rake build` will update your gemspec, build your gemspec into a gem, and
+place it in the `pkg` directory.
+
+`rake release` will update your gemspec, build your gem, make a commit with
+the message `Release 0.1.0` (with the correct version, obviously), tag the
+commit with `v0.1.0` (again with the correct version), and push the `master`
+branch and new tag to `origin`.
+
+Keep in mind that these are just simple Rake tasks and you can edit them
+however you please. Don't want to auto-commit or auto-push? Just delete those
+lines. You can bend RakeGem to your own needs. That's the whole point!
150 Rakefile
@@ -0,0 +1,150 @@
+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
+#
+#############################################################################
+
+desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
+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 origin v#{version}"
+ sh "gem push pkg/#{name}-#{version}.gem"
+end
+
+desc "Build #{gem_file} into the pkg directory"
+task :build => :gemspec do
+ sh "mkdir -p pkg"
+ sh "gem build #{gemspec_file}"
+ sh "mv #{gem_file} pkg"
+end
+
+desc "Generate #{gemspec_file}"
+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
+
+desc "Validate #{gemspec_file}"
+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
26 color_routes.gemspec
@@ -0,0 +1,26 @@
+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 = 'NAME'
+ s.version = '0.0'
+ s.date = '2010-01-01'
+ s.rubyforge_project = 'NAME'
+
+ s.summary = "Colorize rake routes output for rails."
+ s.description = "Colorize rake routes output for rails."
+
+ s.authors = ["Nicolas Oga"]
+ s.email = '2112.oga@gmail.com'
+ s.homepage = 'http://nicooga.github.com/NAME'
+
+ s.require_paths = %w[lib]
+
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.extra_rdoc_files = %w[README.md LICENSE]
+
+ # = MANIFEST =
+ s.files = %w[]
+ # = MANIFEST =
+end
3 lib/color_routes.rb
@@ -0,0 +1,3 @@
+module ColorRoutes
+ VERSION="0.0.1"
+end

0 comments on commit f4a0079

Please sign in to comment.