Permalink
Browse files

Remove duplication and fix register bug

  • Loading branch information...
1 parent ee93e41 commit e7540ba0438b146b78394ebbf1521832839429ab @peteog committed Dec 15, 2011
Showing with 19 additions and 19 deletions.
  1. +19 −19 lib/sinatra/simple_assets.rb
@@ -126,26 +126,26 @@ def assets(&block)
def self.registered(app)
app.helpers SimpleAssets::Helpers
- app.get '/stylesheets/:bundle' do
- serve_content(params[:bundle], :css)
- end
-
- app.get '/javascripts/:bundle' do
- serve_content(params[:bundle], :js)
- end
-
- def serve_content(bundle, type)
- assets = settings.assets
- exists = assets.bundle_exists?(bundle)
-
- etag bundle if exists
- not_found unless exists
-
- cache_control :public, :must_revalidate, :max_age => 86400
-
- content_type type
- assets.content_for(bundle)
+ [
+ { :route => '/stylesheets', :type => :css },
+ { :route => '/javascripts', :type => :js }
+ ].each do |r|
+ app.get "#{r[:route]}/:bundle" do
+ bundle = params[:bundle]
+ assets = settings.assets
+ exists = assets.bundle_exists?(bundle)
+
+ etag bundle if exists
+ not_found unless exists
+
+ cache_control :public, :must_revalidate, :max_age => 86400
+
+ content_type r[:type]
+ assets.content_for(bundle)
+ end
end
end
end
+
+ register SimpleAssets
end

0 comments on commit e7540ba

Please sign in to comment.