use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class BidiMarkAfterFunctionTest method testComputeForJsSrc.
@Test
public void testComputeForJsSrc() {
BidiMarkAfterFunction codeSnippet = new BidiMarkAfterFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_JS_ISRTL_CODE_SNIPPET_PROVIDER);
JsExpr textExpr = new JsExpr("TEXT_JS_CODE", Integer.MAX_VALUE);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJsSrc(ImmutableList.of(textExpr))).isEqualTo(new JsExpr("soy.$$bidiMarkAfter(1, TEXT_JS_CODE)", Integer.MAX_VALUE));
assertThat(codeSnippet.computeForJsSrc(ImmutableList.of(textExpr))).isEqualTo(new JsExpr("soy.$$bidiMarkAfter(IS_RTL?-1:1, TEXT_JS_CODE)", Integer.MAX_VALUE));
JsExpr isHtmlExpr = new JsExpr("IS_HTML_JS_CODE", Integer.MAX_VALUE);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJsSrc(ImmutableList.of(textExpr, isHtmlExpr))).isEqualTo(new JsExpr("soy.$$bidiMarkAfter(-1, TEXT_JS_CODE, IS_HTML_JS_CODE)", Integer.MAX_VALUE));
assertThat(codeSnippet.computeForJsSrc(ImmutableList.of(textExpr, isHtmlExpr))).isEqualTo(new JsExpr("soy.$$bidiMarkAfter(IS_RTL?-1:1, TEXT_JS_CODE, IS_HTML_JS_CODE)", Integer.MAX_VALUE));
}
use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class IdDirectiveTest method testApplyForJsSrc.
@Test
public void testApplyForJsSrc() {
IdDirective idDirective = new IdDirective();
JsExpr dataRef = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
assertThat(idDirective.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText()).isEqualTo("opt_data.myKey");
}
use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class StrIndexOfFunction method computeForJsSrc.
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
// Coerce SanitizedContent args to strings.
String arg0 = JsExprUtils.toString(args.get(0)).getText();
String arg1 = JsExprUtils.toString(args.get(1)).getText();
return new JsExpr("(" + arg0 + ").indexOf(" + arg1 + ")", Integer.MAX_VALUE);
}
use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class BidiDirAttrFunction method computeForJsSrc.
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
JsExpr value = args.get(0);
JsExpr isHtml = (args.size() == 2) ? args.get(1) : null;
String callText = "soy.$$bidiDirAttr(" + bidiGlobalDirProvider.get().getCodeSnippet() + ", " + value.getText() + (isHtml != null ? ", " + isHtml.getText() : "") + ")";
return new JsExpr(callText, Integer.MAX_VALUE);
}
use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class LengthFunction method computeForJsSrc.
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
JsExpr arg = args.get(0);
String exprText = arg.getPrecedence() == Integer.MAX_VALUE ? arg.getText() + ".length" : "(" + arg.getText() + ").length";
return new JsExpr(exprText, Integer.MAX_VALUE);
}
Aggregations