Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Store bundles

  • Loading branch information...
commit e50a13d66dcd92bb3dd6b3b2f22ad2e06767a23a 1 parent d0efd66
@peteog authored
Showing with 24 additions and 0 deletions.
  1. +24 −0 lib/sinatra/simple_assets.rb
View
24 lib/sinatra/simple_assets.rb
@@ -18,16 +18,38 @@ def javascript(name)
end
end
+ class Bundle
+ def initialize(name, type, root, files)
+ @name = name
+ @type = type
+ @root = root
+ @files = files
+ end
+
+ def name
+ "#{@name}.#{@type}"
+ end
+ end
+
class Assets
def initialize(app, &block)
@app = app
+ @bundles = {}
+ @hashes = {}
instance_eval(&block)
end
def css(bundle, files)
+ create_bundle(bundle, :css, files)
end
def js(bundle, files)
+ create_bundle(bundle, :js, files)
+ end
+
+ def create_bundle(name, type, name, files)
+ bundle = Bundle.new(name, type, @app.public_folder, files)
+ @bundles[bundle.name] = bundle
end
def paths_for(bundle)
@@ -35,6 +57,8 @@ def paths_for(bundle)
end
def content_for(bundle)
+ bundle = @bundles[@hashes[bundle]]
+ bundle.content if bundle
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.