Skip to content

Commit 51329d1

Browse files
committed
1 parent a52189c commit 51329d1

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

Rakefile

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ Bundler::GemHelper.install_tasks
1212

1313
require 'yard'
1414

15-
namespace :yard do
16-
YARD::Rake::YardocTask.new(:doc) do |t|
17-
t.stats_options = ['--list-undoc']
18-
end
19-
15+
namespace :doc do
2016
desc 'start a gem server'
2117
task :server do
2218
sh 'bundle exec yard server --gems'
@@ -28,6 +24,63 @@ namespace :yard do
2824
sh "bundle exec yard graph --protected --full --dependencies > #{output_file}"
2925
puts 'open doc/erd.dot if you have graphviz installed'
3026
end
27+
28+
DOC_FILES = ['lib/**/*.rb', 'README.md'].freeze
29+
DOC_REF = `git log --pretty=format:'%h' -1`.chomp
30+
DOC_REMOTE = "[email protected]:rails-api/active_model_serializers.git"
31+
DOC_VERSION = ActiveModel::Serializer::VERSION
32+
DOC_PATH = '../ams.doc'
33+
DOC_DIR = File.dirname(__FILE__) + '/../ams.doc'
34+
35+
YARD::Rake::YardocTask.new(:doc) do |t|
36+
t.stats_options = ['--list-undoc']
37+
t.files = DOC_FILES
38+
end
39+
40+
YARD::Rake::YardocTask.new(:pages) do |t|
41+
t.files = DOC_FILES
42+
t.options = ['-o', DOC_PATH]
43+
end
44+
45+
namespace :pages do
46+
task :clean do
47+
Dir.chdir(DOC_DIR) do
48+
next unless File.directory?('.git')
49+
sh 'git rm -rf . || echo $!'
50+
end
51+
end
52+
53+
desc 'Check out gh-pages.'
54+
task :checkout do
55+
unless Dir.exist?(DOC_DIR)
56+
Dir.mkdir(DOC_DIR)
57+
Dir.chdir(DOC_DIR) do
58+
sh 'git init'
59+
sh "git remote add origin #{DOC_REMOTE}"
60+
sh 'git pull'
61+
sh 'git checkout gh-pages' || begin
62+
sh 'git checkout --orphan gh-pages'
63+
sh 'git rm -rf .'
64+
sh 'echo "Page" > index.html'
65+
sh 'git add index.html'
66+
sh 'git commit -a -m "First pages commit"'
67+
sh 'git push origin gh-pages'
68+
end
69+
end
70+
end
71+
end
72+
73+
desc 'Generate and publish YARD docs to GitHub pages.'
74+
task publish: ['doc:pages:checkout', 'doc:pages:clean', 'doc:pages'] do
75+
Dir.chdir(DOC_DIR) do
76+
sh 'git checkout gh-pages'
77+
sh 'git add .'
78+
sh 'git add -u'
79+
sh "git commit -m 'Generating docs for version #{DOC_VERSION} at ref #{DOC_REF}.'"
80+
sh 'git push origin gh-pages'
81+
end
82+
end
83+
end
3184
end
3285

3386
begin

0 commit comments

Comments
 (0)