Sha256: 58712b3ca8dde694db3c2e84987da4bbdb7fc5e9f0906e97b2732de730f7b69d

Contents?: true

Size: 1.8 KB

Versions: 4

Compression:

Stored size: 1.8 KB

Contents

#!/usr/bin/env ruby

require 'slide_hero'
require 'thor'
require 'fileutils'

class PresentationGenerator < Thor
  include Thor::Actions
  desc "new NAME", "Create a new presentation"
  def new(name)
    @name = name
    template 'templates/new_presentation.tt', "#{name}/presentation.rb"
    ['/images', '/audio', '/video', '/code']. each do |media|
      empty_directory "#{name}/#{media}"
    end
  end

  desc "compile PRESENTATION_NAME (defaults to presentation.rb", "Compile presentation"
  def compile(name = 'presentation.rb', folder="presentation")
    directory 'vendor/reveal.js', folder
    move_slide_files(name, folder)
  end

  desc "move_slide_files NAME DEST_FOLDER", "Only move the user generated files"
  def move_slide_files(name, folder)
    ['/images', '/audio', '/video', '/code']. each do |media|
      FileUtils.cp_r(File.dirname(File.realdirpath(name)) + media, "#{folder}")
    end

    File.open("#{folder}/index.html", 'w+') do |f|
      f.puts eval(File.read(name), SlideHero.get_binding)
    end
  end

  desc "serve FILENAME", "starts a server running your presentation on port 9292"
  def serve(name = 'presentation.rb')
    compile(name, '.tmp')
    puts "Go checkout your awesome presentation at http://localhost:9292!"

    serverPid = Process.spawn("ruby -run -e httpd .tmp -p 9292")

    last_update = Time.now
    loop do
      if File.mtime(name) > last_update
        puts "File change noted!"
        puts "Recompiling"
        move_slide_files(name, '.tmp')
        last_update = File.mtime(name)
      end
      sleep 1
    end

  rescue Exception => e
    puts e
    Process.kill(9, serverPid) rescue Errno::ESRCH
    remove_dir '.tmp'
    puts "GOING DOWN!"
    exit 0
  end
end

PresentationGenerator.source_root(Gem.loaded_specs['slide_hero'].full_gem_path)
PresentationGenerator.start ARGV

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
slide_hero-0.0.11 bin/slidehero
slide_hero-0.0.10 bin/slidehero
slide_hero-0.0.9 bin/slidehero
slide_hero-0.0.8 bin/slidehero