/** * Prepends JS to the output. */ public JsResponseBuilder prependJs(String content, String name) { return prependJs(JsContent.fromText(content, name)); }
/** * Prepends JS to the output. */ public JsResponseBuilder prependJs(String content, String name, boolean noCompile) { return prependJs(JsContent.fromText(content, name, noCompile)); }
protected void injectBaseConfig(String configJson, JsResponseBuilder builder) { builder.prependJs(String.format(CONFIG_INJECT_CODE, configJson), CONFIG_INIT_ID); builder.appendJs(String.format(CONFIG_INIT_TPL, configJson), CONFIG_INIT_ID); }
public boolean process(JsRequest jsRequest, JsResponseBuilder builder) { JsUri jsUri = jsRequest.getJsUri(); if (!jsUri.isNohint()) { String features = getFeatures(jsUri); builder.prependJs(String.format(FEATURES_HINT_TEMPLATE, features), CODE_ID, true); builder.prependJs(BASE_HINT_TEMPLATE, CODE_ID); } return true; }
public boolean process(JsRequest jsRequest, JsResponseBuilder builder) throws JsException { if (jsRequest.getJsUri().getCompileMode() != JsCompileMode.COMPILE_CONCAT) { builder.prependJs("(function(){", "[js-anon-wrapper]"); builder.appendJs("})();", "[js-anon-wrapper]"); } return true; } }
@Test public void skipsEmptyContent() throws Exception { builder.appendJs("number 1", "num1"); builder.appendJs("", "num2"); builder.appendJs("number 3", "num3"); builder.prependJs("number 4", "num4"); builder.prependJs("", "num5"); Iterator<JsContent> allJsContent = builder.build().getAllJsContent().iterator(); assertEquals("num4", allJsContent.next().getSource()); assertEquals("num1", allJsContent.next().getSource()); assertEquals("num3", allJsContent.next().getSource()); assertFalse(allJsContent.hasNext()); } }
@Test public void skipsEmptyContent() throws Exception { builder.appendJs("number 1", "num1"); builder.appendJs("", "num2"); builder.appendJs("number 3", "num3"); builder.prependJs("number 4", "num4"); builder.prependJs("", "num5"); Iterator<JsContent> allJsContent = builder.build().getAllJsContent().iterator(); assertEquals("num4", allJsContent.next().getSource()); assertEquals("num1", allJsContent.next().getSource()); assertEquals("num3", allJsContent.next().getSource()); assertFalse(allJsContent.hasNext()); } }