require 'bundler' Bundler.setup require 'sinatra/base' require 'slim' require 'sinatra/assetpack' require 'eggplant' module Sinatra::AssetPack class NoneEngine < Engine def js(str, options={}) str end end Compressor.register :js, :none, NoneEngine end module Eggplant class Server < Sinatra::Base set :root, File.dirname(__FILE__) register Sinatra::AssetPack assets do serve '/js', from: 'assets/js' serve '/css', from: 'assets/css' js :eggplant, '/js/eggplant.js', [ '/js/vendor/modernizr.js', '/js/vendor/jquery.js', # Deck '/js/vendor/deck.core.js', '/js/vendor/extensions/*.js', '/js/eggplant/main.js' ] js :eggplant_processors, '/js/eggplant_processors.js', [ #'/js/vendor/coffee-script.js', '/js/vendor/less.js' ] js :eggplant_remote, '/js/eggplant_remote.js', [ '/js/vendor/jquery.js', '/js/eggplant/remote.js' ] css :eggplant, '/css/eggplant.css', [ '/css/vendor/deck.core.css', '/css/vendor/transitions/horizontal-slide.css', '/css/vendor/extensions/*.css', '/css/eggplant/main.css' ] js_compression :none, :no_fallback => true end get '/' do slim :show end get '/remote' do slim :remote end get '/images/:filename' do |filename| path = File.join(settings.presentation_root, 'images', filename) send_file_if_exists path end get '/assets/:filename' do |filename| path = File.join(settings.presentation_root, 'assets', filename) send_file_if_exists path end get '/slides.:format' do |format| path = asset_path(format) send_file_if_exists path end get '/download.:format' do |format| end def index slim :show end def self.configure path, ui=['goto'] set :environment, :production set :presentation_root, path set :ui, ui end def self.build_html path showtime = Eggplant::Server.new while !showtime.is_a?(Eggplant::Server) showtime = showtime.instance_variable_get(:@app) end html = showtime.send('index') File.open(path, 'w') do |f| f << html end end helpers do def render_slides slides.to_html end def slides @slides ||= Eggplant::Slides.new settings.presentation_root end def send_file_if_exists path if File.exists?(path) send_file path else not_found end end def asset_path format File.join(settings.presentation_root, "slides.#{format}") end def remote_enabled? false end def has_js? File.exists?(asset_path('js')) end def has_coffee? File.exists?(asset_path('coffee')) end def has_css? File.exists?(asset_path('css')) end def has_less? File.exists?(asset_path('less')) end def show_status? settings.ui.include?('status') end def show_goto? settings.ui.include?('goto') end def show_navigation? settings.ui.include?('nav') end end end end