Search in sources :

Example 56 with JsExpr

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));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 57 with JsExpr

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");
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 58 with JsExpr

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);
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) SoyString(com.google.template.soy.data.restricted.SoyString)

Example 59 with JsExpr

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);
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr)

Example 60 with JsExpr

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);
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr)

Aggregations

JsExpr (com.google.template.soy.jssrc.restricted.JsExpr)64 Test (org.junit.Test)42 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)3 ImmutableList (com.google.common.collect.ImmutableList)2 RequiresCollector (com.google.template.soy.jssrc.dsl.CodeChunk.RequiresCollector)2 SoyLibraryAssistedJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyLibraryAssistedJsSrcPrintDirective)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 SanitizedContent (com.google.template.soy.data.SanitizedContent)1 ContentKind (com.google.template.soy.data.SanitizedContent.ContentKind)1 SoyValue (com.google.template.soy.data.SoyValue)1 UnsafeSanitizedContentOrdainer (com.google.template.soy.data.UnsafeSanitizedContentOrdainer)1 SoyString (com.google.template.soy.data.restricted.SoyString)1 StringData (com.google.template.soy.data.restricted.StringData)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 StringNode (com.google.template.soy.exprtree.StringNode)1 WithValue (com.google.template.soy.jssrc.dsl.CodeChunk.WithValue)1 SoyJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyJsSrcPrintDirective)1