Skip to content
Browse files

Using bundler.

  • Loading branch information...
1 parent 69407eb commit e5888c6107077216cf66867aee3a897466ec09ed @fnando committed Apr 27, 2011
Showing with 42 additions and 103 deletions.
  1. +2 −0 .gitignore
  2. +2 −70 Rakefile
  3. +16 −17 colorize.gemspec
  4. +14 −16 lib/colorize.rb
  5. +8 −0 lib/colorize/version.rb
View
2 .gitignore
@@ -0,0 +1,2 @@
+pkg
+.DS_Store
View
72 Rakefile
@@ -1,70 +1,2 @@
-require "rake"
-require File.dirname(__FILE__) + "/lib/colorize"
-
-PKG_FILES = %w(Rakefile colorize.gemspec README.markdown lib/colorize.rb)
-
-spec = Gem::Specification.new do |s|
- s.name = "colorize"
- s.version = Colorize::VERSION
- s.summary = "Colorize add color to $stdout output"
- s.authors = ["Nando Vieira"]
- s.email = ["fnando.vieira@gmail.com"]
- s.homepage = "http://github.com/fnando/colorize"
- s.has_rdoc = false
- s.files = PKG_FILES
-
- s.add_dependency "main"
-end
-
-namespace :gem do
- # Thanks to the Merb project for this code.
- desc "Update Github Gemspec"
- task :update_gemspec do
- skip_fields = %w(new_platform original_platform specification_version loaded required_ruby_version rubygems_version platform )
-
- result = "# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!\n"
- result << "# RUN : 'rake gem:update_gemspec'\n\n"
- result << "Gem::Specification.new do |s|\n"
-
- spec.instance_variables.each do |ivar|
- value = spec.instance_variable_get(ivar)
- name = ivar.split("@").last
- next if name == "date"
-
- next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
- if name == "dependencies"
- value.each do |d|
- dep, *ver = d.to_s.split(" ")
- result << " s.add_dependency #{dep.inspect}, #{ver.join(" ").inspect.gsub(/[()]/, "").gsub(", runtime", "")}\n"
- end
- else
- case value
- when Array
- value = name != "files" ? value.inspect : value.inspect.split(",").join(",\n")
- when FalseClass
- when TrueClass
- when Fixnum
- when String
- value = value.inspect
- else
- value = value.to_s.inspect
- end
- result << " s.#{name} = #{value}\n"
- end
- end
-
- result << "end"
- File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << result}
- end
-
- desc "Build gem"
- task :build => [:update_gemspec] do
- system "gem build #{spec.instance_variable_get('@name')}.gemspec"
- end
-
- desc "Install gem"
- task :install => [:update_gemspec, :build] do
- system "sudo gem install #{spec.instance_variable_get('@name')}"
- system "rm *.gem"
- end
-end
+require "bundler"
+Bundler::GemHelper.install_tasks
View
33 colorize.gemspec
@@ -1,20 +1,19 @@
-# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!
-# RUN : 'rake gem:update_gemspec'
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "colorize/version"
Gem::Specification.new do |s|
- s.required_rubygems_version = ">= 0"
- s.has_rdoc = true
- s.email = ["fnando.vieira@gmail.com"]
- s.name = "colorize"
- s.homepage = "http://github.com/fnando/colorize"
- s.bindir = "bin"
- s.summary = "Colorize add color to $stdout output"
- s.add_dependency "main", ">= 0"
- s.version = "0.0.1"
+ s.name = "colorize"
+ s.version = Colorize::Version::STRING
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Nando Vieira"]
+ s.email = ["fnando.vieira@gmail.com"]
+ s.homepage = "http://rubygems.org/gems/colorize"
+ s.summary = "Make your $stdout colorful"
+ s.description = s.summary
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.files = ["Rakefile",
- "colorize.gemspec",
- "README.markdown",
- "lib/colorize.rb"]
- s.authors = ["Nando Vieira"]
-end
+end
View
30 lib/colorize.rb
@@ -1,8 +1,6 @@
module Colorize
extend self
-
- VERSION = "0.0.1"
-
+
COLORS = {
:black => "30",
:blue => "34",
@@ -14,7 +12,7 @@ module Colorize
:white => "37",
:yellow => "33"
}
-
+
BGCOLORS = {
:black => "40",
:blue => "44",
@@ -26,48 +24,48 @@ module Colorize
:white => "47",
:yellow => "43"
}
-
+
STYLES = {
:highlight => "1",
:blink => "5",
:underscore => "4"
}
-
+
def puts(string, options={})
Kernel.puts apply(string, options)
end
-
+
def apply(string, options={})
options = {
:style => []
}.merge(options)
-
+
options[:style] = [options[:style]].flatten
-
+
colors = []
-
+
options[:color] = options[:color].to_sym if options[:color]
options[:bgcolor] = options[:bgcolor].to_sym if options[:bgcolor]
-
+
colors << COLORS[options[:color]] if options[:color]
colors << BGCOLORS[options[:bgcolor]] if options[:bgcolor]
-
+
options[:style] << :highlight if [options[:color], options[:bgcolor]].include?(:white)
-
+
options[:style].each do |option|
colors << STYLES[option.to_sym]
end
-
+
colors.uniq!
colors.compact!
-
+
if ENV["COLORIZE"] == "0"
string
else
%(\e[#{colors.join(";")}m#{string}\e[0m)
end
end
-
+
def method_missing(color_name, *args)
if COLORS.keys.include?(color_name.to_sym)
string = args.shift
View
8 lib/colorize/version.rb
@@ -0,0 +1,8 @@
+module Colorize
+ module Version
+ MAJOR = 0
+ MINOR = 0
+ PATCH = 1
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
+ end
+end

0 comments on commit e5888c6

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