Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: d71e0e641c
...
compare: b5d65c5ec3
  • 5 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 31, 2012
@namelessjon Allow Assets to be configured multiple times 9c14465
@namelessjon Return self from commands b82571a
@namelessjon Allow assigning Assets ffad0ec
@namelessjon Allow a separate asset root
This allows for e.g. assets in app/assets/ which get compiled into
public/ for deployment, so there's no need to mix compiled and real
files in the same folder tree.
a77ffcd
@namelessjon Expose configuration for the asset root b5d65c5
View
7 lib/sinatra/simple_assets.rb
@@ -17,13 +17,16 @@ def javascript(bundle)
end
end
- def assets(&block)
- @assets ||= Assets.new(self.public_folder, &block)
+ def assets(assets = nil, &block)
+ @assets ||= (assets ? assets : Assets.new(self.public_folder, self.asset_root))
+ @assets.configure(&block)
end
def self.registered(app)
app.helpers SimpleAssets::Helpers
+ set :asset_root, self.public_folder
+
[
{ :route => '/css', :type => :css },
{ :route => '/js', :type => :js }
View
20 lib/sinatra/simple_assets/assets.rb
@@ -2,11 +2,17 @@
module Sinatra
module SimpleAssets
class Assets
- def initialize(root, &block)
- @root = root
- @bundles = {}
- @hashes = {}
- instance_eval(&block)
+ def initialize(root, asset_root=root, &block)
+ @root = root
+ @asset_root = asset_root
+ @bundles = {}
+ @hashes = {}
+ configure(&block)
+ end
+
+ def configure(&block)
+ instance_eval(&block) if block_given?
+ self
end
def css(bundle, files)
@@ -18,9 +24,10 @@ def js(bundle, files)
end
def create_bundle(name, type, files)
- bundle = Bundle.new(name, type, @root, files)
+ bundle = Bundle.new(name, type, @root, @asset_root, files)
@bundles[bundle.name] = bundle
@hashes[bundle.hashed_path] = bundle
+ self
end
def paths_for(bundle, environment = :development)
@@ -43,6 +50,7 @@ def precompile
@bundles.values.each do |bundle|
bundle.compile
end
+ self
end
def bundle_exists?(bundle)
View
13 lib/sinatra/simple_assets/bundle.rb
@@ -4,11 +4,12 @@ module SimpleAssets
class Bundle
attr_accessor :files
- def initialize(name, type, root, files)
- @name = name
- @type = type
- @root = root
- @files = files
+ def initialize(name, type, root, asset_root, files)
+ @name = name
+ @type = type
+ @root = root
+ @asset_root = asset_root
+ @files = files
end
def name
@@ -40,7 +41,7 @@ def content
def combined
@combined ||= @files.map do |file|
- File.open(@root + file) { |f| f.read }
+ File.open(@asset_root + file) { |f| f.read }
end.join("\n")
end

No commit comments for this range

Something went wrong with that request. Please try again.