-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnew-presentation.rb
executable file
·46 lines (33 loc) · 1.21 KB
/
new-presentation.rb
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
# Windows:
# docker run -it --rm --name new-presentation -v ${PWD}:/usr/src/myapp -w /usr/src/myapp ruby:2.5 ruby new-presentation.rb -v
# If this screws up permissions, you might need to run the following:
# sudo chown dane:dane -R FolderName
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: new-presentation.rb [options] TITLE"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
end
end.parse!
title = ARGV.join(' ')
name = title.split(' ').map(&:capitalize).join('')
url = 'https://daneweber.github.io/presentations'
files = {
"#{name}.md" => "# #{title}\n\n",
'readme.md' => "[#{title}](#{url}/#{name}/#{name}.html)\n\n"
}
html = File.read(File.join('Template', 'template.html'))
html.sub!(%r{-[^-<]+</title>}, "- #{title}</title>")
html.sub!(%r{data-markdown="[^"]+"}, %Q{data-markdown="#{name}.md"})
files["#{name}.html"] = html
serve = File.read(File.join('Template', 'serve.ps1'))
serve.sub!('/name/name.html', "/#{name}/#{name}.html")
files["serve.ps1"] = serve
Dir.mkdir(name)
Dir.chdir(name) do
files.each{ |fname, content| File.write(fname, content) }
end
File.open("README.md", "a") do |handle|
handle << "\n#{files['readme.md']}"
end