public
Description: selectively import methods from modules
Homepage: http://projects.gregweber.info/module-import
Clone URL: git://github.com/gregwebs/module-import.git
Click here to lend your support to: module-import and make a donation at www.pledgie.com !
module-import / Rakefile
100644 96 lines (81 sloc) 2.656 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
$rubyforge_project = "'module import'"
$project = 'module-import'
$rcov_index_html = 'coverage/lib-module-import_rb.html'
 
require 'tasks/helpers'
 
def __DIR__; "#{File.dirname(__FILE__)}" end
 
desc "test run all tests"
task :test => [:spec, 'test:readme', :rcov]
 
namespace :test do
  # run README through xmp
  desc "run README code through xmp filter"
  task :readme do
    cd_tmp do
      example_file = "#{__DIR__}/example.rb"
 
      File.write(example_file, (
        File.read("#{__DIR__}/lib/module-import.rb") <<
        File.readlines('../README').grep(/^ / ).
          reject {|l| l =~ /^\s*require/ or l.include?('Error')}.
            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
 
namespace :readme do
  desc "create html for website using coderay, use --silent option"
  task :html do
    rm_rf 'doc'
    fail unless system 'rdoc --force-update --quiet README'
 
    require 'hpricot'
    require 'htmlentities'
    doc = open( 'doc/files/README.html' ) { |f| Hpricot(f) }
    # find example code
    doc.at('#description').search('pre').
    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
end
                        
 
require 'rubygems'
require 'spec/rake/spectask'
 
require 'rubygems'
require 'rake/gempackagetask'
 
spec = Gem::Specification.new do |s|
  s.name = $project
  s.rubyforge_project = $project
  s.version = "0.4.0"
  s.author = "Greg Weber"
  s.email = "greg@gregweber.info"
  s.homepage = "http://projects.gregweber.info/#{$project}"
  s.platform = Gem::Platform::RUBY
  s.summary = "selectively import methods from modules"
  s.files = FileList.new('./**', '*/**') do |fl|
             fl.exclude('pkg','pkg/*','tmp','tmp/*')
           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
 
desc "run this once to set up the project"
task :setup do
  cd_tmp do
    unless File.exist? 'index.html'
      File.write('index.html', <<-EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<meta http-equiv="REFRESH" content="0;url=http://projects.gregweber.info/#{$project}"></head>
</html>
EOF
)
    end
    run "scp index.html gregwebs@rubyforge.org:/var/www/gforge-projects/#{$project}"
  end
end