bin/slidehero in slide_hero-0.0.2 vs bin/slidehero in slide_hero-0.0.3
- old
+ new
@@ -8,29 +8,55 @@
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')
- directory 'vendor/reveal.js', 'presentation'
- File.open('presentation/index.html', 'w+') do |f|
+ 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')
- directory 'vendor/reveal.js', '.tmp'
- File.open('.tmp/index.html', 'w+') do |f|
- f.puts eval(File.read(name), SlideHero.get_binding)
- end
+ compile(name, '.tmp')
puts "Go checkout your awesome presentation at http://localhost:9292!"
- system("rackup #{Gem.loaded_specs['slide_hero'].full_gem_path}/config.ru")
- rescue Interrupt
+
+ rackupPid = Process.spawn("rackup #{Gem.loaded_specs['slide_hero'].full_gem_path}/config.ru")
+
+ 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, rackupPid) 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