use of com.google.template.soy.internal.i18n.BidiGlobalDir in project closure-templates by google.
the class BidiFunctionsRuntime method bidiMarkAfter.
public static String bidiMarkAfter(BidiGlobalDir bidiGlobalDir, SoyValue value, boolean isHtml) {
Dir valueDir = null;
if (value instanceof SanitizedContent) {
SanitizedContent sanitizedContent = (SanitizedContent) value;
valueDir = sanitizedContent.getContentDirection();
isHtml = isHtml || sanitizedContent.getContentKind() == ContentKind.HTML;
}
String markAfterKnownDir = BidiFormatter.getInstance(bidiGlobalDir.toDir()).markAfter(valueDir, value.coerceToString(), isHtml);
return markAfterKnownDir;
}
use of com.google.template.soy.internal.i18n.BidiGlobalDir in project closure-templates by google.
the class BidiFunctionsRuntime method bidiDirAttr.
public static String bidiDirAttr(BidiGlobalDir dir, SoyValue value, boolean isHtml) {
Dir valueDir = null;
boolean isHtmlForValueDirEstimation = false;
if (value instanceof SanitizedContent) {
SanitizedContent sanitizedContent = (SanitizedContent) value;
valueDir = sanitizedContent.getContentDirection();
if (valueDir == null) {
isHtmlForValueDirEstimation = sanitizedContent.getContentKind() == ContentKind.HTML;
}
}
if (valueDir == null) {
isHtmlForValueDirEstimation = isHtmlForValueDirEstimation || isHtml;
valueDir = BidiUtils.estimateDirection(value.coerceToString(), isHtmlForValueDirEstimation);
}
BidiFormatter bidiFormatter = BidiFormatter.getInstance(dir.toDir());
return bidiFormatter.knownDirAttr(valueDir);
}
use of com.google.template.soy.internal.i18n.BidiGlobalDir in project closure-templates by google.
the class IncrementalDomSrcMain method genJsSrc.
/**
* Generates Incremental DOM JS source code given a Soy parse tree, an options object, and an
* optional bundle of translated messages.
*
* @param soyTree The Soy parse tree to generate JS source code for.
* @param registry The template registry that contains all the template information.
* @param options The compilation options relevant to this backend.
* @param errorReporter The Soy error reporter that collects errors during code generation.
* @return A list of strings where each string represents the JS source code that belongs in one
* JS file. The generated JS files correspond one-to-one to the original Soy source files.
*/
public List<String> genJsSrc(SoyFileSetNode soyTree, TemplateRegistry registry, SoyIncrementalDomSrcOptions options, ErrorReporter errorReporter) {
SoyJsSrcOptions incrementalJSSrcOptions = options.toJsSrcOptions();
try (GuiceSimpleScope.InScope inScope = apiCallScope.enter()) {
// Seed the scoped parameters.
BidiGlobalDir bidiGlobalDir = SoyBidiUtils.decodeBidiGlobalDirFromJsOptions(incrementalJSSrcOptions.getBidiGlobalDir(), incrementalJSSrcOptions.getUseGoogIsRtlForBidiGlobalDir());
ApiCallScopeUtils.seedSharedParams(inScope, null, /* msgBundle */
bidiGlobalDir);
// Do the code generation.
new HtmlContextVisitor(errorReporter).exec(soyTree);
// Return an empty list here, {@code SoyFileSet} will throw an exception.
if (errorReporter.hasErrors()) {
return Collections.emptyList();
}
new UnescapingVisitor().exec(soyTree);
new RemoveUnnecessaryEscapingDirectives().run(soyTree);
// some of the above passes may slice up raw text nodes, recombine them.
new CombineConsecutiveRawTextNodesPass().run(soyTree);
return createVisitor(incrementalJSSrcOptions, typeRegistry).gen(soyTree, registry, errorReporter);
}
}
Aggregations