forked from rubocop/ruby-style-guide
/
generate.rake
44 lines (37 loc) · 1.3 KB
/
generate.rake
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
# Taken from hub
# https://github.com/defunkt/hub/blob/master/lib/hub/context.rb#L186
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = "#{path}/#{cmd}#{ext}"
return exe if File.executable? exe
}
end
return nil
end
require 'ruby_style_guide'
namespace :generate do
task :sanity_check do
unless which("pygmentize")
abort "Please install pygments, sudo easy_install pygments"
end
unless which("wkhtmltopdf")
abort "Please install wkhtmltopdf, if you are using linux-i386 or mac, you can install the gem wkhtmltopdf-binary"
end
end
desc "Generate README.pdf"
task :pdf => :sanity_check do
html = RubyStyleGuide::HtmlGenerator.process(File.read("README.md"))
pdf = RubyStyleGuide::PdfGenerator.process(html, :stylesheets => %w(stylesheets/default.css))
File.open('README.pdf', 'w') { |f| f.write(pdf) }
end
desc "Generate README.html"
task :html => :sanity_check do
html = RubyStyleGuide::HtmlGenerator.process(File.read("README.md"), :stylesheets => %w(stylesheets/default.css))
File.open('README.html', 'w') { |f| f.write(html) }
end
end