Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom assets into the manifest #481

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -92,6 +92,17 @@ def assets
@data['assets'] ||= {}
end

# Allows to add custom assets which are compiled from
# sources outside the asset pipeline.
#
# Logical path (String): Fingerprinted path (String)
#
# { "app.js" => "app.2e8e97c6.js",
# "vendor.js" => "vendor.ae090855.js" }
def add_assets(custom_assets)
@data['assets'] = assets.merge(custom_assets)
end

# Returns internal file directory listing. Keys are filenames
# which map to an attributes array.
#
@@ -483,6 +483,32 @@ def teardown
assert data['assets']['application.js']
end

test 'allow custom assets' do
manifest = Sprockets::Manifest.new(@env, File.join(@dir, 'manifest.json'))
custom_assets = {'app.js' => 'app.2e8e97c6.js', 'vendor.js' => 'vendor.ae090855.js'}

digest_path = @env['application.js'].digest_path

assert !File.exist?("#{@dir}/#{digest_path}")
manifest.compile('application.js')
manifest.add_assets(custom_assets)
manifest.save

assert File.directory?(manifest.directory)
assert File.file?(manifest.filename)

assert File.exist?("#{@dir}/manifest.json")
assert File.exist?("#{@dir}/#{digest_path}")

data = JSON.parse(File.read(manifest.filename))
assert data['files'][digest_path]
assert_equal 'application.js', data['files'][digest_path]['logical_path']
assert data['files'][digest_path]['size'] > 230
assert_equal digest_path, data['assets']['application.js']
assert_equal custom_assets['app.js'], data['assets']['app.js']
assert_equal custom_assets['vendor.js'], data['assets']['vendor.js']
end

test "nil environment raises compilation error" do
assert !File.exist?("#{@dir}/manifest.json")

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.