use of com.enonic.xp.macro.MacroKey in project xp by enonic.
the class MacroDescriptorServiceImpl method getByApplication.
@Override
public MacroDescriptors getByApplication(final ApplicationKey applicationKey) {
final List<MacroDescriptor> list = new ArrayList<>();
if (isSystem(applicationKey)) {
list.addAll(builtinMacrosDescriptors.getAll().getSet());
} else {
for (final DescriptorKey descriptorKey : descriptorKeyLocator.findKeys(applicationKey)) {
final MacroKey macroKey = MacroKey.from(descriptorKey.getApplicationKey(), descriptorKey.getName());
final MacroDescriptor descriptor = getByKey(macroKey);
if (descriptor != null) {
list.add(descriptor);
}
}
}
return MacroDescriptors.from(list);
}
use of com.enonic.xp.macro.MacroKey in project xp by enonic.
the class BuiltinMacroDescriptors method generateDisableMacroDescriptor.
private MacroDescriptor generateDisableMacroDescriptor() {
final MacroKey macroKey = MacroKey.from(ApplicationKey.SYSTEM, "disable");
final Form form = Form.create().addFormItem(createTextAreaInput("body", "Contents", macroKey).occurrences(1, 1).build()).build();
return create(macroKey, "Disable macros", "Contents of this macro will not be formatted", form);
}
use of com.enonic.xp.macro.MacroKey in project xp by enonic.
the class BuiltinMacroDescriptors method generateEmbedIFrameMacroDescriptor.
private MacroDescriptor generateEmbedIFrameMacroDescriptor() {
final MacroKey macroKey = MacroKey.from(ApplicationKey.SYSTEM, "embed");
final Form form = Form.create().addFormItem(createTextAreaInput("body", "IFrame HTML", macroKey).occurrences(1, 1).build()).build();
return create(macroKey, "Embed IFrame", "Generic iframe embedder", form);
}
use of com.enonic.xp.macro.MacroKey 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);
}
use of com.enonic.xp.macro.MacroKey in project xp by enonic.
the class MacroInstructionTest method testMacroInstructionMissingController.
@Test
public void testMacroInstructionMissingController() throws Exception {
MacroKey key = MacroKey.from("myapp:mymacro");
MacroDescriptor macroDescriptor = MacroDescriptor.create().key(key).build();
when(macroDescriptorService.getByKey(key)).thenReturn(macroDescriptor);
try {
macroInstruction.evaluate(portalRequest, "MACRO _name=\"mymacro\" param1=\"value1\" _body=\"body\"");
fail("Expected exception");
} catch (RenderException e) {
assertEquals("Macro controller not found: mymacro", e.getMessage());
}
}
Aggregations