Rakefile 6.2 KB
Newer Older
S
Santiago Pastorino 已提交
1
gem 'rdoc', '>= 2.5.10'
2 3
require 'rdoc'

4
require 'rake'
A
Aaron Patterson 已提交
5
require 'rdoc/task'
6
require 'net/http'
7

8 9 10 11 12 13 14
$:.unshift File.expand_path('..', __FILE__)
require "tasks/release"

desc "Build gem files for all projects"
task :build => "all:build"

desc "Release all gems to gemcutter and create a tag"
C
Carl Lerche 已提交
15
task :release => "all:release"
16

17 18 19 20 21 22 23 24 25 26 27 28
# RDoc skips some files in the Rails tree due to its binary? predicate. This is a quick
# hack for edge docs, until we decide which is the correct way to address this issue.
# If not fixed in RDoc itself, via an option or something, we should probably move this
# to railties and use it also in doc:rails.
def hijack_rdoc!
  require "rdoc/parser"
  class << RDoc::Parser
    def binary?(file)
      s = File.read(file, 1024) or return false

      if s[0, 2] == Marshal.dump('')[0, 2] then
        true
29
      elsif file =~ /erb\.rb$/ then
30 31 32 33 34 35 36 37 38 39 40 41
        false
      elsif s.index("\x00") then # ORIGINAL is s.scan(/<%|%>/).length >= 4 || s.index("\x00")
        true
      elsif 0.respond_to? :fdiv then
        s.count("^ -~\t\r\n").fdiv(s.size) > 0.3
      else # HACK 1.8.6
        (s.count("^ -~\t\r\n").to_f / s.size) > 0.3
      end
    end
  end
end

C
Carlhuda 已提交
42
PROJECTS = %w(activesupport activemodel actionpack actionmailer activeresource activerecord railties)
43 44

desc 'Run all tests by default'
45
task :default => %w(test test:isolated)
46

47
%w(test test:isolated package gem).each do |task_name|
48 49
  desc "Run #{task_name} task for all projects"
  task task_name do
50
    errors = []
51
    PROJECTS.each do |project|
52
      system(%(cd #{project} && #{$0} #{task_name})) || errors << project
53
    end
54
    fail("Errors in #{errors.join(', ')}") unless errors.empty?
55 56
  end
end
J
Jeremy Kemper 已提交
57

58 59 60
desc "Smoke-test all projects"
task :smoke do
  (PROJECTS - %w(activerecord)).each do |project|
61
    system %(cd #{project} && #{$0} test:isolated)
62
  end
63
  system %(cd activerecord && #{$0} sqlite3:isolated_test)
64
end
C
Carlhuda 已提交
65

J
José Valim 已提交
66
desc "Install gems for all projects."
67
task :install => :gem do
68
  version = File.read("RAILS_VERSION").strip
69
  (PROJECTS - ["railties"]).each do |project|
C
Carlhuda 已提交
70
    puts "INSTALLING #{project}"
71
    system("gem install #{project}/pkg/#{project}-#{version}.gem --no-ri --no-rdoc")
72
  end
73 74
  system("gem install railties/pkg/railties-#{version}.gem --no-ri --no-rdoc")
  system("gem install pkg/rails-#{version}.gem --no-ri --no-rdoc")
75 76
end

J
Jeremy Kemper 已提交
77
desc "Generate documentation for the Rails framework"
A
Aaron Patterson 已提交
78
RDoc::Task.new do |rdoc|
79 80
  hijack_rdoc!

J
Jeremy Kemper 已提交
81 82
  rdoc.rdoc_dir = 'doc/rdoc'
  rdoc.title    = "Ruby on Rails Documentation"
J
Jeremy Kemper 已提交
83

A
Aaron Patterson 已提交
84
  rdoc.options << '-f' << 'horo'
85 86 87 88
  rdoc.options << '-c' << 'utf-8'
  rdoc.options << '-m' << 'README.rdoc'

  rdoc.rdoc_files.include('README.rdoc')
J
Jeremy Kemper 已提交
89 90 91

  rdoc.rdoc_files.include('railties/CHANGELOG')
  rdoc.rdoc_files.include('railties/MIT-LICENSE')
92
  rdoc.rdoc_files.include('railties/README.rdoc')
93 94
  rdoc.rdoc_files.include('railties/lib/**/*.rb')
  rdoc.rdoc_files.exclude('railties/lib/rails/generators/**/templates/*')
J
Jeremy Kemper 已提交
95

96
  rdoc.rdoc_files.include('activerecord/README.rdoc')
J
Jeremy Kemper 已提交
97 98 99 100
  rdoc.rdoc_files.include('activerecord/CHANGELOG')
  rdoc.rdoc_files.include('activerecord/lib/active_record/**/*.rb')
  rdoc.rdoc_files.exclude('activerecord/lib/active_record/vendor/*')

101
  rdoc.rdoc_files.include('activeresource/README.rdoc')
J
Jeremy Kemper 已提交
102 103 104 105
  rdoc.rdoc_files.include('activeresource/CHANGELOG')
  rdoc.rdoc_files.include('activeresource/lib/active_resource.rb')
  rdoc.rdoc_files.include('activeresource/lib/active_resource/*')

106
  rdoc.rdoc_files.include('actionpack/README.rdoc')
J
Jeremy Kemper 已提交
107
  rdoc.rdoc_files.include('actionpack/CHANGELOG')
108
  rdoc.rdoc_files.include('actionpack/lib/abstract_controller/**/*.rb')
J
Jeremy Kemper 已提交
109
  rdoc.rdoc_files.include('actionpack/lib/action_controller/**/*.rb')
110
  rdoc.rdoc_files.include('actionpack/lib/action_dispatch/**/*.rb')
J
Jeremy Kemper 已提交
111 112 113
  rdoc.rdoc_files.include('actionpack/lib/action_view/**/*.rb')
  rdoc.rdoc_files.exclude('actionpack/lib/action_controller/vendor/*')

114
  rdoc.rdoc_files.include('actionmailer/README.rdoc')
J
Jeremy Kemper 已提交
115 116 117 118
  rdoc.rdoc_files.include('actionmailer/CHANGELOG')
  rdoc.rdoc_files.include('actionmailer/lib/action_mailer/base.rb')
  rdoc.rdoc_files.exclude('actionmailer/lib/action_mailer/vendor/*')

119
  rdoc.rdoc_files.include('activesupport/README.rdoc')
J
Jeremy Kemper 已提交
120 121 122
  rdoc.rdoc_files.include('activesupport/CHANGELOG')
  rdoc.rdoc_files.include('activesupport/lib/active_support/**/*.rb')
  rdoc.rdoc_files.exclude('activesupport/lib/active_support/vendor/*')
X
Xavier Noria 已提交
123

124
  rdoc.rdoc_files.include('activemodel/README.rdoc')
X
Xavier Noria 已提交
125 126
  rdoc.rdoc_files.include('activemodel/CHANGELOG')
  rdoc.rdoc_files.include('activemodel/lib/active_model/**/*.rb')
J
Jeremy Kemper 已提交
127 128 129 130
end

# Enhance rdoc task to copy referenced images also
task :rdoc do
J
Jeremy Kemper 已提交
131 132
  FileUtils.mkdir_p "doc/rdoc/files/examples/"
  FileUtils.copy "activerecord/examples/associations.png", "doc/rdoc/files/examples/associations.png"
J
Jeremy Kemper 已提交
133 134
end

135
desc 'Bump all versions to match version.rb'
136
task :update_versions do
137 138 139 140 141 142
  require File.dirname(__FILE__) + "/version"

  File.open("RAILS_VERSION", "w") do |f|
    f.write Rails::VERSION::STRING + "\n"
  end

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
  constants = {
    "activesupport"   => "ActiveSupport",
    "activemodel"     => "ActiveModel",
    "actionpack"      => "ActionPack",
    "actionmailer"    => "ActionMailer",
    "activeresource"  => "ActiveResource",
    "activerecord"    => "ActiveRecord",
    "railties"        => "Rails"
  }

  version_file = File.read("version.rb")

  PROJECTS.each do |project|
    Dir["#{project}/lib/*/version.rb"].each do |file|
      File.open(file, "w") do |f|
        f.write version_file.gsub(/Rails/, constants[project])
      end
    end
  end
end
163 164 165 166 167 168 169 170 171 172 173 174

#
# We have a webhook configured in Github that gets invoked after pushes.
# This hook triggers the following tasks:
#
#   * updates the local checkout
#   * updates Rails Contributors
#   * generates and publishes edge docs
#   * if there's a new stable tag, generates and publishes stable docs
#
# Everything is automated and you do NOT need to run this task normally.
#
S
Santiago Pastorino 已提交
175
# We publish a new version by tagging, and pushing a tag does not trigger
176 177 178 179 180 181 182 183 184 185 186
# that webhook. Stable docs would be updated by any subsequent regular
# push, but if you want that to happen right away just run this.
#
desc 'Publishes docs, run this AFTER a new stable tag has been pushed'
task :publish_docs do
  Net::HTTP.new('rails-hooks.hashref.com').start do |http|
    request  = Net::HTTP::Post.new('/rails-master-hook')
    response = http.request(request)
    puts response.body
  end
end