Created
September 2, 2012 03:05
-
-
Save cfcosta/3594414 to your computer and use it in GitHub Desktop.
Sinatra application for serving simple Single Page Applications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
Bundler.require | |
class Application < Sinatra::Base | |
get '/assets/:file' do | |
env['PATH_INFO'].gsub!("/assets","") | |
asset_handler.call(env) | |
end | |
get '/' do | |
erb :index | |
end | |
private | |
def project_root | |
@project_root ||= File.expand_path File.dirname(__FILE__) | |
end | |
def asset_handler | |
@asset_handler ||= create_asset_handler | |
end | |
def create_asset_handler | |
handler = Sprockets::Environment.new(project_root) | |
handler.cache = Sprockets::Cache::FileStore.new("/tmp") | |
handler.append_path(File.join(project_root, 'src/javascripts')) | |
handler.append_path(File.join(project_root, 'src/stylesheets')) | |
handler | |
end | |
end | |
run Application |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment