Skip to content

Commit 7578a3c

Browse files
committed
1 parent a52189c commit 7578a3c

File tree

1 file changed

+68
-5
lines changed

1 file changed

+68
-5
lines changed

Rakefile

Lines changed: 68 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,73 @@ 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 `git ls-files -z docs *.md`.split("\x0")
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 = Rails.root.to_s
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 .' 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 'git checkout gh-pages'
69+
else
70+
sh 'git checkout --orphan gh-pages'
71+
sh 'git rm -rf . || echo $?'
72+
sh 'echo "Page" > index.html'
73+
sh 'git add index.html'
74+
sh 'git commit -a -m "First pages commit"'
75+
sh "git push #{DOC_REMOTE_NAME} gh-pages --force-with-lease"
76+
end
77+
end
78+
end
79+
end
80+
81+
desc 'Generate and publish YARD docs to GitHub pages.'
82+
task publish: ['doc:pages:checkout', 'doc:pages:clean', 'doc:pages'] do
83+
Dir.chdir(DOC_DIR) do
84+
sh "cat .git/HEAD | grep -q 'gh-pages' || git checkout gh-pages || echo $?"
85+
sh 'git add .'
86+
sh 'git add -u'
87+
sh 'git diff --stat | cat'
88+
sh 'git diff --stat --staged | cat'
89+
sh 'git remote -v'
90+
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 $!"
91+
end
92+
end
93+
end
3194
end
3295

3396
begin

0 commit comments

Comments
 (0)