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

Adding Jammit::Packager#includes? to detect existence of compiled assets. #246

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/jammit/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ def individual_urls(package, extension)
package_for(package, extension)[:urls]
end

# Determines the existence of a packaged asset in the assets.yml file.
def includes?(package, extension)
!!package_for(package.to_sym, extension.to_sym)
rescue PackageNotFound
false
end

def compressor
@compressor ||= Compressor.new
end
Expand Down
14 changes: 13 additions & 1 deletion test/unit/test_packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ def test_fetching_lists_of_nested_urls
assert urls == ['/assets/jst_test_nested.jst']
end

def test_package_includes
assert Jammit.packager.includes?(:css_test, :css)
assert Jammit.packager.includes?("css_test_nested", "css")
assert Jammit.packager.includes?(:js_test, :js)
assert Jammit.packager.includes?("js_test_nested", "js")
assert Jammit.packager.includes?(:jst_test, :js)
assert Jammit.packager.includes?("jst_test_nested", "js")

assert !Jammit.packager.includes?(:not_included_file, :js)
assert !Jammit.packager.includes?(:test1, :css)
assert !Jammit.packager.includes?(:"nested/nested1", :js)
end

def test_packaging_stylesheets
css = Jammit.packager.pack_stylesheets(:css_test)
assert css == File.read('test/fixtures/jammed/css_test.css')
Expand Down Expand Up @@ -129,5 +142,4 @@ def test_packaging_javascripts_with_package_names
assert File.read('test/public/assets/js_test.js') == File.read('test/fixtures/jammed/js_test_package_names.js')
FileUtils.rm_rf("test/public/assets")
end

end