This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

sprockets now runs inside sinatra

  • Loading branch information...
1 parent d5f357d commit 577438992e095b491061a1c479d18d1b6c5534ea @andreaseger committed Mar 5, 2012
Showing with 14 additions and 19 deletions.
  1. +6 −3 app.rb
  2. +1 −1 config/environment.rb
  3. +6 −4 lib/asset_helper.rb
  4. +1 −11 views/layout.rb
View
9 app.rb
@@ -7,10 +7,7 @@ class App < Sinatra::Base
set :root, File.dirname(__FILE__)
set :public_folder, File.join(root, 'public')
- set :assets_prefix, 'assets'
- set :assets_path, File.join(public_folder, assets_prefix)
- set :sprockets, ::AssetHelper::sprockets
configure do |c|
set :mustache, {
templates: File.join(root, 'templates'),
@@ -27,6 +24,12 @@ class App < Sinatra::Base
c.also_reload "./views/**/*.tb"
end
+ get '/assets/*' do
+ new_env = env.clone
+ new_env["PATH_INFO"].gsub!('/assets','')
+ ::Assets.sprockets.call(new_env)
+ end
+
get '/' do
mustache :home
end
View
@@ -20,4 +20,4 @@
{}
end
-require './../lib/asset_helper.rb'
+require_relative '../lib/asset_helper.rb'
View
@@ -1,8 +1,10 @@
-module AssetHelpers
- def asset_path(source)
- "/assets/" + sprockets.find_asset(source).digest_path
+module Assets
+ module Helpers
+ def asset_path(source)
+ "/assets/" + ::Assets.sprockets.find_asset(source).digest_path
+ end
end
- def sprockets
+ def self.sprockets
return @sprockets if @sprockets
compass_gem_root = Gem.loaded_specs['compass'].full_gem_path
@sprockets = Sprockets::Environment.new { |env| env.logger = Logger.new(STDOUT) }
View
@@ -1,26 +1,16 @@
class App
module Views
class Layout < Mustache
- include AssetHelpers
+ include Assets::Helpers
def title
"App"
end
def stylesheets_tag
%{<link href="#{asset_path 'application.css'}" media="screen, projection" rel="stylesheet" type="text/css" />}
- #if @settings.try(:production?)
- # '<link href="/compiled/css/application.min.css" media="screen, projection" rel="stylesheet" type="text/css" />'
- #else
- # %{<link href="#{@assets_css || "foo"}" media="screen, projection" rel="stylesheet" type="text/css" />}
- #end
end
def javascripts_tag
%{<script src="#{asset_path 'application.js'}"</script>}
- #if @settings.try(:production?)
- # '<script src="/compiled/js/application.min.js" type="text/javascript"></script>'
- #else
- # %{<script src="#{@assets_js || "foo"}" type="text/javascript"></script>'}
- #end
end
end
end

0 comments on commit 5774389

Please sign in to comment.