#!/usr/bin/env ruby require 'gli' require 'reveal-ck' class RevealCKExecutable extend GLI::App program_desc 'A reveal.js construction kit' version RevealCK::VERSION desc 'Generate reveal.js slides' command :generate do |c| slide_files = FileList['slides.*'] default_file = slide_files.empty? ? nil : slide_files.first c.desc 'The file containing your slide content' c.flag [:f, :file], default_value: default_file c.desc 'The directory to place your generated slides in' c.flag [:d, :dir], default_value: 'slides' c.action do |_, options, _| slides_file = options[:file] if slides_file.nil? puts puts 'Problem:' puts puts ' reveal-ck could not find a slides file, and it cannnot build' puts ' your presentation without one.' puts puts ' It thinks anything that matches "slides.*" is a slides file.' puts puts ' Some examples are: slides.md, slides.html, slides.haml' puts msg = 'Create a file matching slides.* to proceed, such as slides.md.' exit_now!(msg) end puts "Generating slides for '#{slides_file}'.." builder_args = { user_dir: Dir.pwd, gem_dir: RevealCK.path, output_dir: options[:dir], slides_file: options[:file] } slides_builder = RevealCK::Builders::SlidesBuilder.new(builder_args) slides_builder.prepare slides_builder.build end end desc 'Start webserver so slides are available via http' command :serve, :server do |c| c.desc 'The directory to serve up' c.flag [:d, :dir], default_value: 'slides' c.desc 'The port to serve on' c.flag [:p, :port], default_value: 10_000 c.action do |_, options, _| dir = options[:dir] port = options[:port] require 'webrick' server = WEBrick::HTTPServer.new Port: port, DocumentRoot: dir trap('INT') { server.shutdown } puts puts puts "\tServing up slide content in '#{dir}/'." puts puts "\tOpen your browser to 'http://localhost:#{port}'." puts puts "\tPress CTRL-C to stop serving slides." puts puts server.start end end exit run(ARGV) end