gregwebs / methodchain

ruby helpers for method chaining: tap, then, else

This URL has Read+Write access

methodchain / Rakefile
100644 74 lines (64 sloc) 2.242 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
$project = "methodchain"
$rcov_index_html = 'coverage/lib-methodchain-not_included_rb.html'
 
require 'tasks/helpers'
 
def __DIR__; "#{File.dirname(__FILE__)}" end
 
desc "test run all tests"
task :test => [:spec, 'readme:test']
 
namespace :readme do
  desc "create html for website using coderay, use --silent option"
  task :html do
    rm_rf 'doc'
    `rdoc --quiet --style rdoc.css README`
    require 'hpricot'
    require 'htmlentities'
    doc = open( 'doc/files/README.html' ) { |f| Hpricot(f) }
    # find example code
    doc.at('#description').search('pre').each do |ex|
      #select {|elem| elem.inner_html =~ /class |module /}.each do |ex|
      # add coderay and undo what rdoc has done in the example code
      ex.swap("<coderay lang='ruby'>#{HTMLEntities.new.decode ex.inner_html}</coderay>")
    end
    puts doc.at('#description').to_html
  end
 
  # run README through xmp
  desc "run README code through xmp filter"
  task :test do
    # grab example code from README
    cd_tmp do
      example_file = "#{Dir.pwd}/example.rb"
 
      File.write(example_file, (
        File.read("#{__DIR__}/lib/methodchain/not-included.rb") <<
        "class Object; include MethodChain end\n" <<
        File.readlines('../README').grep(/^ / ).
          reject {|l| l =~ /^\s*require/ or l.include?('Error') or l.include? 'gem install'}.
            join ))
 
      command = "ruby ../bin/xmpfilter -c #{example_file}"
      Dir.chdir '/home/greg/src/head/lib' do
        run "#{command}"
      end
      puts "README code successfully evaluated"
    end
  end
end
 
require 'rubygems'
require 'rake/gempackagetask'
 
spec = Gem::Specification.new do |s|
  s.name = $project
  s.rubyforge_project = $project
  s.version = "0.4.2"
  s.author = "Greg Weber"
  s.email = "greg@gregweber.info"
  s.homepage = "http://projects.gregweber.info/#{$project}"
  s.platform = Gem::Platform::RUBY
  s.summary = "convenience methods for method chaining"
  s.files =
  FileList.new('./**', '*/**', 'lib/methodchain/*') do |fl|
    fl.exclude('pkg','pkg/*','tmp','tmp/*', 'coverage', 'coverage/*')
  end
  s.require_path = "lib"
  s.has_rdoc = true
  s.extra_rdoc_files = ["README"]
end
Rake::GemPackageTask.new(spec) do |pkg|
  pkg.need_tar = false
end