diff --git a/Rakefile b/Rakefile index 004f0654..8689de9a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,215 +1,65 @@ -begin - require 'rubygems' -rescue LoadError -end +begin; require 'rubygems'; rescue LoadError; end require 'rake' require 'rake/clean' -require 'rake/packagetask' require 'rake/gempackagetask' -require 'rake/rdoctask' - -require 'pp' -require 'date' require 'time' -require 'fileutils' - -include FileUtils - -$:.unshift File.join(File.dirname(__FILE__), "lib") - -require 'ramaze/version' -load 'rake_tasks/conf.rake' -load 'rake_tasks/maintenance.rake' -load 'rake_tasks/spec.rake' -load 'rake_tasks/coverage.rake' -load 'rake_tasks/release.rake' -load 'rake_tasks/git.rake' -load 'rake_tasks/gem.rake' -load 'rake_tasks/metric.rake' -load 'rake_tasks/doc.rake' - -task :default => ['spec'] -task :test => ['spec'] -# task :package => ['jquery'] - -desc 'download latest jquery and put in /lib/proto/public/js/jquery.js' -task :jquery do - require 'open-uri' - $stdout.sync = true - - File.open('lib/proto/public/js/jquery.js', 'w+') do |jquery| - remote = open('http://code.jquery.com/jquery-latest.js') - print "openend remote side, copying..." - while chunk = remote.read(4096) - print '.' - jquery.write(chunk) - end - puts " done." - end -end - -desc 'Check gemspec file list against real file list' -task :check_gemspec do - base_dir = File.expand_path(File.dirname(__FILE__)) - gemspec_files = eval(File.read(File.join(base_dir,'ramaze.gemspec'))).files.map{|file|File.join(base_dir,file)} - - deleted_files = gemspec_files.select{|file|!File.exists?(file)}.map{|file|file[(base_dir.size+1)..-1]} - - added_files = Dir.glob(File.join(File.dirname(__FILE__),'**/*')).select do |file| - !gemspec_files.index(file) - end.map do |file| - file[(base_dir.size+1)..-1] - end.select do |file| - !( file == 'pkg' or file =~ /.*\.gem/ ) - end - - unless deleted_files.empty? - puts "The following files appear in the gemspec but cannot be found:" - deleted_files.each do |file| - puts "\t#{file}" - end - end - unless added_files.empty? - puts "The following files exist, but cannot be found in the gemspec:" - added_files.each do |file| - puts "\t#{file}" - end - end -end - -task :rcov_dir do - mkdir_p 'doc/output/tools/rcov/' -end - -desc "Generate HTML coverage report" -task :rcov_summary => :rcov_dir do - `rcov --version` - raise LoadError, "Please `gem install rcov` first" if $?.exitstatus == 127 - raise "Run `rake coverage` to generate coverage data first" unless File.exists? 'coverage.data' - sh "rcov --aggregate coverage.data -o doc/output/tools/rcov/" -end - -desc "create bzip2 and tarball" -task :distribute => :gem do - sh "rm -rf pkg/ramaze-#{VERS}" - sh "mkdir -p pkg/ramaze-#{VERS}" - sh "cp -r {bin,doc,lib,examples,spec,Rakefile,README.markdown,rake_tasks} pkg/ramaze-#{VERS}/" - - Dir.chdir('pkg') do |pwd| - sh "tar -zcvf ramaze-#{VERS}.tar.gz ramaze-#{VERS}" - sh "tar -jcvf ramaze-#{VERS}.tar.bz2 ramaze-#{VERS}" - end - - sh "rm -rf pkg/ramaze-#{VERS}" -end - -desc "show a todolist from all the TODO tags in the source" -task :todo do - files = Dir[File.join(BASEDIR, '{lib,spec}', '**/*.rb')] - - files.each do |file| - lastline = todo = comment = long_comment = false - - File.readlines(file).each_with_index do |line, lineno| - lineno += 1 - comment = line =~ /^\s*?#.*?$/ - long_comment = line =~ /^=begin/ - long_comment = line =~ /^=end/ - todo = true if line =~ /TODO/ and (long_comment or comment) - todo = false if line.gsub('#', '').strip.empty? - todo = false unless comment or long_comment - if todo - unless lastline and lastline + 1 == lineno - puts - puts "vim #{file} +#{lineno}" - end - - l = line.strip.gsub(/^#\s*/, '') - print ' ' unless l =~ /^-/ - puts l - lastline = lineno - end - end - end -end - -desc "opens a simple readline that makes making requests easier" -task 'request' do - ARGV.clear - require 'open-uri' - require 'pp' - - loop do - print 'do request? [enter] ' - gets - begin - pp open('http://localhost:7000/xxx').read - rescue Object => ex - puts ex - end - end -end - -desc 'listing of available traits per class/module' -task 'traits' do - nodes = Hash.new{|h,k| h[k] = []} - Dir['lib/**/*.rb'].each do |file| - content = File.read(file) - traits = content.grep(/^\s*trait\s*:/) - traits.each do |trait| - space = content[0..content.index(trait)].scan(/^\s*(?:class|module)\s+(.*)$/) - space = space.flatten.join('::') - nodes[space] << trait.strip - end - end - - nodes.each do |space, traits| - puts space - traits.each do |trait| - print ' ', trait, "\n" - end - puts - end -end - -desc "Update doc/CHANGELOG" -task 'doc/CHANGELOG' do - File.open('doc/CHANGELOG', 'w+') do |f| - f.puts `git log` - end -end - -desc "#{README} to doc/README.html" -task 'doc/README.html' => [README] do - sh "maruku #{README}" - mv 'README.html', 'doc/README.html' -end - -desc "Compile the #{README} from the parts of doc/readme" -task README do - require 'enumerator' - - chapters = [ - 'About Ramaze', 'introduction', - 'Features Overview', 'features', - 'Basic Principles', 'principles', - 'Installation', 'installing', - 'Getting Started', 'getting_started', - 'A couple of Examples', 'examples', - 'How to find Help', 'getting_help', - 'Appendix', 'appendix', - 'And thanks to...', 'thanks', - ] - - File.open(README, 'w+') do |readme| - readme.puts COPYRIGHT.map{|l| l[1..-1]}, '' +require 'date' - chapters.each_slice(2) do |title, file| - file = File.join('doc', 'readme_chunks', "#{file}.txt") - chapter = File.read(file) - readme.puts "# #{title}", '', chapter - readme.puts '', '' unless title == chapters[-2] - end - end -end +PROJECT_SPECS = Dir['spec/{examples,ramaze,snippets}/**/*.rb'] +PROJECT_MODULE = 'Ramaze' +PROJECT_JQUERY_FILE = 'lib/proto/public/js/jquery.js' +PROJECT_README = 'README.markdown' +PROJECT_RUBYFORGE_GROUP_ID = 3034 +PROJECT_COPYRIGHT = [ + "# Copyright (c) #{Time.now.year} Michael Fellinger m.fellinger@gmail.com", + "# All files in this distribution are subject to the terms of the Ruby license." +] + +# To release the monthly version do: +# $ PROJECT_VERSION=2009.03 rake release + +GEMSPEC = Gem::Specification.new{|s| + s.name = 'ramaze' + s.author = "Michael 'manveru' Fellinger" + s.summary = "Ramaze is a simple and modular web framework" + s.description = s.summary + s.email = 'm.fellinger@gmail.com' + s.homepage = 'http://github.com/manveru/org' + s.platform = Gem::Platform::RUBY + s.version = (ENV['PROJECT_VERSION'] || Date.today.strftime("%Y.%m.%d")) + s.files = `git ls-files`.split("\n").sort + s.has_rdoc = true + s.require_path = 'lib' + s.bindir = "bin" + s.executables = ["ramaze"] + s.rubyforge_project = "ramaze" + s.add_dependency('rack', '>= 0.9.1') # lies! + s.add_dependency('innate', '>= 2009.03') + s.post_install_message = < [:bacon] + +CLEAN.include %w[ + **/.*.sw? + *.gem + .config + **/*~ + **/{data.db,cache.yaml} + *.yaml + pkg + rdoc + ydoc + *coverage* +] diff --git a/rake_tasks/conf.rake b/rake_tasks/conf.rake deleted file mode 100644 index 39d6e33b..00000000 --- a/rake_tasks/conf.rake +++ /dev/null @@ -1,72 +0,0 @@ -BASEDIR = File.expand_path(File.join(File.dirname(__FILE__), '..')) - -VERS = Ramaze::VERSION -COPYRIGHT = [ - "# Copyright (c) #{Time.now.year} Michael Fellinger m.fellinger@gmail.com", - "# All files in this distribution are subject to the terms of the Ruby license." -] -README = 'README.markdown' -CLEAN.include %w[ - **/.*.sw? - *.gem - .config - **/*~ - **/{data.db,cache.yaml} - *.yaml - pkg - rdoc - *coverage* -] -RDOC_OPTS = %W[ - --all - --quiet - --op rdoc - --line-numbers - --inline-source - --main #{README} - --opname index.html - --title "Ramaze\ documentation" - --exclude "^(spec|examples|bin|pkg)/" - --exclude "lib/proto" - --include "doc" - --accessor "trait" -] -RDOC_FILES = %W[ - lib doc #{README} doc/FAQ doc/CHANGELOG -] -POST_INSTALL_MESSAGE = %{ -#{'=' * 60} - -Thank you for installing Ramaze! -You can now do following: - -* Create a new project using the `ramaze' command: - ramaze --create yourproject - -#{'=' * 60} -}.strip - -AUTHOR_MAP = { - 'andy@tinnedfruit.org' => 'Andy Smith', - 'ahoward' => 'Ara T. Howard', - 'ara.t.howard@gmail.com' => 'Ara T. Howard', - 'blueonyx@dev-area.net' => 'Martin Hilbig', - 'clive@crous.co.za' => 'Clive Crous', - 'comp.lang.zenix+ramaze@gmail.com' => 'Colin Shea', - 'evaryont@gmx.us' => 'Colin Shea', - 'jesusisramazing.10.pistos@geoshell.com' => 'Pistos', - 'jesuswasramazing.10.pistos@geoshell.com' => 'Pistos', - 'keita.yamaguchi@gmail.com' => 'Keita Yamaguchi', - 'leo.borisenko@gmail.com' => 'Leo Borisenko', - 'manveru@weez-int.com' => 'Michael Fellinger', - 'm.fellinger@gmail.com' => 'Michael Fellinger', - 'outtenr@gmail.com' => 'Richard Outten', - 'ryan@wonko.com' => 'Ryan Grove', - 'rff.rff@gmail.com' => 'Gabriele Renzi', - 'skaar@waste.org' => 'skaar', - 'stephan@spaceboyz.net' => 'Stephan Maka', - 'samcarr@gmail.com' => 'samcarr', -} - -# * Browse and try the Examples in -# #{File.join(Gem.path, 'gems', 'ramaze-' + VERS, 'examples')} diff --git a/rake_tasks/doc.rake b/rake_tasks/doc.rake deleted file mode 100644 index 4288742a..00000000 --- a/rake_tasks/doc.rake +++ /dev/null @@ -1,18 +0,0 @@ -desc 'Generate YARD documentation' -task :ydoc => :clean do - sh('yardoc -o ydoc -r README.md') -end - -desc "generate rdoc" -task :rdoc => [:clean] do - sh "rdoc #{(RDOC_OPTS + RDOC_FILES).join(' ')}" -end - -desc "generate improved allison-rdoc" -task :allison => :clean do - opts = RDOC_OPTS - path = `allison --path`.strip - raise LoadError, "Please `gem install allison` first" if $?.exitstatus == 127 - opts << %W[--template '#{path}'] - sh "rdoc #{(RDOC_OPTS + RDOC_FILES).join(' ')}" -end diff --git a/rake_tasks/gem.rake b/rake_tasks/gem.rake deleted file mode 100644 index e252d28e..00000000 --- a/rake_tasks/gem.rake +++ /dev/null @@ -1,75 +0,0 @@ -def generate_gemspec(version) - Gem::Specification.new{|s| - s.name = "ramaze" - s.version = version - s.summary = "Ramaze is a simple and modular web framework" - s.description = s.summary - - s.author = "Michael 'manveru' Fellinger" - s.email = "m.fellinger@gmail.com" - s.homepage = "http://ramaze.rubyforge.org" - s.rubyforge_project = "ramaze" - - s.bindir = "bin" - s.require_path = "lib" - - s.executables = Dir["#{s.bindir}/*"].map{|f| File.basename(f) } - s.files = FileList.new('**/*'){|fl| - fl.exclude(/^pkg\//) - fl.exclude(/^tags$/) - }.sort - - s.platform = Gem::Platform::RUBY - s.has_rdoc = true - s.post_install_message = POST_INSTALL_MESSAGE - - s.add_dependency('rack', '>= 0.9.1') - s.add_dependency('innate', '>= 2009.02') - } -end - -def update_gemspec(spec) - gemspec = <<-OUT.strip -Gem::Specification.new do |s| - s.name = %name% - s.version = %version% - - s.summary = %summary% - s.description = %description% - s.platform = %platform% - s.has_rdoc = %has_rdoc% - s.author = %author% - s.email = %email% - s.homepage = %homepage% - s.executables = %executables% - s.bindir = %bindir% - s.require_path = %require_path% - s.post_install_message = %post_install_message% - - %dependencies% - - s.files = %files% -end - OUT - - gemspec.gsub!(/%(\w+)%/) do - case key = $1 - when 'version' - spec.version.to_s.dump - when 'dependencies' - spec.dependencies.map{|dep| - "s.add_dependency('#{dep.name}', '#{dep.version_requirements}')" - }.join("\n ") - else - spec.send($1).pretty_inspect.strip - end - end - - File.open("ramaze.gemspec", 'w+'){|file| file.puts(gemspec) } -end - -spec = generate_gemspec(version_today) -Rake::GemPackageTask.new(spec) do |pkg| - pkg.need_zip = true - pkg.need_tar = true -end diff --git a/rake_tasks/maintenance.rake b/rake_tasks/maintenance.rake deleted file mode 100644 index c46c26e4..00000000 --- a/rake_tasks/maintenance.rake +++ /dev/null @@ -1,386 +0,0 @@ -def version_today - Date.today.strftime("%Y.%m.%d") -end - -def version_month - Date.today.strftime("%Y.%m") -end - -namespace :maintenance do - desc "add copyright to all .rb files in the distribution" - task 'add-copyright' do - ignore = File.readlines('doc/LEGAL'). - select{|line| line.strip!; File.exist?(line)}. - map{|file| File.expand_path(file)} - - puts "adding copyright to files that don't have it currently" - puts COPYRIGHT - puts - - Dir['{lib,test}/**/*{.rb}'].each do |file| - file = File.expand_path(file) - next if ignore.include? file - lines = File.readlines(file).map{|l| l.chomp} - unless lines.first(COPYRIGHT.size) == COPYRIGHT - puts "#{file} seems to need attention, first 4 lines:" - puts lines[0..3] - puts - end - end - end - - desc "#{README} to doc/README.html" - Rake::RDocTask.new('readme2html-build') do |rd| - rd.options = %w[ - --quiet - --opname readme.html - ] - - rd.rdoc_dir = 'readme' - rd.rdoc_files = [README] - rd.main = README - rd.title = "Ramaze documentation" - end - - desc "generate doc/TODO from the TODO tags in the source" - task 'todolist' do - list = `rake todo` - tasks = {} - current = nil - - list.split("\n")[2..-1].each do |line| - if line =~ /TODO/ or line.empty? - elsif line =~ /^vim/ - current = line.split[1] - tasks[current] = [] - else - tasks[current] << line - end - end - - lines = tasks.map{ |name, items| [name, items, ''] }.flatten - lines.pop - - File.open(File.join('doc', 'TODO'), 'w+') do |f| - f.puts "This list is programmaticly generated by `rake todolist`" - f.puts "If you want to add/remove items from the list, change them at the" - f.puts "position specified in the list." - f.puts - f.puts(lines) - end - end - - desc "remove those annoying spaces at the end of lines" - task 'fix-end-spaces' do - Dir['{lib,spec}/**/*.rb'].each do |file| - lines = File.readlines(file) - new = lines.dup - lines.each_with_index do |line, i| - if line =~ /\s+\n/ - puts "fixing #{file}:#{i + 1}" - p line - new[i] = line.rstrip - end - end - - unless new == lines - File.open(file, 'w+') do |f| - new.each do |line| - f.puts(line) - end - end - end - end - end - - desc "Rebuild doc/tutorial/todolist.html" - task 'tutorial' do - require 'maruku' - require 'hpricot' - - syntax_dir = File.dirname(Gem::latest_load_paths.grep(/syntax-/).first) - ruby_css = File.join(syntax_dir, 'data/ruby.css') - basefile = 'doc/tutorial/todolist' - - content = File.read(basefile + '.mkd') - html = Maruku.new(content).to_html_document - - doc = Hpricot(html) - css = %() - doc.at('title').after(css) - - File.open(basefile + '.html', 'w+'){|io| io << doc.to_s } - end - - # This task is so full of hacks, it may break any second, but it just feels - # good to have proper highlighting for sh, ezamar and ruby generated from - # markdown without any external CSS to worry about. - desc 'Rebuild doc/tutorial/todolist.html using UltraViolet' - task 'tutorial-uv' do - require 'maruku' - require 'uv' - require 'hpricot' - require 'ramaze/contrib/maruku_uv' - - # Inject ezamar syntax - Uv.init_syntaxes - ezamar = 'lib/ramaze/template/ezamar/textpow.syntax' - syntaxes = Uv.instance_variable_get('@syntaxes') - syntaxes['ezamar'] = Textpow::SyntaxNode.load(ezamar) - - base = 'doc/tutorial/todolist' - original = File.read(base + '.mkd') - maruku = Maruku.new(original) - style = maruku.attributes[:uv_style] - - html = maruku.to_html_document - - uv_lib = Gem::latest_load_paths.grep(/ultraviolet/).first - uv_root = File.dirname(uv_lib) - css = Dir["#{uv_root}/**/#{style}.css"].first - - doc = Hpricot(html) - css = %() - - doc.at('title').after(css) - - File.open(base + '.html', 'w+'){|io| io << doc.to_s } - end - - def existing_authors - authors = {} - - File.readlines('doc/AUTHORS').each do |line| - if line =~ /\s+(.*?)\s*:\s*(.*@.*)/ - authors[$1] = {:email => $2, :patches => 0} - end - end - - authors - end - - def authors - format = "%an ** %ae" - log = `git-log --pretty=format:'#{format}'` - - mapping = existing_authors - - log.split("\n").each do |line| - name, email = line.split(' ** ') - - if name =~ /(\S+@\S+)/ - email ||= $1 - name.sub!(email, '').strip! - end - - email_start = /^#{Regexp.escape(name)}@(.*)/ - AUTHOR_MAP.each do |e, a| - if e =~ email_start - email, name = e, a - break - end - end - - name = AUTHOR_MAP[name] || name - email = AUTHOR_MAP.index(name) || email - - mapping[name] ||= {:email => email, :patches => 0} - mapping[name][:patches] += 1 - end - - max = mapping.map{|k,v| k.size }.max - mapping.inject({}) {|h,(k,v)| h[k.ljust(max)] = v; h} - end - - desc "Update /doc/AUTHORS" - task 'authors' do - # get the authors before we overwrite the file - authors = authors().sort_by{|k,v| k} - - File.open('doc/AUTHORS', 'w+') do |fp| - fp.puts "Following persons (in alphabetical order) have contributed to Ramaze:" - fp.puts - authors.each do |name, author| - fp.puts " #{name} : #{author[:email]}" - end - fp.puts - end - end - - desc "show how many patches we made so far" - task :patchsize do - patches = `git rev-list HEAD | wc -l`.to_i - puts "currently we have #{patches} patches" - init = Time.parse("Sat Oct 14 04:22:49 JST 2006") - days = (Time.now - init) / (3600 * 24) - puts "%d days since init, avg %4.2f patches per day" % [days, patches/days] - end - - desc "show who made how many patches" - task :patchstat do - total = 0.0 - - authors.map do |name, hash| - patches = hash[:patches] - total += patches - [patches, name] - end.sort.reverse_each do |patches, name| - puts "%s %4d [%6.2f%% ]" % [name, patches, patches/total * 100] - end - end - - desc "upload packages to rubyforge" - task 'release' => ['distribute'] do - sh 'rubyforge login' - sh "rubyforge add_release ramaze ramaze #{VERS} pkg/ramaze-#{VERS}.gem" - - require 'open-uri' - require 'hpricot' - - url = "http://rubyforge.org/frs/?group_id=3034" - doc = Hpricot(open(url)) - a = (doc/:a).find{|a| a[:href] =~ /release_id/} - - version = a.inner_html - release_id = Hash[*a[:href].split('?').last.split('=').flatten]['release_id'] - - sh "rubyforge add_file ramaze ramaze #{release_id} pkg/ramaze-#{VERS}.tar.gz" - sh "rubyforge add_file ramaze ramaze #{release_id} pkg/ramaze-#{VERS}.tar.bz2" - end - - task 'undocumented-module' do - require 'strscan' - require 'term/ansicolor' - - $stdout.sync = true - - class String - include Term::ANSIColor - end - - class SimpleDoc - def initialize(string) - @s = StringScanner.new(string) - end - - def scan - comment = false - total, missing = [], [] - until @s.eos? - unless @s.scan(/^\s*#.*/) - comment = true if @s.scan(/^=begin[^$]*$/) - comment = false if comment and @s.scan(/^=end$/) - - unless comment - if @s.scan(/(?:class ).*/) - #p @s.matched - elsif @s.scan(/(?:module ).*/) - #p @s.matched - elsif @s.scan(/(?:[\s$]def\s+)[\w?!*=+\/-]+(?=[\(\s])/) - total << @s.matched.split.last - prev = @s.pre_match.split("\n") - prev.delete_if{|s| s.strip.empty?} - unless prev.last =~ /^\s*#.*/ - missing << @s.matched.split.last - end - else - @s.scan(/./m) - end - end - end - end - - return total, missing - end - end - - all = {} - files = Dir['lib/**/*.rb'] - ignore = [ - %r'contrib/gettext/(mo|po)\.rb', - %r'snippets/dictionary\.rb', - %r'lib/vendor', - ] - - print "scanning ~#{files.size} files " - files.each do |file| - next if ignore.any?{|i| file =~ i} - print "." - t, m = SimpleDoc.new(File.read(file)).scan - all[file] = [t, m] - end - puts " done." - - failed = all.reject{|k,(t,m)| m.size == 0} - - max = failed.keys.sort_by{|f| f.size}.last.size - - colors = { - (0..25 ) => :blue, - (25..50 ) => :green, - (50..75 ) => :yellow, - (75..100) => :red, - } - - puts "\nAll undocumented methods\n\n" - - failed.sort.each do |file, (t, m)| - ts, ms = t.size, m.size - tss, mss = ts.to_s, ms.to_s - ratio = ((ms.to_f/ts)*100).to_i - color = colors.find{|k,v| k.include?(ratio)}.last - complete = ms.to_f/ts.to_f - mthc = "method" - if ms > 0 - puts "#{file.ljust(max)}\t[#{[mss, tss].join('/').center(8)}]".send(color) - mthc = "methods" if ts > 1 - if $VERBOSE - puts "Of #{tss} #{mthc}, #{mss} still needs documenting (#{100 - ratio}% documented, #{ratio}% undocumented)".send(color) - mthc = "method" - mthc = "methods" if ms > 1 - print "#{mthc.capitalize}: " - end - puts m.join(', ') - puts "vim #{file} '+/def #{m.first}'" - puts - end - end - - puts "The colors mean percentages of documentation left (ratio of undocumented methods to total):" - colors.sort_by{|k,v| k.begin}.each do |r, color| - print "[#{r.inspect}] ".send(color) - end - puts "", "" - - documented = 0 - undocumented = 0 - - all.values.each do |(d,m)| - documented += d.size - undocumented += m.size - end - - total = documented + undocumented - ratio = (documented * 100.0) / total - - puts "Total documented: #{documented}, undocumented: #{undocumented}" - puts "%.2f%% of Ramaze is documented!" % ratio - end - - desc "list all undocumented methods" - task 'undocumented' do - $VERBOSE = false - Rake::Task['maintenance:undocumented-module'].invoke - end - - desc "list all undocumented methods verbosely" - task 'undocumented-verbose' do - $VERBOSE = true - Rake::Task['maintenance:undocumented-module'].invoke - end -end diff --git a/rake_tasks/release.rake b/rake_tasks/release.rake deleted file mode 100644 index 2f82636f..00000000 --- a/rake_tasks/release.rake +++ /dev/null @@ -1,76 +0,0 @@ -def latest_release_id - require 'open-uri' - require 'hpricot' - - url = "http://rubyforge.org/frs/?group_id=3034" - doc = Hpricot(open(url)) - a = (doc/:a).find{|a| a[:href] =~ /release_id/} - - version = a.inner_html - release_id = Hash[*a[:href].split('?').last.split('=').flatten]['release_id'] -end - -def update_version_rb(version) - File.open('lib/ramaze/version.rb', 'w+') do |v| - v.puts COPYRIGHT - v.puts - v.puts "module Ramaze" - v.puts " VERSION = #{version.to_s.dump}" - v.puts "end" - end -end - -def prepare_package(version) - update_version_rb(version) - spec = generate_gemspec(version) - - Rake::GemPackageTask.new(spec) do |pkg| - pkg.need_tar = true - pkg.need_zip = true - end - - Rake::Task['package'].invoke -end - -namespace :release do - desc 'Nightly release to gems.ramaze.net' - task 'nightly' do - prepare_package(version_today) - - location = 'web/gems/' - - sh "scp pkg/*.{gem,tgz,zip} ramaze@ramaze.net:#{location}" - sh "ssh ramaze@ramaze.net ' -source ~/.zsh/export.sh -cd #{location} -gem generate_index'" - end - - desc 'Monthly release to rubyforge' - task 'monthly' do - prepare_package(v = version_month) - - sh "rubyforge login" - sh "rubyforge add_release ramaze ramaze #{v} pkg/ramaze-#{v}.gem" - - release_id = latest_release_id - - files = Dir['pkg/*'].reject{|f| File.directory?(f) or f =~ /\.gem$/ } - files.each do |file| - sh "rubyforge add_file ramaze ramaze #{release_id} '#{file}'" - end - end - - desc 'Prepare and push gemspec to github' - task 'gemspec' => 'gemspec-prepare' do - sh "git commit -m 'Update ramaze.gemspec' ramaze.gemspec" - sh 'git fetch' - sh 'git rebase origin/master' - sh 'git push' - end - - desc 'Prepare gemspec for push to github' - task 'gemspec-prepare' do - update_gemspec(generate_gemspec(version_month)) - end -end diff --git a/tasks/authors.rake b/tasks/authors.rake new file mode 100644 index 00000000..1f19d321 --- /dev/null +++ b/tasks/authors.rake @@ -0,0 +1,30 @@ +# Once git has a fix for the glibc in handling .mailmap and another fix for +# allowing empty mail address to be mapped in .mailmap we won't have to handle +# them manually. + +desc 'Update doc/AUTHORS' +task :authors do + authors = Hash.new(0) + + `git shortlog -nse`.scan(/(\d+)\s(.+)\s<(.*)>$/) do |count, name, email| + case name + when "ahoward" + name, email = "Ara T. Howard", "ara.t.howard@gmail.com" + when "Martin Hilbig blueonyx@dev-area.net" + name, email = "Martin Hilbig", "blueonyx@dev-area.net" + when "Michael Fellinger m.fellinger@gmail.com" + name, email = "Michael Fellinger", "m.fellinger@gmail.com" + end + + authors[[name, email]] += count.to_i + end + + File.open('doc/AUTHORS', 'w+') do |io| + io.puts "Following persons have contributed to #{GEMSPEC.name}." + io.puts '(Sorted by number of submitted patches, then alphabetically)' + io.puts '' + authors.sort_by{|(n,e),c| [-c, n.downcase] }.each do |(name, email), count| + io.puts("%6d %s <%s>" % [count, name, email]) + end + end +end diff --git a/rake_tasks/spec.rake b/tasks/bacon.rake similarity index 63% rename from rake_tasks/spec.rake rename to tasks/bacon.rake index e4e6bc39..120633f0 100644 --- a/rake_tasks/spec.rake +++ b/tasks/bacon.rake @@ -1,40 +1,32 @@ -# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com -# All files in this distribution are subject to the terms of the Ruby license. - -require 'rake' - -desc 'run specs' -task 'spec' do +desc 'Run all bacon specs with pretty output' +task :bacon => :install_dependencies do require 'open3' require 'scanf' - specs = Dir['spec/{examples,ramaze,snippets}/**/*.rb'] + specs = PROJECT_SPECS some_failed = false total = specs.size len = specs.map{|s| s.size }.sort.last tt = ta = tf = te = 0 + red, yellow, green = "\e[31m%s\e[0m", "\e[33m%s\e[0m", "\e[32m%s\e[0m" left_format = "%4d/%d: %-#{len + 11}s" - red, green = "\e[31m%s\e[0m", "\e[32m%s\e[0m" spec_format = "%d specifications (%d requirements), %d failures, %d errors" specs.each_with_index do |spec, idx| print(left_format % [idx + 1, total, spec]) - Open3.popen3("#{RUBY} #{begin;::Gem;true;rescue;false;end ? "-rubygems" : '' } #{spec}") do |sin, sout, serr| + Open3.popen3(RUBY, spec) do |sin, sout, serr| out = sout.read err = serr.read - if out.empty? - puts(red % "ERROR getting a result") - puts err - next - end + ran = false out.each_line do |line| tests, assertions, failures, errors = all = line.scanf(spec_format) next unless all.any? + ran = true tt += tests; ta += assertions; tf += failures; te += errors if tests == 0 || failures + errors > 0 @@ -47,6 +39,8 @@ task 'spec' do break end + + puts(yellow % " skipped") unless ran end end diff --git a/tasks/changelog.rake b/tasks/changelog.rake new file mode 100644 index 00000000..3cc15b04 --- /dev/null +++ b/tasks/changelog.rake @@ -0,0 +1,18 @@ +desc 'update changelog' +task :changelog do + File.open('CHANGELOG', 'w+') do |changelog| + `git log -z --abbrev-commit`.split("\0").each do |commit| + next if commit =~ /^Merge: \d*/ + ref, author, time, _, title, _, message = commit.split("\n", 7) + ref = ref[/commit ([0-9a-f]+)/, 1] + author = author[/Author: (.*)/, 1].strip + time = Time.parse(time[/Date: (.*)/, 1]).utc + title.strip! + + changelog.puts "[#{ref} | #{time}] #{author}" + changelog.puts '', " * #{title}" + changelog.puts '', message.rstrip if message + changelog.puts + end + end +end diff --git a/tasks/copyright.rake b/tasks/copyright.rake new file mode 100644 index 00000000..fa05192e --- /dev/null +++ b/tasks/copyright.rake @@ -0,0 +1,21 @@ +desc "add copyright to all .rb files in the distribution" +task :copyright do + ignore = File.readlines('doc/LEGAL'). + select{|line| line.strip!; File.exist?(line)}. + map{|file| File.expand_path(file)} + + puts "adding copyright to files that don't have it currently" + puts PROJECT_COPYRIGHT + puts + + Dir['{lib,test}/**/*{.rb}'].each do |file| + file = File.expand_path(file) + next if ignore.include? file + lines = File.readlines(file).map{|l| l.chomp} + unless lines.first(PROJECT_COPYRIGHT.size) == PROJECT_COPYRIGHT + puts "#{file} seems to need attention, first 4 lines:" + puts lines[0..3] + puts + end + end +end diff --git a/tasks/gem.rake b/tasks/gem.rake new file mode 100644 index 00000000..4e3152b0 --- /dev/null +++ b/tasks/gem.rake @@ -0,0 +1,22 @@ +require 'rake/gempackagetask' + +task :gemspec => [:manifest, :changelog] do + gemspec_file = "#{GEMSPEC.name}.gemspec" + File.open(gemspec_file, 'w+'){|gs| gs.puts(GEMSPEC.to_ruby) } +end + +desc "package and install from gemspec" +task :install => [:gemspec] do + sh "gem build #{GEMSPEC.name}.gemspec" + sh "gem install #{GEMSPEC.name}-#{GEMSPEC.version}.gem" +end + +desc "uninstall the gem" +task :uninstall => [:clean] do + sh %{gem uninstall -x #{GEMSPEC.name}} +end + +Rake::GemPackageTask.new(GEMSPEC) do |p| + p.need_tar = true + p.need_zip = true +end diff --git a/tasks/gem_installer.rake b/tasks/gem_installer.rake new file mode 100644 index 00000000..dab250b1 --- /dev/null +++ b/tasks/gem_installer.rake @@ -0,0 +1,76 @@ +task :gem_installer do + class GemInstaller + def initialize(options = {}, &block) + @gems = [] + @options = options + + run(&block) + end + + def run(&block) + instance_eval(&block) if block_given? + end + + def gem(name, version = nil, options = {}) + if version.respond_to?(:merge!) + options = version + else + options[:version] = version + end + + @gems << [name, options] + end + + def setup_gemspec(gemspec) + gemspec.dependencies.each do |dependency| + dependency.version_requirements.as_list.each do |version| + gem(dependency.name, version) + end + end + + setup + end + + def setup + require 'rubygems' + require 'rubygems/dependency_installer' + + @gems.each do |name, options| + setup_gem(name, options) + end + end + + def setup_gem(name, options, try_install = true) + print "activating #{name} ... " + Gem.activate(name, *[options[:version]].compact) + require(options[:lib] || name) + puts "success." + rescue LoadError => error + puts error + install_gem(name, options) if try_install + setup_gem(name, options, try_install = false) + end + + def install_gem(name, options) + installer = Gem::DependencyInstaller.new(options) + + temp_argv(options[:extconf]) do + print "Installing #{name} ... " + installer.install(name, options[:version]) + puts "done." + end + end + + def temp_argv(extconf) + if extconf ||= @options[:extconf] + old_argv = ARGV.clone + ARGV.replace(extconf.split(' ')) + end + + yield + + ensure + ARGV.replace(old_argv) if extconf + end + end +end diff --git a/rake_tasks/git.rake b/tasks/git.rake similarity index 67% rename from rake_tasks/git.rake rename to tasks/git.rake index 891bb3f9..d6b5c741 100644 --- a/rake_tasks/git.rake +++ b/tasks/git.rake @@ -1,7 +1,3 @@ -def git_branch - `git branch`[/^\*\s+(.*)/, 1] -end - namespace :git do task :anon do sh 'git config remote.origin.url git://github.com/manveru/ramaze' @@ -18,7 +14,7 @@ namespace :git do puts "Putting your changes on stash" sh 'git stash' - branch = git_branch + branch = `git branch`[/^\*\s+(.*)/, 1] puts "Current branch is #{branch}" if switch = branch != 'master' @@ -38,4 +34,13 @@ namespace :git do task :send do sh 'git format-patch ^HEAD' end + + desc "show some stats about patches" + task :patchflow do + patches = `git rev-list HEAD | wc -l`.to_i + puts "currently we have #{patches} patches" + init = Time.parse("Sat Oct 14 04:22:49 JST 2006") + days = (Time.now - init) / (3600 * 24) + puts "%d days since init, avg %4.2f patches per day" % [days, patches/days] + end end diff --git a/tasks/grancher.rake b/tasks/grancher.rake new file mode 100644 index 00000000..f3140374 --- /dev/null +++ b/tasks/grancher.rake @@ -0,0 +1,12 @@ +begin + require 'grancher/task' + + Grancher::Task.new do |g| + g.branch = 'gh-pages' + g.push_to = 'origin' + g.message = 'Updated website' + g.directory 'ydoc', 'doc' + end +rescue LoadError + # oh well :) +end diff --git a/tasks/install_dependencies.rake b/tasks/install_dependencies.rake new file mode 100644 index 00000000..6db63297 --- /dev/null +++ b/tasks/install_dependencies.rake @@ -0,0 +1,6 @@ +desc 'install dependencies' +task :install_dependencies => [:gem_installer] do + GemInstaller.new do + setup_gemspec(GEMSPEC) + end +end diff --git a/tasks/jquery.rake b/tasks/jquery.rake new file mode 100644 index 00000000..b9c4deff --- /dev/null +++ b/tasks/jquery.rake @@ -0,0 +1,15 @@ +desc 'download latest jquery and put in /lib/proto/public/js/jquery.js' +task :jquery do + require 'open-uri' + $stdout.sync = true + + File.open(PROJECT_JQUERY_FILE, 'w+') do |jquery| + remote = open('http://code.jquery.com/jquery-latest.js') + print "openend remote side, copying..." + while chunk = remote.read(4096) + print '.' + jquery.write(chunk) + end + puts " done." + end +end diff --git a/tasks/manifest.rake b/tasks/manifest.rake new file mode 100644 index 00000000..657b0531 --- /dev/null +++ b/tasks/manifest.rake @@ -0,0 +1,4 @@ +desc 'update manifest' +task :manifest do + File.open('MANIFEST', 'w+'){|io| io.puts(*GEMSPEC.files) } +end diff --git a/rake_tasks/metric.rake b/tasks/metric_changes.rake similarity index 68% rename from rake_tasks/metric.rake rename to tasks/metric_changes.rake index bb9a662c..4ca3399f 100644 --- a/rake_tasks/metric.rake +++ b/tasks/metric_changes.rake @@ -1,21 +1,21 @@ namespace :metric do - desc 'changes per file according to git' - task :churn do + desc 'committed changes per file according to git' + task 'changes' do $stdout.sync = true out = lambda{|changes, rb| puts("%4d %s" % [changes, rb]) } - churn = {} + changes = {} - print 'churning ' + print 'counting changes ' Dir['lib/**/*.rb'].each do |rb| changes = `git-log --pretty=oneline '#{rb}'`.count("\n") print '.' # out[changes, rb] - churn[rb] = changes + changes[rb] = changes end puts ' done.' - sorted = churn.sort_by{|r,c| c }.reverse + sorted = changes.sort_by{|r,c| c }.reverse puts "Top 20:" sorted.first(20).each{|(r,c)| out[c,r] } puts "Bottom 20:" diff --git a/rake_tasks/coverage.rake b/tasks/rcov.rake similarity index 71% rename from rake_tasks/coverage.rake rename to tasks/rcov.rake index c104d3b5..1f05478f 100644 --- a/rake_tasks/coverage.rake +++ b/tasks/rcov.rake @@ -1,9 +1,7 @@ desc 'code coverage' task :rcov => :clean do - specs = Dir['spec/{ramaze,snippets}/**/*.rb'] - specs -= Dir['spec/ramaze/cache/common.rb'] + specs = PROJECT_SPECS - # we ignore adapter as this has extensive specs in rack already. ignore = %w[ gem rack bacon innate hpricot nagoro/lib/nagoro ] if RUBY_VERSION >= '1.8.7' @@ -14,11 +12,12 @@ task :rcov => :clean do end ignored = ignore.join(',') + cmd = "rcov --aggregate coverage.data --sort coverage -t --%s -x '#{ignored}' %s" while spec = specs.shift puts '', "Gather coverage for #{spec} ..." html = specs.empty? ? 'html' : 'no-html' - sh(cmd % [html, spec]){|*a| } + sh(cmd % [html, spec]) end end diff --git a/tasks/release.rake b/tasks/release.rake new file mode 100644 index 00000000..546fecb9 --- /dev/null +++ b/tasks/release.rake @@ -0,0 +1,69 @@ +namespace :release do + task :all => [:release_github, :release_rubyforge] + + desc 'Display instructions to release on github' + task :github => [:reversion, :gemspec] do + name, version = GEMSPEC.name, GEMSPEC.version + + puts < [:reversion, :gemspec, :package] do + name, version = GEMSPEC.name, GEMSPEC.version + + puts < :clean do + sh("yardoc -o ydoc -r #{PROJECT_README}") +end