Permalink
Browse files

Serve assets from bundles

  • Loading branch information...
1 parent e50a13d commit f5dd539352e605356d53189fc50a064edf919cc0 @peteog committed Dec 15, 2011
Showing with 10 additions and 6 deletions.
  1. +10 −6 lib/sinatra/simple_assets.rb
@@ -5,20 +5,22 @@ module SimpleAssets
VERSION = '0.0.1'
module Helpers
- def stylesheet(name)
- settings.assets.paths_for("#{name}.css").map do |file|
+ def stylesheet(bundle)
+ settings.assets.paths_for("#{bundle}.css").map do |file|
"<link rel=\"stylesheet\" href=\"#{url(file)}\">"
end.join("\n")
end
- def javascript(name)
- settings.assets.paths_for("#{name}.js").map do |file|
+ def javascript(bundle)
+ settings.assets.paths_for("#{bundle}.js").map do |file|
"<script src=\"#{url(file)}\"></script>"
end.join("\n")
end
end
class Bundle
+ attr_accessor :files
+
def initialize(name, type, root, files)
@name = name
@type = type
@@ -47,13 +49,15 @@ def js(bundle, files)
create_bundle(bundle, :js, files)
end
- def create_bundle(name, type, name, files)
+ def create_bundle(name, type, files)
bundle = Bundle.new(name, type, @app.public_folder, files)
@bundles[bundle.name] = bundle
end
def paths_for(bundle)
- []
+ bundle = @bundles[bundle]
+ return [] unless bundle
+ bundle.files
end
def content_for(bundle)

0 comments on commit f5dd539

Please sign in to comment.