private void renderAMD(Iterable<Asset> modules, Stream stream) { StringBuilder buffer = new StringBuilder(); buffer.append("<script type=\"text/javascript\">"); buffer.append(" var require={"); buffer.append("\"paths\":{"); for (Iterator<Asset> i = modules.iterator(); i.hasNext();) { Asset module = i.next(); buffer.append("\"").append(module.getId()).append("\":\""); String uri = module.resolveURI(minifyAssets); uri = uri.substring(0, uri.lastIndexOf(".js")); buffer.append(renderAssetURL(module.getLocation(), uri)); buffer.append("\""); if (i.hasNext()) { buffer.append(","); } } buffer.append("}"); buffer.append("};"); buffer.append("</script>"); stream.provide(Chunk.create(buffer)); } }
private void renderAMD(Iterable<Asset> modules, Stream stream) { StringBuilder buffer = new StringBuilder(); buffer.append("<script type=\"text/javascript\">"); buffer.append(" var require={"); buffer.append("\"paths\":{"); for (Iterator<Asset> i = modules.iterator(); i.hasNext();) { Asset module = i.next(); buffer.append("\"").append(module.getId()).append("\":\""); String uri = module.resolveURI(minifyAssets); uri = uri.substring(0, uri.lastIndexOf(".js")); buffer.append(renderAssetURL(module.getLocation(), uri)); buffer.append("\""); if (i.hasNext()) { buffer.append(","); } } buffer.append("}"); buffer.append("};"); buffer.append("</script>"); stream.provide(Chunk.create(buffer)); } }
@Test public void testUndeploy() { AssetManager mgr = new AssetManager("", ResourceResolver.NULL_RESOLVER); AssetDeployment fooDepl = mgr.createDeployment(); fooDepl.addAsset("foo", "script", AssetLocation.APPLICATION, "foo.js", null, null, null, DUMMY_URL, "bar"); fooDepl.deploy(); AssetDeployment barDepl = mgr.createDeployment(); barDepl.addAsset("bar", "script", AssetLocation.APPLICATION, "bar.js", null, null, null, DUMMY_URL); barDepl.deploy(); List<Asset> asset = Tools.list(mgr.resolveAssets(Collections.singletonList("foo"))); assertEquals(2, asset.size()); assertEquals("bar", asset.get(0).getId()); assertEquals("foo", asset.get(1).getId()); barDepl.undeploy(); try { mgr.resolveAssets(Collections.singletonList("foo")); fail(); } catch (IllegalArgumentException expected) { } } }
@Test public void testUndeploy() { AssetManager mgr = new AssetManager("", ResourceResolver.NULL_RESOLVER); AssetDeployment fooDepl = mgr.createDeployment(); fooDepl.addAsset("foo", "script", AssetLocation.APPLICATION, "foo.js", null, null, null, DUMMY_URL, "bar"); fooDepl.deploy(); AssetDeployment barDepl = mgr.createDeployment(); barDepl.addAsset("bar", "script", AssetLocation.APPLICATION, "bar.js", null, null, null, DUMMY_URL); barDepl.deploy(); List<Asset> asset = Tools.list(mgr.resolveAssets(Collections.singletonList("foo"))); assertEquals(2, asset.size()); assertEquals("bar", asset.get(0).getId()); assertEquals("foo", asset.get(1).getId()); barDepl.undeploy(); try { mgr.resolveAssets(Collections.singletonList("foo")); fail(); } catch (IllegalArgumentException expected) { } } }