ddollar / simple-parser

Simple parsing library

This URL has Read+Write access

simple-parser / Rakefile
100644 141 lines (113 sloc) 3.641 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
require 'rubygems'
require 'erb'
require 'yaml'
require 'rake'
require 'rake/rdoctask'
require 'spec/rake/spectask'
require 'spec/rake/verify_rcov'
require 'FileUtils'
require 'BlueCloth'
 
task :default => [ 'rspec:run' ]
 
namespace :gem do
 
  task :customize do
    raise 'GEM required' unless name = ENV['GEM']
    raise 'CONST required' unless const = ENV['CONST']
 
    raise 'already configured' unless File.exists?('lib/generic')
 
    lib = File.open('lib/generic.rb', 'r') { |f| f.read.gsub('Generic', const) }
    File.open('lib/generic.rb', 'w') { |f| f.puts lib }
 
    FileUtils.mv('lib/generic', "lib/#{name}")
    FileUtils.mv('lib/generic.rb', "lib/#{name}.rb")
 
    editor = ENV['EDITOR'] || 'vi'
    system "#{editor} config/gem.rb"
  end
 
  task :config do
    @config = OpenStruct.new
 
    File.open("config/gem.rb", "r") do |gem_config|
      eval(gem_config.read)
    end
 
    @config.files = FileList["{bin,doc,lib,test}/**/*"].to_a.map do |file|
      '"' + file + '"'
    end.join(',')
  end
 
  desc "Build the gem"
  task :build => [ 'gem:config', 'gem:spec:build' ] do
    spec = nil
    File.open("#{@config.name}.gemspec", 'r') do |gemspec|
      eval gemspec.read
    end
    Gem::manage_gems
    gemfile = Gem::Builder.new(spec).build
    Dir.mkdir('pkg') unless File.exists?('pkg')
    File.rename(gemfile, "pkg/#{gemfile}")
  end
 
  namespace :spec do
 
    desc "Build gemspec"
    task :build => [ :config ] do
      File.open("config/gemspec.rb.erb", "r") do |template|
        File.open("#{@config.name}.gemspec", "w") do |gemspec|
          template_data = "<% config = YAML::load(%{#{Regexp.escape(YAML::dump(@config))}}) %>\n"
          template_data += template.read
          original_stdout = $stdout
          $stdout = gemspec
          ERB.new(template_data).run
          $stdout = original_stdout
        end
      end
    end
 
    desc "Test gemspec against Github"
    task :test => [ 'gem:config', :build ] do
      require 'rubygems/specification'
      data = File.read("#{@config.name}.gemspec")
      spec = nil
      Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
      puts spec
    end
 
  end
end
 
namespace :documentation do
 
  desc 'Compile HTML documentation from Markdown'
  task :compile do
    Dir['**/*.markdown'].each do |file|
      html_file = file.gsub('.markdown', '.html')
      html = File.open(file, 'r') { |f| BlueCloth.new(f.read).to_html }
      File.open(html_file, 'w') { |f| f.puts html }
    end
  end
 
end
 
namespace :rdoc do
 
  desc 'Generate RDoc'
  rd = Rake::RDocTask.new(:build) do |rdoc|
    Rake::Task['gem:config'].invoke
    Rake::Task['documentation:compile'].invoke
    rdoc.title = @config.name
    rdoc.main = 'README.html'
    rdoc.rdoc_dir = 'output/rdoc'
    rdoc.options << '--line-numbers' << '--inline-source'
    rdoc.rdoc_files.include('README.html', 'lib/**/*.rb')
  end
 
  desc 'View RDoc'
  task :view => [ :build ] do
    system %{open output/rdoc/index.html}
  end
 
end
 
namespace :rspec do
 
  desc "Run rspec tasks"
  Spec::Rake::SpecTask.new(:run) do |t|
    t.spec_files = FileList['spec/**/*_spec.rb']
    #t.spec_opts = ['--options', 'spec/spec.opts']
    unless ENV['NO_RCOV']
      t.rcov = true
      t.rcov_dir = 'output/coverage'
      t.rcov_opts = ['--exclude', 'bin\/rtr,examples,\/var\/lib\/gems,\/Library\/Ruby,\.autotest']
    end
  end
 
  desc "Show code coverage"
  task :coverage => [ :run ] do
    system %{open output/coverage/index.html}
  end
 
  desc "Verify code coverage"
  RCov::VerifyTask.new(:verify => :run) do |t|
    t.threshold = 100.0
    t.index_html = 'output/coverage/index.html'
  end
 
end