footer
tag snippet injection processor.
+ *
+ * @author guqing
+ * @since 2.17.0
+ */
+public interface TemplateFooterProcessor extends ExtensionPoint {
+
+ MonoFooter element tag processor.
@@ -42,12 +47,23 @@ public TemplateFooterElementTagProcessor(final String dialectPrefix) { @Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, IElementTagStructureHandler structureHandler) { + + IModel modelToInsert = context.getModelFactory().createModel(); /* * Obtain the Spring application context. */ final ApplicationContext appCtx = SpringContextUtils.getApplicationContext(context); + String globalFooterText = getGlobalFooterText(appCtx); - structureHandler.replaceWith(globalFooterText, false); + modelToInsert.add(context.getModelFactory().createText(globalFooterText)); + + getTemplateFooterProcessors(context) + .concatMap(processor -> processor.process(context, tag, + structureHandler, modelToInsert) + ) + .then() + .block(); + structureHandler.replaceWith(modelToInsert, false); } private String getGlobalFooterText(ApplicationContext appCtx) { @@ -57,4 +73,13 @@ private String getGlobalFooterText(ApplicationContext appCtx) { .map(SystemSetting.CodeInjection::getFooter) .block(); } + + private FluxPowered by Halo
"); + lenient().when(fetcher.fetch(eq(SystemSetting.CodeInjection.GROUP), + eq(SystemSetting.CodeInjection.class))).thenReturn(Mono.just(codeInjection)); + + lenient().when(applicationContext.getBeanProvider(ExtensionGetter.class)) + .thenAnswer(invocation -> { + var objectProvider = mock(ObjectProvider.class); + when(objectProvider.getIfUnique()).thenReturn(extensionGetter); + return objectProvider; + }); + lenient().when(applicationContext.getBean(eq(SystemConfigurableEnvironmentFetcher.class))) + .thenReturn(fetcher); + } + + @Test + void footerProcessorTest() { + when(extensionGetter.getExtensions(TemplateFooterProcessor.class)) + .thenReturn(Flux.just(new FakeFooterCodeInjection())); + + String result = templateEngine.process("fake-template", getContext()); + // footer injected code is not processable + assertThat(result).isEqualToIgnoringWhitespace(""" +Powered by Halo
+