lib/showoff.rb in showoff-0.9.10.7 vs lib/showoff.rb in showoff-0.9.10.8
- old
+ new
@@ -725,11 +725,16 @@
files << load_section_files(section)
files = files.flatten
files = files.select { |f| f =~ /.md$/ }
files.each do |f|
fname = f.gsub(settings.pres_dir + '/', '').gsub('.md', '')
- data << process_markdown(fname, File.read(f), opts)
+ begin
+ data << process_markdown(fname, File.read(f), opts)
+ rescue Errno::ENOENT => e
+ logger.error e.message
+ data << process_markdown(fname, "!SLIDE\n# Missing File!\n## #{fname}", opts)
+ end
end
end
end
end
process_content_for_all_slides(data, @slide_count, opts)
@@ -1087,10 +1092,34 @@
return eval_ruby(params[:code]) if ENV['SHOWOFF_EVAL_RUBY']
return "Ruby Evaluation is off. To turn it on set ENV['SHOWOFF_EVAL_RUBY']"
end
+ # provide a callback to trigger a local file editor, but only when called when viewing from localhost.
+ get '/edit/*' do |path|
+ # Docs suggest that old versions of Sinatra might provide an array here, so just make sure.
+ filename = path.class == Array ? path.first : path
+ @logger.debug "Editing #{filename}"
+ return unless File.exist? filename
+
+ if request.host != 'localhost'
+ @logger.warn "Disallowing edit because #{request.host} isn't localhost."
+ return
+ end
+
+ case RUBY_PLATFORM
+ when /darwin/
+ `open #{filename}`
+ when /linux/
+ `xdg-open #{filename}`
+ when /cygwin|mswin|mingw|bccwin|wince|emx/
+ `start #{filename}`
+ else
+ @logger.warn "Cannot open #{filename}, unknown platform #{RUBY_PLATFORM}."
+ end
+ end
+
get %r{(?:image|file)/(.*)} do
path = params[:captures].first
full_path = File.join(settings.pres_dir, path)
if File.exist?(full_path)
send_file full_path
@@ -1162,11 +1191,12 @@
when 'position'
ws.send( { 'current' => @@current[:number] }.to_json ) unless @@cookie.nil?
when 'pace', 'question'
- # just forward to the presenter(s)
- EM.next_tick { settings.presenters.each{|s| s.send(data) } }
+ # just forward to the presenter(s) along with a debounce in case a presenter is registered twice
+ control['id'] = guid()
+ EM.next_tick { settings.presenters.each{|s| s.send(control.to_json) } }
when 'feedback'
filename = "#{settings.statsdir}/#{settings.feedback}"
slide = control['slide']
rating = control['rating']