unique assets
This commit is contained in:
parent
e75abdda47
commit
fb5018148f
@ -1,5 +1,5 @@
|
||||
Feature: Process files with Sprockets
|
||||
Scenario: Simple Sprockets work
|
||||
Background:
|
||||
Given I have the file "dir/file.js" with the content:
|
||||
"""
|
||||
//= require other
|
||||
@ -9,6 +9,8 @@ Feature: Process files with Sprockets
|
||||
"""
|
||||
another file
|
||||
"""
|
||||
|
||||
Scenario: Simple Sprockets work
|
||||
When I instantiate a Sprockets handler with the following asset directories:
|
||||
| dir |
|
||||
And I work with the Sprockets asset "file"
|
||||
@ -16,3 +18,18 @@ Feature: Process files with Sprockets
|
||||
| dir/other.js |
|
||||
| dir/file.js |
|
||||
|
||||
Scenario: Require the file twice
|
||||
Given I have the file "dir/third.js" with the content:
|
||||
"""
|
||||
//= require other
|
||||
third file
|
||||
"""
|
||||
When I instantiate a Sprockets handler with the following asset directories:
|
||||
| dir |
|
||||
And I work with the Sprockets asset "file"
|
||||
And I work with the Sprockets asset "third"
|
||||
Then the handler should have the following files in order:
|
||||
| dir/other.js |
|
||||
| dir/file.js |
|
||||
| dir/third.js |
|
||||
|
||||
|
@ -3,6 +3,7 @@ module Flowerbox
|
||||
autoload :Server, 'flowerbox/delivery/server'
|
||||
autoload :TemplateRenderer, 'flowerbox/delivery/template_renderer'
|
||||
autoload :SprocketsHandler, 'flowerbox/delivery/sprockets_handler'
|
||||
autoload :UniqueAssetList, 'flowerbox/delivery/unique_asset_list'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -7,11 +7,11 @@ module Flowerbox::Delivery
|
||||
def initialize(options)
|
||||
@options = options
|
||||
|
||||
@files = []
|
||||
@files = UniqueAssetList.new
|
||||
end
|
||||
|
||||
def add(asset)
|
||||
@files += paths_for(asset)
|
||||
@files.add(paths_for(asset))
|
||||
end
|
||||
|
||||
def paths_for(asset)
|
||||
|
13
lib/flowerbox/delivery/unique_asset_list.rb
Normal file
13
lib/flowerbox/delivery/unique_asset_list.rb
Normal file
@ -0,0 +1,13 @@
|
||||
module Flowerbox::Delivery
|
||||
class UniqueAssetList < ::Array
|
||||
def add(files)
|
||||
files.each { |file| self << file if !include?(file) }
|
||||
end
|
||||
|
||||
private
|
||||
def include?(file)
|
||||
any? { |other_file| other_file == file }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
17
spec/flowerbox/delivery/unique_asset_list_spec.rb
Normal file
17
spec/flowerbox/delivery/unique_asset_list_spec.rb
Normal file
@ -0,0 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Flowerbox::Delivery::UniqueAssetList do
|
||||
let(:unique_asset_list) { described_class.new }
|
||||
|
||||
describe "#add" do
|
||||
let(:first) { Pathname.new('one') }
|
||||
let(:second) { Pathname.new('one') }
|
||||
let(:third) { Pathname.new('two') }
|
||||
|
||||
it 'should not add assets already added' do
|
||||
unique_asset_list.add([ first, second, third ])
|
||||
|
||||
unique_asset_list.should == [ first, third ]
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user