From ee808b400543d924286eebaee8ed1ad8a4e28ced Mon Sep 17 00:00:00 2001 From: murphy Date: Sun, 16 Apr 2006 00:38:38 +0000 Subject: Rake tasks completely redone. rdoctask2.rb deleted; issues were fixed as of Rake 0.7.0. --- Rakefile | 270 +----------------------------------------- rake_helpers/ftp.rb | 45 +++++++ rake_helpers/rdoctask2.rb | 125 ------------------- rake_tasks/benchmark.rake | 6 + rake_tasks/documentation.rake | 44 +++++++ rake_tasks/example.rake | 25 ++++ rake_tasks/gem.rake | 103 ++++++++++++++++ rake_tasks/rubyforge.rake | 19 +++ rake_tasks/statistic.rake | 14 +++ rake_tasks/test.rake | 19 +++ 10 files changed, 280 insertions(+), 390 deletions(-) create mode 100644 rake_helpers/ftp.rb delete mode 100644 rake_helpers/rdoctask2.rb create mode 100644 rake_tasks/benchmark.rake create mode 100644 rake_tasks/documentation.rake create mode 100644 rake_tasks/example.rake create mode 100644 rake_tasks/gem.rake create mode 100644 rake_tasks/rubyforge.rake create mode 100644 rake_tasks/statistic.rake create mode 100644 rake_tasks/test.rake diff --git a/Rakefile b/Rakefile index 8799307..753508e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,18 +1,7 @@ -# excuse me, this is my first Rakefile :( [m] -require 'rake' -require 'rake_helpers/rdoctask2' -require 'rake/gempackagetask.rb' +require 'rake_helpers/ftp.rb' ROOT = '.' -LIB_ROOT = File.join(ROOT, 'lib') - -task :default => :make - -#task :doc => [:deldoc, :make_doc] -#task :minidoc => [:deldoc, :make_minidoc] -#task :deldoc do -# rm_r 'doc' if File.directory? 'doc' -#end +LIB_ROOT = File.join ROOT, 'lib' EXTRA_FILES = %w(README FOLDERS) def EXTRA_FILES.in folder @@ -21,257 +10,8 @@ def EXTRA_FILES.in folder end end -def set_rdoc_info rd, small = false -# rd.rdoc_dir = 'doc' - rd.main = File.join(ROOT, 'README') - rd.title = "CodeRay Documentation" - rd.options << '--line-numbers' << '--inline-source' << '--tab-width' << '2' - rd.options << '--fmt' << 'html_coderay' - rd.options << '--all' - rd.template = 'rake_helpers/coderay_rdoc_template.rb' - rd.rdoc_files.add *EXTRA_FILES.in(ROOT) - rd.rdoc_files.add *Dir[File.join(LIB_ROOT, "#{'**/' unless small}*.rb")] -end - -desc 'Generate documentation for CodeRay' -Rake::RDocTask.new :rdoc do |rd| - set_rdoc_info rd -end - -desc 'Generate test documentation for CodeRay' -Rake::RDocTask.new :rdoc_small do |rd| - set_rdoc_info rd, true -end - -desc 'Report code statistics (LOC) from the application' -task :stats => :copy_files do - require 'rake_helpers/code_statistics' - CodeStatistics.new( - ['Main', 'lib'], - ['CodeRay', 'lib/coderay/'], - [' Scanners', 'lib/coderay/scanners'], - [' Encoders', 'lib/coderay/encoders'], - [' Helpers', 'lib/coderay/helpers'], - ['Test', 'test/**', /\/\w+.rb$/], - ['Demo Tests', 'demo/**'] - ).print -end - -desc 'Test CodeRay Demos' -task :test_demos do - system 'ruby -wd ./demo/suite.rb' -end - -desc 'Test CodeRay' -task :test do - system 'ruby -wd ./test/suite.rb' -end - -desc 'Test CodeRay Demos with Fox' -task :testf_demos do - system 'ruby -w ./demo/suite.rb -f' -end - -desc 'Test CodeRay with Fox' -task :testf do - system 'ruby -w ./test/suite.rb -f' -end - -desc 'Test CodeRay with debugging' -task :debug do - system 'ruby -w -d ./test/suite.rb' -end - -desc 'Do a benchmark' -task :bench do - system 'ruby -wIlib bench\bench.rb ruby html 0' -end - -def gemspec - Gem::Specification.new do |s| - # Basic Information - s.name = s.rubyforge_project = 'coderay' - s.version = '0' - - s.platform = Gem::Platform::RUBY - s.requirements = ['strscan'] - s.date = Time.now.strftime '%Y-%m-%d' - s.has_rdoc = true - s.rdoc_options = '-SNw2', '-mREADME', '-a', '-t CodeRay Documentation' - s.extra_rdoc_files = EXTRA_FILES.in('./') - - # Description - s.summary = <<-EOF - CodeRay is a fast syntax highlighter engine for many languages. - EOF - s.description = <<-EOF - CodeRay is a Ruby library for syntax highlighting. - I try to make CodeRay easy to use and intuitive, but at the same time - fully featured, complete, fast and efficient. - - Usage is simple: - require 'coderay' - code = 'some %q(weird (Ruby) can\'t shock) me!' - puts CodeRay.scan(code, :ruby).html - EOF - - # Files - s.require_path = 'lib' - s.autorequire = 'coderay' - - s.files = nil # defined later - - # Credits - s.author = 'murphy' - s.email = 'murphy@cYcnus.de' - s.homepage = 'http://rd.cycnus.de/coderay' - end -end - -gemtask = Rake::GemPackageTask.new(gemspec) do |pkg| - pkg.need_zip = true - pkg.need_tar = true -end - -$: << './lib' -require 'coderay' -$version = CodeRay::Version - -desc 'Create the gem again' -task :make => [:build, :make_gem] - -BUILD_FILE = 'build' -task :build do - $version.sub!(/\.(\d+)\./) { minor = $1; ".#{minor.to_i - 1}." } - $version << '.' << (`svn info`[/Revision: (\d+)/,1]) -end - -task :make_gem => [:copy_files, :make_gemspec, :gem, :copy_gem] - -desc 'Copy the gem files' -task :copy_files do - rm_r 'pkg' if File.exist? 'pkg' -end - -task :make_gemspec do - candidates = Dir['./lib/**/*.rb'] + - Dir['./demo/*.rb'] + -# Dir['./bin/*'] + -# Dir['./demo/bench/*'] + -# Dir['./test/*'] + - %w( ./README ./LICENSE) - s = gemtask.gem_spec - s.files = candidates #.delete_if { |item| item[/(?:CVS|rdoc)|~$/] } - gemtask.version = s.version = $version -end - -GEMDIR = 'gem_server/gems' -task :copy_gem => :build do - $gemfile = "coderay-#$version.gem" - Dir[GEMDIR + '/*.gem'].each { |g| rm g } - cp "pkg/#$gemfile", GEMDIR - system 'ruby -S generate_yaml_index.rb -d gem_server' -end - -def g msg - $stderr.print msg -end -def gn msg = '' - $stderr.puts msg -end -def gd - gn 'done.' -end - -require 'net/ftp' -require 'yaml' -FTP_YAML = 'ftp.yaml' -$username = File.exist?(FTP_YAML) ? YAML.load_file(FTP_YAML)[:username] : 'anonymous' - -FTP_DOMAIN = 'cycnus.de' -FTP_CODERAY_DIR = 'public_html/raindark/coderay' - -def cYcnus_ftp - Net::FTP.open(FTP_DOMAIN) do |ftp| - g 'ftp login, password needed: ' - ftp.login $username, $stdin.gets - gn 'logged in.' - yield ftp - end -end - -def uploader_for ftp - proc do |l, *r| - r = r.first || l - raise 'File %s not found!' % l unless File.exist? l - if l == r - g 'Uploading %s...' % [l] - else - g 'Uploading %s to %s...' % [l, r] - end - ftp.putbinaryfile l, r - gd - end -end - -desc 'Upload gemfile to ' + FTP_DOMAIN -task :up_gem => [:make, :copy_gem] do - gn 'Uploading gem:' - Dir.chdir 'gem_server' do - cYcnus_ftp do |ftp| - uploader = uploader_for ftp - ftp.chdir FTP_CODERAY_DIR - %w(yaml yaml.Z).each &uploader - Dir.chdir 'gems' do - ftp.chdir 'gems' - uploader.call $gemfile - end - end - end - gn 'Gem successfully uploaded.' -end - -desc 'Upload example to ' + FTP_DOMAIN -task :up_example do - gn 'Highlighting self...' - system 'ruby -wIlib ../hidden/highlight.rb -1 -L -I lib lib/coderay/**/' - gd - gn 'Uploading example:' - cYcnus_ftp do |ftp| - ftp.chdir FTP_CODERAY_DIR - uploader = proc do |l, r| - g 'Uploading %s to %s...' % [l, r] - ftp.putbinaryfile l, r - gd - end - uploader.call 'highlighted/all_in_one.html', 'example.html' - end - gn 'Example uploaded.' -end - -desc 'Upload rdoc to ' + FTP_DOMAIN -task :up_doc => :rdoc do - gn 'Uploading documentation:' - Dir.chdir 'rdoc' do - cYcnus_ftp do |ftp| - uploader = uploader_for ftp - ftp.chdir FTP_CODERAY_DIR - ftp.chdir 'doc' - Dir['**/*.*'].each &uploader - end - end - gn 'Documentation uploaded.' +for task_file in Dir['rake_tasks/*.rake'] + load task_file end -RUBYFORGE_TRUNK_DIR = 'L:/rubyforge/trunk/coderay/trunk' -desc 'Export trunk to Rubyforge working copy via SVN' -task :export do - system 'svn st' - puts 'Exporting changelog.' - system 'svn log > ../changelog.txt' - system "svn export #{`svn info`[/URL: (.*)/,1]}/ #{RUBYFORGE_TRUNK_DIR} --force" - cp '../changelog.txt', "#{RUBYFORGE_TRUNK_DIR}/.." - Dir.chdir RUBYFORGE_TRUNK_DIR do - system "svn st" - end -end +task :default => 'gem:make' diff --git a/rake_helpers/ftp.rb b/rake_helpers/ftp.rb new file mode 100644 index 0000000..c1eb98c --- /dev/null +++ b/rake_helpers/ftp.rb @@ -0,0 +1,45 @@ +def prepare_ftp + require 'net/ftp' + require 'yaml' + $username = File.exist?(FTP_YAML) ? YAML.load_file(FTP_YAML)[:username] : 'anonymous' +end + +FTP_YAML = 'ftp.yaml' +FTP_DOMAIN = 'cycnus.de' +FTP_CODERAY_DIR = 'public_html/raindark/coderay' + +def cYcnus_ftp + prepare_ftp + Net::FTP.open(FTP_DOMAIN) do |ftp| + g 'ftp login, password needed: ' + ftp.login $username, $stdin.gets + gn 'logged in.' + yield ftp + end +end + +def uploader_for ftp + proc do |l, *r| + r = r.first || l + raise 'File %s not found!' % l unless File.exist? l + if l == r + g 'Uploading %s...' % [l] + else + g 'Uploading %s to %s...' % [l, r] + end + ftp.putbinaryfile l, r + gd + end +end + +def g msg + $stderr.print msg +end + +def gn msg = '' + $stderr.puts msg +end + +def gd + gn 'done.' +end diff --git a/rake_helpers/rdoctask2.rb b/rake_helpers/rdoctask2.rb deleted file mode 100644 index 1e6bedd..0000000 --- a/rake_helpers/rdoctask2.rb +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env ruby - -require 'rake' -require 'rake/tasklib' -require 'rdoc/rdoc' - -module Rake - - # Create a documentation task that will generate the RDoc files for - # a project. - # - # The RDocTask will create the following targets: - # - # [rdoc] - # Main task for this RDOC task. - # - # [:clobber_rdoc] - # Delete all the rdoc files. This target is automatically - # added to the main clobber target. - # - # [:rerdoc] - # Rebuild the rdoc files from scratch, even if they are not out - # of date. - # - # Simple Example: - # - # Rake::RDocTask.new do |rd| - # rd.main = "README.rdoc" - # rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") - # end - # - # You may wish to give the task a different name, such as if you are - # generating two sets of documentation. For instance, if you want to have a - # development set of documentation including private methods: - # - # Rake::RDocTask.new(:rdoc_dev) do |rd| - # rd.main = "README.doc" - # rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") - # rd.options << "--all" - # end - # - # The tasks would then be named :rdoc_dev, :clobber_rdoc_dev, and - # :rerdoc_dev. - # - class RDocTask < TaskLib - # Name of the main, top level task. (default is :rdoc) - attr_accessor :name - - # Name of directory to receive the html output files. (default is "html") - attr_accessor :rdoc_dir - - # Title of RDoc documentation. (default is none) - attr_accessor :title - - # Name of file to be used as the main, top level file of the - # RDoc. (default is none) - attr_accessor :main - - # Name of template to be used by rdoc. (default is 'html') - attr_accessor :template - - # List of files to be included in the rdoc generation. (default is []) - attr_accessor :rdoc_files - - # List of options to be passed rdoc. (default is []) - attr_accessor :options - - # Create an RDoc task named rdoc. Default task name is +rdoc+. - def initialize(name=:rdoc) # :yield: self - @name = name - @rdoc_files = Rake::FileList.new - @rdoc_dir = name.to_s - @main = nil - @title = nil - @template = 'html' - @options = [] - yield self if block_given? - define - end - - # Create the tasks defined by this task lib. - def define - desc "Build the #{name} HTML Files" - task name - - desc "Force a rebuild of the RDOC files" - task paste("re", name) => [paste("clobber_", name), name] - - desc "Remove rdoc products" - task paste("clobber_", name) do - rm_r rdoc_dir rescue nil - end - - #task :clobber => [paste("clobber_", name)] - - directory @rdoc_dir - task name => [rdoc_target] - file rdoc_target => @rdoc_files + [$rakefile] do - rm_r @rdoc_dir rescue nil - r = RDoc::RDoc.new - r.document(['-o', @rdoc_dir] + option_list + @rdoc_files) - end - self - end - - def option_list - result = @options.dup - result << "--main" << main if main - result << "--title" << "#{title}" if title - result << "-T" << template if template - result - end - - def option_string - option_list.join(' ') - end - - private - - def rdoc_target - "#{rdoc_dir}/index.html" - end - - end -end diff --git a/rake_tasks/benchmark.rake b/rake_tasks/benchmark.rake new file mode 100644 index 0000000..3046fc7 --- /dev/null +++ b/rake_tasks/benchmark.rake @@ -0,0 +1,6 @@ +desc 'Do a benchmark' +task :benchmark do + system 'ruby -wIlib bench\bench.rb ruby html 0' +end + +task :bench => :benchmark diff --git a/rake_tasks/documentation.rake b/rake_tasks/documentation.rake new file mode 100644 index 0000000..21232b3 --- /dev/null +++ b/rake_tasks/documentation.rake @@ -0,0 +1,44 @@ +require 'rake/rdoctask' + +def set_rdoc_info rd, small = false + rd.main = 'README' + rd.title = "CodeRay Documentation" + rd.options << '--line-numbers' << '--inline-source' << '--tab-width' << '2' + rd.options << '--fmt' << ENV.fetch('format', 'html_coderay') + rd.options << '--all' + rd.template = ENV.fetch('template', 'rake_helpers/coderay_rdoc_template.rb') + rd.rdoc_files.add *EXTRA_FILES.in(ROOT) + rd.rdoc_files.add *Dir[File.join(LIB_ROOT, "#{'**/' unless small}*.rb")] +end + +namespace :doc do + + desc 'Generate documentation for CodeRay' + Rake::RDocTask.new :all do |rd| + set_rdoc_info rd + rd.rdoc_dir = 'doc/all' + end + + desc 'Generate test documentation for CodeRay (faster)' + Rake::RDocTask.new :small do |rd| + set_rdoc_info rd, true + rd.rdoc_dir = 'doc/small' + end + + desc 'Upload rdoc to ' + FTP_DOMAIN + task :upload => :all do + gn 'Uploading documentation:' + Dir.chdir 'rdoc' do + cYcnus_ftp do |ftp| + uploader = uploader_for ftp + ftp.chdir FTP_CODERAY_DIR + ftp.chdir 'doc' + Dir['**/*.*'].each &uploader + end + end + gn 'Documentation uploaded.' + end + +end + +task :doc => 'doc:all' diff --git a/rake_tasks/example.rake b/rake_tasks/example.rake new file mode 100644 index 0000000..fa7e1ec --- /dev/null +++ b/rake_tasks/example.rake @@ -0,0 +1,25 @@ +namespace :example do + + desc 'Generate an example output' + task :make do + system 'ruby -wIlib ../hidden/highlight.rb -1 -L -I lib lib/coderay/**/' + end + + desc 'Upload example to ' + FTP_DOMAIN + task :upload => :make do + gn 'Highlighting self...' + gd + gn 'Uploading example:' + cYcnus_ftp do |ftp| + ftp.chdir FTP_CODERAY_DIR + uploader = proc do |l, r| + g 'Uploading %s to %s...' % [l, r] + ftp.putbinaryfile l, r + gd + end + uploader.call 'highlighted/all_in_one.html', 'example.html' + end + gn 'Example uploaded.' + end + +end diff --git a/rake_tasks/gem.rake b/rake_tasks/gem.rake new file mode 100644 index 0000000..bf2e2e1 --- /dev/null +++ b/rake_tasks/gem.rake @@ -0,0 +1,103 @@ +require 'rake/gempackagetask.rb' + +def gemspec + Gem::Specification.new do |s| + # Basic Information + s.name = s.rubyforge_project = 'coderay' + s.version = '0' + + s.platform = Gem::Platform::RUBY + s.requirements = ['strscan'] + s.date = Time.now.strftime '%Y-%m-%d' + s.has_rdoc = true + s.rdoc_options = '-SNw2', '-mREADME', '-a', '-t CodeRay Documentation' + s.extra_rdoc_files = EXTRA_FILES.in('./') + + # Description + s.summary = <<-EOF + CodeRay is a fast syntax highlighter engine for many languages. + EOF + s.description = <<-EOF + CodeRay is a Ruby library for syntax highlighting. + I try to make CodeRay easy to use and intuitive, but at the same time + fully featured, complete, fast and efficient. + + Usage is simple: + require 'coderay' + code = 'some %q(weird (Ruby) can\'t shock) me!' + puts CodeRay.scan(code, :ruby).html + EOF + + # Files + s.require_path = 'lib' + s.autorequire = 'coderay' + + s.files = nil # defined later + + # Credits + s.author = 'murphy' + s.email = 'murphy@cYcnus.de' + s.homepage = 'http://rd.cycnus.de/coderay' + end +end + +namespace :gem do + + gemtask = Rake::GemPackageTask.new(gemspec) do |pkg| + pkg.need_zip = true + pkg.need_tar = true + end + + desc 'Create the gem again' + task :make => [:make_gemspec, :gem, :prepare_server] + + desc 'Find out the current CodeRay version' + task :get_version do + unless $version + $: << './lib' + require 'coderay' + $version = CodeRay::Version + end + puts 'Current Version: %s' % $version + $version.sub!(/\.(\d+)\./) { minor = $1; ".#{minor.to_i - 1}." } + $version << '.' << (`svn info`[/Revision: (\d+)/,1]) + end + + task :make_gemspec => :get_version do + candidates = Dir['./lib/**/*.rb'] + + Dir['./demo/*.rb'] + + # Dir['./bin/*'] + + # Dir['./demo/bench/*'] + + # Dir['./test/*'] + + %w( ./README ./LICENSE) + s = gemtask.gem_spec + s.files = candidates #.delete_if { |item| item[/(?:CVS|rdoc)|~$/] } + gemtask.version = s.version = $version + end + + GEMDIR = 'gem_server/gems' + task :prepare_server => :get_version do + $gemfile = "coderay-#$version.gem" + Dir[GEMDIR + '/*.gem'].each { |g| rm g } + cp "pkg/#$gemfile", GEMDIR + system 'ruby -S generate_yaml_index.rb -d gem_server' + end + + desc 'Upload gemfile to ' + FTP_DOMAIN + task :up_gem => :make do + gn 'Uploading gem:' + Dir.chdir 'gem_server' do + cYcnus_ftp do |ftp| + uploader = uploader_for ftp + ftp.chdir FTP_CODERAY_DIR + %w(yaml yaml.Z).each &uploader + Dir.chdir 'gems' do + ftp.chdir 'gems' + uploader.call $gemfile + end + end + end + gn 'Gem successfully uploaded.' + end + +end diff --git a/rake_tasks/rubyforge.rake b/rake_tasks/rubyforge.rake new file mode 100644 index 0000000..3a21bbf --- /dev/null +++ b/rake_tasks/rubyforge.rake @@ -0,0 +1,19 @@ +RUBYFORGE_TRUNK_DIR = 'L:/rubyforge/trunk/coderay/trunk' + +namespace :rubyforge do + + desc 'Export trunk to Rubyforge working copy via SVN' + task :export do + system 'svn st' + puts 'Exporting changelog.' + system 'svn log > ../changelog.txt' + system "svn export #{`svn info`[/URL: (.*)/,1]}/ #{RUBYFORGE_TRUNK_DIR} --force" + cp '../changelog.txt', "#{RUBYFORGE_TRUNK_DIR}/.." + Dir.chdir RUBYFORGE_TRUNK_DIR do + system "svn st" + end + end + +end + +task :export => 'rubyforge:export' diff --git a/rake_tasks/statistic.rake b/rake_tasks/statistic.rake new file mode 100644 index 0000000..6114547 --- /dev/null +++ b/rake_tasks/statistic.rake @@ -0,0 +1,14 @@ +desc 'Report code statistics (LOC) from the application' +task :stats do + require 'rake_helpers/code_statistics' + CodeStatistics.new( + ['Main', 'lib'], + ['CodeRay', 'lib/coderay/'], + [' Scanners', 'lib/coderay/scanners/**'], + [' Encoders', 'lib/coderay/encoders/**'], + [' Helpers', 'lib/coderay/helpers/**'], + [' Styles', 'lib/coderay/styles/**'], + ['Test', 'test/**', /\/\w+.rb$/], + ['Demo Tests', 'demo/**'] + ).print +end diff --git a/rake_tasks/test.rake b/rake_tasks/test.rake new file mode 100644 index 0000000..b9cc2a6 --- /dev/null +++ b/rake_tasks/test.rake @@ -0,0 +1,19 @@ +namespace :test do + desc 'Test CodeRay Demos' + task :demos do + system 'ruby -wd ./demo/suite.rb' + end + + desc 'Test CodeRay' + task :scanners do + system 'ruby -w ./test/suite.rb' + end + + desc 'Test CodeRay with debugging' + task :scanners_debug do + system 'ruby -w -d ./test/suite.rb' + end +end + +task :test => 'test:scanners' +task :debug => 'test:scanners_debug' -- cgit v1.2.1