Sha256: 4cc95a3edb07dcea892778ec12671decd06393aeb6cc6425f06e7ad038e7145d
Contents?: true
Size: 1.22 KB
Versions: 6
Compression:
Stored size: 1.22 KB
Contents
require 'sinatra/static_assets' require 'sinatra/url_for' module TableSetter class App < Sinatra::Base helpers Sinatra::UrlForHelper register Sinatra::StaticAssets set :root, TableSetter.config_path # serve static files from the public directory enable :static not_found do show :"404" end error do show :"500" end get "/" do headers['Cache-Control'] = "public, max-age=#{TableSetter::App.cache_timeout}" last_modified Table.fresh_yaml_time show :index, :tables => Table.all end ["/:slug/:page/?", "/:slug/?"].each do |path| get path do headers['Cache-Control'] = "public, max-age=#{TableSetter::App.cache_timeout}" not_found unless Table.exists? params[:slug] table = Table.new(params[:slug], :defer => true) last_modified table.updated_at table.load page = params[:page] || 1 table.paginate! page show :table, :table => table, :page => page end end private def show(page, locals={}) erb page, {:layout => true}, locals end class << self attr_accessor :cache_timeout def cache_timeout @cache_timeout || 0 end end end end
Version data entries
6 entries across 6 versions & 1 rubygems