/** * * @param engine * @return a new decorator instance * @throws IllegalStateException * If {@link ReflectionResolver} is not available */ public Decorator<T> build(MustacheEngine engine) { return build(engine.getConfiguration()); }
@Override public void engineBuilt(MustacheEngine engine) { this.localeSupport = engine.getConfiguration().getLocaleSupport(); }
DefaultValuePlaceholder(String name, MustacheEngine engine) { this.name = name; this.provider = new ValueProvider(name, engine.getConfiguration()); }
@Override public void engineBuilt(MustacheEngine engine) { minifier.init(engine.getConfiguration()); }
private void renderingFinished(MustacheRenderingEvent event) { List<MustacheListener> listeners = engine.getConfiguration() .getMustacheListeners(); if (listeners.isEmpty()) { return; } for (ListIterator<MustacheListener> iterator = listeners .listIterator(listeners.size()); iterator.hasPrevious();) { iterator.previous().renderingFinished(event); } }
protected Configuration getEngineConfiguration() { return getEngine().getConfiguration(); }
@Override public void startTemplate(String name, Delimiters delimiters, MustacheEngine engine) { this.delimiters = delimiters; this.engine = engine; this.templateName = name; containerStack.addFirst(new RootSegmentBase()); skipValueEscaping = engine.getConfiguration().getBooleanPropertyValue( EngineConfigurationKey.SKIP_VALUE_ESCAPING); handlebarsSupportEnabled = engine.getConfiguration() .getBooleanPropertyValue( EngineConfigurationKey.HANDLEBARS_SUPPORT_ENABLED); start = System.currentTimeMillis(); LOGGER.debug("Start compilation of {}", new Object[] { name }); }
private void renderingStarted(MustacheRenderingEvent event) { List<MustacheListener> listeners = engine.getConfiguration() .getMustacheListeners(); if (listeners.isEmpty()) { return; } for (MustacheListener listener : listeners) { listener.renderingStarted(event); } }
/** * * @param engine */ public DefaultParser(MustacheEngine engine) { this.state = State.TEXT; this.line = 1; this.delimiterIdx = 0; this.triple = false; this.buffer = new StringBuilder(); this.separatorIdx = 0; this.engine = engine; this.delimiters = new Delimiters(engine.getConfiguration() .getStringPropertyValue(START_DELIMITER), engine .getConfiguration().getStringPropertyValue(END_DELIMITER)); this.supportedSeparators = ImmutableSet.of(Strings.LINE_SEPARATOR_LF, Strings.LINE_SEPARATOR_CR, Strings.LINE_SEPARATOR_CRLF); this.zeroIndexNonSeparatorCharacters = new HashSet<>(); }
/** * * @param segment * @return the name for one-off lambda, e.g. "oneoff_lambda_10_4242" * @see Lambda#isReturnValueInterpolated() */ public static String constructLambdaOneoffTemplateName(Segment segment) { final Template template = segment.getOrigin().getTemplate(); return new StringBuilder() .append(Lambda.ONEOFF_LAMBDA_TEMPLATE_PREFIX) .append(template.getGeneratedId()) .append("_") .append(template.getEngine().getConfiguration() .getIdentifierGenerator().generate(null)) .toString(); } }
/** * * @param generatedId * @param name * @param engine * @param nestedTemplates */ public Template(Long generatedId, String name, MustacheEngine engine, List<Template> nestedTemplates) { this.generatedId = generatedId; this.name = name; this.engine = engine; this.globalExecutionContext = ExecutionContexts .newGlobalExecutionContext(engine.getConfiguration()); if (nestedTemplates == null || nestedTemplates.isEmpty()) { this.nestedTemplates = Collections.emptyMap(); } else { ImmutableMapBuilder<String, Template> builder = ImmutableMap .builder(); for (Template template : nestedTemplates) { builder.put(template.getName(), template); } this.nestedTemplates = builder.build(); } }
/** * Builds the engine instance. * * @return the built engine */ public synchronized MustacheEngine build() { MustacheEngine engine = new DefaultMustacheEngine(this); for (EngineBuiltCallback callback : engineReadyCallbacks) { callback.engineBuilt(engine); } BuildInfo buildInfo = BuildInfo.load(); LOGGER.info("Engine built {} ({})", buildInfo.getVersion(), buildInfo.getTimestampDate()); LOGGER.debug("Engine configuration: {}", engine.getConfiguration().getInfo()); isBuilt = true; return engine; }
@Override public void endTemplate() { RootSegmentBase rootSegmentBase = validate(); // Post processing if (engine.getConfiguration() .getBooleanPropertyValue(REMOVE_STANDALONE_LINES)) { SegmentBases.removeStandaloneLines(rootSegmentBase); } if (engine.getConfiguration() .getBooleanPropertyValue(REMOVE_UNNECESSARY_SEGMENTS)) { SegmentBases.removeUnnecessarySegments(rootSegmentBase); } if (engine.getConfiguration() .getBooleanPropertyValue(REUSE_LINE_SEPARATOR_SEGMENTS)) { SegmentBases.reuseLineSeparatorSegments(rootSegmentBase); } template = new Template(engine.getConfiguration() .getIdentifierGenerator().generate(Mustache.class), templateName, engine, nestedTemplates); template.initRootSegment(rootSegmentBase.asSegment(template)); for (Template nested : nestedTemplates) { nested.initParent(template); } LOGGER.debug("Compilation of {} finished [time: {} ms, segments: {}]", templateName, System.currentTimeMillis() - start, template.getRootSegment().getSegmentsSize(true)); nestedTemplates.clear(); containerStack.clear(); }
Template nested = new Template(engine.getConfiguration() .getIdentifierGenerator().generate(Mustache.class), container.getContent(), engine);
@Override public void executeAsync(final HelperExecutable executable) { // For async execution we need to wrap the original appendable final AsyncAppendable asyncAppendable = new AsyncAppendable( appendable); // Now submit the executable and get the future ExecutorService executor = engine.getConfiguration() .geExecutorService(); if (executor == null) { throw new MustacheException( MustacheProblem.RENDER_ASYNC_PROCESSING_ERROR, "ExecutorService must be set in order to submit an asynchronous task"); } Future<AsyncAppendable> future = executor .submit(() -> { // We need a separate appendable for the async // execution DefaultOptions asyncOptions = new DefaultOptions( new AsyncAppendable(asyncAppendable), executionContext, segment, parameters, hash, new ArrayList<>(), engine, originalDefinition); executable.execute(asyncOptions); return (AsyncAppendable) asyncOptions .getAppendable(); }); asyncAppendable.setFuture(future); this.appendable = asyncAppendable; }
Helper helper = engine.getConfiguration().getHelpers() .get(parts.next()); LiteralSupport literalSupport = engine.getConfiguration() .getLiteralSupport();
@Override public void render(Appendable appendable, Object data) { DefaultMustacheRenderingEvent event = new DefaultMustacheRenderingEvent( engine.getConfiguration().getIdentifierGenerator() .generate(MustacheRenderingEvent.class)); try { renderingStarted(event); appendable = rootSegment.execute(appendable, data != null ? globalExecutionContext.setContextObject(data) : globalExecutionContext); // We need for flush the async appendable if needed RootSegment.flushAsyncAppendable(appendable); renderingFinished(event); } finally { event.release(); } }
private void nestedTemplate(ParsedTag tag) { if (engine.getConfiguration().getBooleanPropertyValue( EngineConfigurationKey.NESTED_TEMPLATE_SUPPORT_ENABLED)) {