From b8ebb719137789825fa03c4a9a3b82c87d3970fe Mon Sep 17 00:00:00 2001 From: Andrew Hao Date: Sun, 3 Mar 2013 10:37:48 -0800 Subject: [PATCH 1/2] Adding Jammit::Packager#asset_defined? public method to allow callers to determine whether an asset can be expected in Jammit. --- lib/jammit/packager.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/jammit/packager.rb b/lib/jammit/packager.rb index 26cc7313..5ba9f5fc 100644 --- a/lib/jammit/packager.rb +++ b/lib/jammit/packager.rb @@ -70,6 +70,12 @@ def individual_urls(package, extension) package_for(package, extension)[:urls] end + def asset_defined?(package, extension) + !!package_for(package, extension) + rescue PackageNotFound + false + end + def compressor @compressor ||= Compressor.new end From 218580229eae93e03c1dc87b2a2903caf5ba3f75 Mon Sep 17 00:00:00 2001 From: Andrew Hao Date: Mon, 4 Mar 2013 09:20:06 -0800 Subject: [PATCH 2/2] Renaming method to Jammit::Packager#includes? to be more concise. Added tests. Coerce inputs to symbols. --- lib/jammit/packager.rb | 5 +++-- test/unit/test_packager.rb | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/jammit/packager.rb b/lib/jammit/packager.rb index 5ba9f5fc..aed355de 100644 --- a/lib/jammit/packager.rb +++ b/lib/jammit/packager.rb @@ -70,8 +70,9 @@ def individual_urls(package, extension) package_for(package, extension)[:urls] end - def asset_defined?(package, extension) - !!package_for(package, extension) + # 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 diff --git a/test/unit/test_packager.rb b/test/unit/test_packager.rb index 38743ba6..a7288c15 100644 --- a/test/unit/test_packager.rb +++ b/test/unit/test_packager.rb @@ -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') @@ -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