Search in sources :

Example 6 with BidiGlobalDir

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;
}
Also used : SanitizedContent(com.google.template.soy.data.SanitizedContent) BidiGlobalDir(com.google.template.soy.internal.i18n.BidiGlobalDir) Dir(com.google.template.soy.data.Dir)

Example 7 with BidiGlobalDir

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);
}
Also used : SanitizedContent(com.google.template.soy.data.SanitizedContent) BidiFormatter(com.google.template.soy.internal.i18n.BidiFormatter) BidiGlobalDir(com.google.template.soy.internal.i18n.BidiGlobalDir) Dir(com.google.template.soy.data.Dir)

Example 8 with BidiGlobalDir

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);
    }
}
Also used : BidiGlobalDir(com.google.template.soy.internal.i18n.BidiGlobalDir) GuiceSimpleScope(com.google.template.soy.shared.internal.GuiceSimpleScope) SoyJsSrcOptions(com.google.template.soy.jssrc.SoyJsSrcOptions) CombineConsecutiveRawTextNodesPass(com.google.template.soy.passes.CombineConsecutiveRawTextNodesPass)

Aggregations

BidiGlobalDir (com.google.template.soy.internal.i18n.BidiGlobalDir)8 Dir (com.google.template.soy.data.Dir)4 SanitizedContent (com.google.template.soy.data.SanitizedContent)4 BidiFormatter (com.google.template.soy.internal.i18n.BidiFormatter)3 GuiceSimpleScope (com.google.template.soy.shared.internal.GuiceSimpleScope)3 SoyString (com.google.template.soy.data.restricted.SoyString)2 CombineConsecutiveRawTextNodesPass (com.google.template.soy.passes.CombineConsecutiveRawTextNodesPass)2 BasicDirectivesModule (com.google.template.soy.basicdirectives.BasicDirectivesModule)1 BasicFunctionsModule (com.google.template.soy.basicfunctions.BasicFunctionsModule)1 BidiDirectivesModule (com.google.template.soy.bididirectives.BidiDirectivesModule)1 BidiFunctionsModule (com.google.template.soy.bidifunctions.BidiFunctionsModule)1 CoreDirectivesModule (com.google.template.soy.coredirectives.CoreDirectivesModule)1 ContentKind (com.google.template.soy.data.SanitizedContent.ContentKind)1 I18nDirectivesModule (com.google.template.soy.i18ndirectives.I18nDirectivesModule)1 SoyJsSrcOptions (com.google.template.soy.jssrc.SoyJsSrcOptions)1 InsertMsgsVisitor (com.google.template.soy.msgs.internal.InsertMsgsVisitor)1 ApiCall (com.google.template.soy.shared.restricted.ApiCallScopeBindingAnnotations.ApiCall)1 LocaleString (com.google.template.soy.shared.restricted.ApiCallScopeBindingAnnotations.LocaleString)1