ddollar / albino forked from github/albino

Ruby wrapper for the Pygments syntax highlighter.

This URL has Read+Write access

albino / Rakefile
100644 102 lines (81 sloc) 2.546 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
require 'rubygems'
require 'erb'
require 'yaml'
require 'rake'
 
begin
  require 'hanna/rdoctask'
rescue LoadError
  require 'rake/rdoctask'
end
 
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 :rdoc do
 
  desc 'Generate RDoc'
  rd = Rake::RDocTask.new(:build) do |rdoc|
    Rake::Task['gem:config'].invoke
    rdoc.title = @config.name
    rdoc.main = 'README.rdoc'
    rdoc.rdoc_dir = 'doc'
    rdoc.options << '--line-numbers' << '--inline-source'
    rdoc.rdoc_files.include('README.rdoc', 'lib/**/*.rb')
  end
 
  desc 'View RDoc'
  task :view => [ :build ] do
    system %{open doc/index.html}
  end
 
end