use of com.enonic.xp.macro.MacroDescriptor in project xp by enonic.
the class MacroInstruction method resolveMacroDescriptorCaseInsensitive.
private MacroDescriptor resolveMacroDescriptorCaseInsensitive(final SiteConfigs siteConfigs, final String macroName) {
for (SiteConfig siteConfig : siteConfigs) {
final MacroDescriptors macroDescriptors = macroDescriptorService.getByApplication(siteConfig.getApplicationKey());
final MacroDescriptor macroDescriptor = macroDescriptors.stream().filter((md) -> md.getName().equalsIgnoreCase(macroName)).findFirst().orElse(null);
if (macroDescriptor != null) {
return macroDescriptor;
}
}
return null;
}
use of com.enonic.xp.macro.MacroDescriptor in project xp by enonic.
the class MacroInstructionTest method testInstructionMacro.
@Test
public void testInstructionMacro() throws Exception {
MacroKey key = MacroKey.from("myapp:mymacro");
MacroDescriptor macroDescriptor = MacroDescriptor.create().key(key).build();
when(macroDescriptorService.getByKey(key)).thenReturn(macroDescriptor);
MacroProcessor macro = (ctx) -> PortalResponse.create().body(ctx.getName() + ": param1=" + ctx.getParameter("param1").get(0) + ", body=" + ctx.getBody()).build();
when(macroProcessorFactory.fromScript(any())).thenReturn(macro);
String outputHtml = macroInstruction.evaluate(portalRequest, "MACRO _name=\"mymacro\" param1=\"value1\" _body=\"body\"").getAsString();
assertEquals("mymacro: param1=value1, body=body", outputHtml);
}
use of com.enonic.xp.macro.MacroDescriptor in project xp by enonic.
the class MacroInstructionTest method testInstructionSystemMacro.
@Test
public void testInstructionSystemMacro() throws Exception {
MacroKey key = MacroKey.from(ApplicationKey.SYSTEM, "mymacro");
MacroDescriptor macroDescriptor = MacroDescriptor.create().key(key).build();
when(macroDescriptorService.getByKey(key)).thenReturn(macroDescriptor);
when(macroDescriptorService.getByApplication(any())).thenReturn(MacroDescriptors.empty());
MacroProcessor macro = (ctx) -> PortalResponse.create().body(ctx.getName() + ": param1=" + ctx.getParam("param1") + ", body=" + ctx.getBody()).build();
when(macroProcessorFactory.fromScript(any())).thenReturn(macro);
String outputHtml = macroInstruction.evaluate(portalRequest, "MACRO _name=\"mymacro\" param1=\"value1\" _body=\"body\"").getAsString();
assertEquals("mymacro: param1=value1, body=body", outputHtml);
}
use of com.enonic.xp.macro.MacroDescriptor in project xp by enonic.
the class MacroInstructionTest method testInstructionMacroParamsCaseInsensitive.
@Test
public void testInstructionMacroParamsCaseInsensitive() throws Exception {
MacroKey key = MacroKey.from("myapp:mymacro");
Form form = Form.create().addFormItem(createTextLineInput("param1", "Param 1").occurrences(1, 1).build()).addFormItem(createTextLineInput("param2", "Param 2").occurrences(1, 1).build()).build();
MacroDescriptor macroDescriptor = MacroDescriptor.create().key(key).form(form).build();
when(macroDescriptorService.getByKey(key)).thenReturn(macroDescriptor);
when(macroDescriptorService.getByApplication(key.getApplicationKey())).thenReturn(MacroDescriptors.from(macroDescriptor));
MacroProcessor macro = (ctx) -> PortalResponse.create().body(ctx.getName() + ": param1=" + ctx.getParam("param1") + ", body=" + ctx.getBody()).build();
when(macroProcessorFactory.fromScript(any())).thenReturn(macro);
String outputHtml = macroInstruction.evaluate(portalRequest, "MACRO _name=\"MYMACRO\" PARAM1=\"value1\" _body=\"body\"").getAsString();
assertEquals("mymacro: param1=value1, body=body", outputHtml);
}
use of com.enonic.xp.macro.MacroDescriptor in project xp by enonic.
the class MacroInstructionTest method testInstructionMissingMacro.
@Test
public void testInstructionMissingMacro() throws Exception {
MacroKey key = MacroKey.from("myapp:somemacro");
Form form = Form.create().build();
MacroDescriptor macroDescriptor = MacroDescriptor.create().key(key).form(form).build();
when(macroDescriptorService.getByKey(key)).thenReturn(macroDescriptor);
when(macroDescriptorService.getByApplication(key.getApplicationKey())).thenReturn(MacroDescriptors.from(macroDescriptor));
String outputHtml = macroInstruction.evaluate(portalRequest, "MACRO _name=\"mymacro\" param1=\"value1\" _body=\"body\"").getAsString();
assertEquals("[mymacro param1=\"value1\"]body[/mymacro]", outputHtml);
}
Aggregations