Skip to content

Instantly share code, notes, and snippets.

@jenningsanderson
Created October 31, 2016 22:23
Show Gist options
  • Save jenningsanderson/104e4d9d7f9bc332b2db567afdd32232 to your computer and use it in GitHub Desktop.
Save jenningsanderson/104e4d9d7f9bc332b2db567afdd32232 to your computer and use it in GitHub Desktop.
#
# Jennings Anderson 2016
#
# Compile a 'slides' directory to a reveal presentation (with customizations)
#
#
def run_build(args={})
print "Building: "
out_file = args["file"] || "index.html"
slides_dir = args["slides"] || "slides"
front_matter = args["front_matter"]
slide_files = Dir.glob(slides_dir+"/**/**")
slide_files.reject!{|x| !x.end_with? '.html'}
slides = slide_files.map{|x| {slide: x[x.rindex("/")+1 .. -1].to_f, file: x}}
slides.sort_by!{|x| x[:slide]}
print "["
File.open(out_file,'w') do |f|
f.puts(args.to_yaml)
f.puts('---')
slides.each do |s|
f.puts("<!-- Slide: #{s[:slide]}-->")
this_slide = File.read(s[:file])
if this_slide.start_with? "-----"
sections = this_slide.split("-----")
f.puts("<section #{sections[1].chomp}>")
f.puts(sections[2])
f.puts('</section>')
else
f.puts('<section>')
f.puts(this_slide)
f.puts('</section>')
end
print "."
end
end
puts ']'
end
if __FILE__ == $0
require 'listen'
require 'yaml'
config_file = ARGV[0] || 'config.yml'
config = YAML.load(File.read(config_file))
run_build( config )
listener = Listen.to(config["slides"]) do |modified, added, removed|
run_build( config )
end
listener.start
sleep
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment