Sha256: c530f80b7fc0daaf6453ab772d0a2bb5ca3d5ca95250d24f2eeef3c1884b6713
Contents?: true
Size: 1.24 KB
Versions: 10
Compression:
Stored size: 1.24 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
10 entries across 10 versions & 1 rubygems