本文整理汇总了Java中com.google.template.soy.jssrc.restricted.JsExpr类的典型用法代码示例。如果您正苦于以下问题:Java JsExpr类的具体用法?Java JsExpr怎么用?Java JsExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsExpr类属于com.google.template.soy.jssrc.restricted包,在下文中一共展示了JsExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Override
public JsExpr applyForJsSrc(JsExpr value, List<JsExpr> args) {
String numberFormatType = parseFormat(args);
StringBuilder expr = new StringBuilder();
expr.append("(new goog.i18n.NumberFormat(" + JS_ARGS_TO_ENUM.get(numberFormatType) + "))");
// If min and max fractional digits were specified, apply those. If only one value was
// specified, use as both min and max. If no values were specified, apply default significant
// digits for compact short and long numbers.
if (args.size() > 2) {
String minFractionDigits = args.get(2).getText();
String maxFractionDigits = args.size() > 3 ? args.get(3).getText() : minFractionDigits;
expr.append(".setMinimumFractionDigits(").append(minFractionDigits).append(")");
expr.append(".setMaximumFractionDigits(").append(maxFractionDigits).append(")");
} else if ("'compact_short'".equals(numberFormatType)
|| "'compact_long'".equals(numberFormatType)) {
expr.append(".setSignificantDigits(3)"); // Note that this trims trailing zeros.
}
expr.append(".format(" + value.getText() + ")");
return new JsExpr(expr.toString(), Integer.MAX_VALUE);
}
示例2: computeForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
return new JsExpr(
"goog.array.range("
+ Joiner.on(", ")
.join(
Iterables.transform(
args,
new Function<JsExpr, String>() {
@Override
public String apply(JsExpr input) {
return input.getText();
}
}))
+ ")",
Integer.MAX_VALUE);
}
示例3: testApplyForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Test
public void testApplyForJsSrc() {
JsExpr dataRef = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
assertThat(
BIDI_UNICODE_WRAP_DIRECTIVE_FOR_STATIC_LTR
.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of())
.getText())
.isEqualTo("soy.$$bidiUnicodeWrap(1, opt_data.myKey)");
assertThat(
BIDI_UNICODE_WRAP_DIRECTIVE_FOR_STATIC_RTL
.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of())
.getText())
.isEqualTo("soy.$$bidiUnicodeWrap(-1, opt_data.myKey)");
BidiUnicodeWrapDirective codeSnippet =
new BidiUnicodeWrapDirective(
SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_JS_ISRTL_CODE_SNIPPET_PROVIDER);
assertThat(codeSnippet.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText())
.isEqualTo("soy.$$bidiUnicodeWrap(IS_RTL?-1:1, opt_data.myKey)");
}
示例4: getUnknownFunction
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
private static SoyJsSrcFunction getUnknownFunction(final String name, final int argSize) {
return new SoyJsSrcFunction() {
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
List<String> argStrings = new ArrayList<>();
for (JsExpr arg : args) {
argStrings.add(arg.getText());
}
return new JsExpr(name + "(" + COMMA_JOINER.join(argStrings) + ")", Integer.MAX_VALUE);
}
@Override
public String getName() {
return name;
}
@Override
public Set<Integer> getValidArgsSizes() {
return ImmutableSet.of(argSize);
}
};
}
示例5: testApplyForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Test
public void testApplyForJsSrc() {
TruncateDirective truncateDirective = new TruncateDirective();
JsExpr dataRefJsExpr = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
JsExpr maxLenJsExpr = new JsExpr("8", Integer.MAX_VALUE);
JsExpr trueJsExpr = new JsExpr("true", Integer.MAX_VALUE);
JsExpr falseJsExpr = new JsExpr("false", Integer.MAX_VALUE);
assertThat(
truncateDirective
.applyForJsSrc(dataRefJsExpr, ImmutableList.of(maxLenJsExpr))
.getText())
.isEqualTo("soy.$$truncate(opt_data.myKey, 8, true)");
assertThat(
truncateDirective
.applyForJsSrc(dataRefJsExpr, ImmutableList.of(maxLenJsExpr, trueJsExpr))
.getText())
.isEqualTo("soy.$$truncate(opt_data.myKey, 8, true)");
assertThat(
truncateDirective
.applyForJsSrc(dataRefJsExpr, ImmutableList.of(maxLenJsExpr, falseJsExpr))
.getText())
.isEqualTo("soy.$$truncate(opt_data.myKey, 8, false)");
}
示例6: testComputeForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Test
public void testComputeForJsSrc() {
BidiDirAttrFunction codeSnippet =
new BidiDirAttrFunction(
SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_JS_ISRTL_CODE_SNIPPET_PROVIDER);
JsExpr textExpr = new JsExpr("TEXT_JS_CODE", Integer.MAX_VALUE);
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_LTR.computeForJsSrc(ImmutableList.of(textExpr)))
.isEqualTo(new JsExpr("soy.$$bidiDirAttr(1, TEXT_JS_CODE)", Integer.MAX_VALUE));
assertThat(codeSnippet.computeForJsSrc(ImmutableList.of(textExpr)))
.isEqualTo(new JsExpr("soy.$$bidiDirAttr(IS_RTL?-1:1, TEXT_JS_CODE)", Integer.MAX_VALUE));
JsExpr isHtmlExpr = new JsExpr("IS_HTML_JS_CODE", Integer.MAX_VALUE);
assertThat(
BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_RTL.computeForJsSrc(
ImmutableList.of(textExpr, isHtmlExpr)))
.isEqualTo(
new JsExpr("soy.$$bidiDirAttr(-1, TEXT_JS_CODE, IS_HTML_JS_CODE)", Integer.MAX_VALUE));
assertThat(codeSnippet.computeForJsSrc(ImmutableList.of(textExpr, isHtmlExpr)))
.isEqualTo(
new JsExpr(
"soy.$$bidiDirAttr(IS_RTL?-1:1, TEXT_JS_CODE, IS_HTML_JS_CODE)",
Integer.MAX_VALUE));
}
示例7: testMsgHtmlTag
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Test
public void testMsgHtmlTag() {
assertGeneratedJsExprs(JOINER.join(
"{@param url : ?}",
"{msg desc=\"\"}<a href=\"{$url}\">Click here</a>{/msg}"),
ImmutableList.of(
new JsExpr("'<a href=\"'", Integer.MAX_VALUE),
new JsExpr("opt_data.url", Integer.MAX_VALUE),
new JsExpr("'\">'", Integer.MAX_VALUE)),
0,
0,
0,
0);
assertGeneratedJsExprs(
"{@param url : ?}\n" + "{msg desc=\"\"}<a href=\"{$url}\">Click here</a>{/msg}",
ImmutableList.of(new JsExpr("'</a>'", Integer.MAX_VALUE)),
0,
0,
0,
2);
}
示例8: assertGeneratedJsExprs
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
/** @param indicesToNode Series of indices for walking down to the node we want to test. */
private static void assertGeneratedJsExprs(
String soyCode, List<JsExpr> expectedJsExprs, int... indicesToNode) {
List<CodeChunk.WithValue> actualChunks = generateChunks(soyCode, indicesToNode);
List<JsExpr> actualJsExprs = new ArrayList<>();
for (CodeChunk.WithValue chunk : actualChunks) {
actualJsExprs.add(chunk.assertExpr()); // TODO(user): Fix tests to work with CodeChunks
}
assertThat(actualJsExprs).hasSize(expectedJsExprs.size());
for (int i = 0; i < expectedJsExprs.size(); i++) {
JsExpr expectedJsExpr = expectedJsExprs.get(i);
JsExpr actualJsExpr = actualJsExprs.get(i);
assertThat(actualJsExpr.getText()).isEqualTo(expectedJsExpr.getText());
assertThat(actualJsExpr.getPrecedence()).isEqualTo(expectedJsExpr.getPrecedence());
}
}
示例9: computeForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
JsExpr value = args.get(0);
JsExpr isHtml = (args.size() == 2) ? args.get(1) : null;
String callText =
"soy.$$bidiMarkAfter("
+ bidiGlobalDirProvider.get().getCodeSnippet()
+ ", "
+ value.getText()
+ (isHtml != null ? ", " + isHtml.getText() : "")
+ ")";
return new JsExpr(callText, Integer.MAX_VALUE);
}
示例10: computeForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
JsExpr value = args.get(0);
JsExpr isHtml = (args.size() == 2) ? args.get(1) : null;
String callText =
(isHtml != null)
? "soy.$$bidiTextDir(" + value.getText() + ", " + isHtml.getText() + ")"
: "soy.$$bidiTextDir(" + value.getText() + ")";
return new JsExpr(callText, Integer.MAX_VALUE);
}
示例11: computeForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
BidiGlobalDir bidiGlobalDir = bidiGlobalDirProvider.get();
if (bidiGlobalDir.isStaticValue()) {
return new JsExpr(
(bidiGlobalDir.getStaticValue() < 0) ? "'left'" : "'right'", Integer.MAX_VALUE);
}
return new JsExpr(
"(" + bidiGlobalDir.getCodeSnippet() + ") < 0 ? 'left' : 'right'",
Operator.CONDITIONAL.getPrecedence());
}
示例12: computeForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
BidiGlobalDir bidiGlobalDir = bidiGlobalDirProvider.get();
return new JsExpr(
bidiGlobalDir.getCodeSnippet(),
bidiGlobalDir.isStaticValue() ? Integer.MAX_VALUE : Operator.CONDITIONAL.getPrecedence());
}
示例13: computeForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
BidiGlobalDir bidiGlobalDir = bidiGlobalDirProvider.get();
if (bidiGlobalDir.isStaticValue()) {
return new JsExpr(
(bidiGlobalDir.getStaticValue() < 0) ? "'right'" : "'left'", Integer.MAX_VALUE);
}
return new JsExpr(
"(" + bidiGlobalDir.getCodeSnippet() + ") < 0 ? 'right' : 'left'",
Operator.CONDITIONAL.getPrecedence());
}
示例14: computeForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@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);
}
示例15: computeForJsSrc
import com.google.template.soy.jssrc.restricted.JsExpr; //导入依赖的package包/类
@Override
public JsExpr computeForJsSrc(List<JsExpr> args) {
BidiGlobalDir bidiGlobalDir = bidiGlobalDirProvider.get();
if (bidiGlobalDir.isStaticValue()) {
return new JsExpr(
(bidiGlobalDir.getStaticValue() < 0) ? "'\\u200F'" /*RLM*/ : "'\\u200E'" /*LRM*/,
Integer.MAX_VALUE);
}
return new JsExpr(
"(" + bidiGlobalDir.getCodeSnippet() + ") < 0 ? '\\u200F' : '\\u200E'",
Operator.CONDITIONAL.getPrecedence());
}