Skip to content

Commit e7b0685

Browse files
committed
1 parent a52189c commit e7b0685

File tree

1 file changed

+69
-5
lines changed

1 file changed

+69
-5
lines changed

Rakefile

Lines changed: 69 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,74 @@ 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+
# #files => Array<String>
29+
# The Ruby source files (and any extra documentation files separated by '-') to process.
30+
DOC_FILES = ['lib/**/*.rb', '-', 'README.md']
31+
DOC_FILES.concat Rake::FileList['docs/**/*.md'].to_a
32+
DOC_FILES.freeze
33+
DOC_REF = `git log --pretty=format:'%h' -1 | less -F -X`.chomp
34+
DOC_VERSION = ActiveModel::Serializer::VERSION
35+
DOC_REMOTE = "[email protected]:rails-api/active_model_serializers.git"
36+
DOC_REMOTE_NAME = 'origin'
37+
DOC_ROOT = File.expand_path('..', __FILE__)
38+
DOC_PATH = File.join('..', 'ams.doc')
39+
DOC_DIR = File.join(DOC_ROOT, DOC_PATH)
40+
41+
YARD::Rake::YardocTask.new(:doc) do |t|
42+
t.stats_options = ['--list-undoc']
43+
t.files = DOC_FILES
44+
end
45+
46+
YARD::Rake::YardocTask.new(:pages) do |t|
47+
t.files = DOC_FILES
48+
t.options = ['-o', DOC_PATH]
49+
end
50+
51+
namespace :pages do
52+
task :clean do
53+
Dir.chdir(DOC_DIR) do
54+
next unless File.directory?('.git')
55+
sh 'git rm -rf . || echo $?' if system("git diff HEAD^..HEAD &>/dev/null | cat")
56+
end
57+
end
58+
59+
desc 'Check out gh-pages.'
60+
task :checkout do
61+
unless Dir.exist?(DOC_DIR)
62+
Dir.mkdir(DOC_DIR)
63+
Dir.chdir(DOC_DIR) do
64+
sh 'git init'
65+
sh "git remote add #{DOC_REMOTE_NAME} #{DOC_REMOTE}"
66+
sh "git fetch #{DOC_REMOTE_NAME}"
67+
if system('git branch -r gh-pages')
68+
sh "cat .git/HEAD | grep -q 'gh-pages' || git checkout gh-pages || echo $?"
69+
sh "git reset --hard #{DOC_REMOTE_NAME}/#{gh-pages}"
70+
else
71+
sh 'git checkout --orphan gh-pages'
72+
sh 'git rm -rf . || echo $?'
73+
sh 'echo "Page" > index.html'
74+
sh 'git add index.html'
75+
sh 'git commit -a -m "First pages commit"'
76+
sh "git push #{DOC_REMOTE_NAME} gh-pages --force-with-lease"
77+
end
78+
end
79+
end
80+
end
81+
82+
desc 'Generate and publish YARD docs to GitHub pages.'
83+
task publish: ['doc:pages:checkout', 'doc:pages:clean', 'doc:pages'] do
84+
Dir.chdir(DOC_DIR) do
85+
sh "cat .git/HEAD | grep -q 'gh-pages' || git checkout gh-pages || echo $?"
86+
sh 'git add .'
87+
sh 'git add -u'
88+
sh 'git diff --stat | cat'
89+
sh 'git diff --stat --staged | cat'
90+
sh 'git remote -v'
91+
sh "git commit -m 'Generating docs for version #{DOC_VERSION} at ref #{DOC_REF}.' && git push #{DOC_REMOTE_NAME} gh-pages --force-with-lease || echo $!"
92+
end
93+
end
94+
end
3195
end
3296

3397
begin

0 commit comments

Comments
 (0)