-
Notifications
You must be signed in to change notification settings - Fork 316
/
Rakefile
150 lines (127 loc) · 4.01 KB
/
Rakefile
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# frozen_string_literal: true
require "rubygems"
require "bundler/gem_tasks"
require "rake"
require "rdoc"
require "date"
require "yaml"
#############################################################################
#
# Helper functions
#
#############################################################################
def name
@name ||= Dir["*.gemspec"].first.split(".").first
end
def version
JekyllImport::VERSION
end
def normalize_bullets(markdown)
markdown.gsub(%r!\n\s{2}\*{1}!, "\n-")
end
def linkify_prs(markdown)
markdown.gsub(%r!(?<\!&)#(\d+)!) do |word|
"[#{word}]({{ site.repository }}/issues/#{word.delete("#")})"
end
end
def linkify_users(markdown)
markdown.gsub(%r!(@\w+)!) do |username|
"[#{username}](https://github.com/#{username.delete("@")})"
end
end
def linkify(markdown)
linkify_users(linkify_prs(markdown))
end
def liquid_escape(markdown)
markdown.gsub(%r!(`{[{%].+[}%]}`)!, "{% raw %}\\1{% endraw %}")
end
def remove_head_from_history(markdown)
index = markdown =~ %r!^##\s+\d+\.\d+\.\d+!
markdown[index..-1]
end
def converted_history(markdown)
remove_head_from_history(liquid_escape(linkify(normalize_bullets(markdown))))
end
#############################################################################
#
# Standard tasks
#
#############################################################################
task :default => :test
require "rake/testtask"
Rake::TestTask.new(:test) do |test|
test.libs << "lib" << "test"
test.pattern = "test/**/test_*.rb"
test.verbose = true
test.warning = false
end
require "rdoc/task"
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = "rdoc"
rdoc.title = "#{name} #{version}"
rdoc.rdoc_files.include("README*")
rdoc.rdoc_files.include("lib/**/*.rb")
end
desc "Open an irb session preloaded with this library"
task :console do
sh "irb -rubygems -r ./lib/#{name}.rb"
end
#############################################################################
#
# Site tasks - http://import.jekyllrb.com
#
#############################################################################
namespace :site do
desc "Generate and view the site locally"
task :preview do
require "launchy"
# Yep, it's a hack! Wait a few seconds for the Jekyll site to generate and
# then open it in a browser. Someday we can do better than this, I hope.
Thread.new do
sleep 4
puts "Opening in browser..."
Launchy.open("http://localhost:4000")
end
# Generate the site in server mode.
puts "Running Jekyll..."
Dir.chdir("docs") do
sh "jekyll serve --watch"
end
end
desc "Update normalize.css library to the latest version and minify"
task :update_normalize_css do
normalize_file = "docs/_sass/normalize.scss"
sh "curl \"http://necolas.github.io/normalize.css/latest/normalize.css\" -o #{normalize_file}"
sh "sass #{normalize_file}:#{normalize_file} --style compressed"
end
desc "Commit the local site to the gh-pages branch and publish to GitHub Pages"
task :publish => [:history] do
puts "We now publish directly from the docs/ subfolder on the master branch."
end
desc "Create a nicely formatted history page for the jekyll site based on the repo history."
task :history do
if File.exist?("History.markdown")
history_file = File.read("History.markdown")
front_matter = {
"layout" => "docs",
"title" => "History",
"permalink" => "/docs/history/",
"prev_section" => "contributing",
}
Dir.chdir("docs/_docs/") do
File.open("history.md", "w") do |file|
file.write("#{front_matter.to_yaml}---\n\n")
file.write(converted_history(history_file))
end
end
if `git diff docs/_docs/history.md`.strip.empty?
puts "No updates to commit at this time. Skipping..."
else
sh "git add docs/_docs/history.md"
sh "git commit -m 'Updated generated history.md file in the site.'"
end
else
abort "You seem to have misplaced your History.markdown file. I can haz?"
end
end
end