Search in sources :

Example 6 with MacroKey

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);
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) ArrayList(java.util.ArrayList) DescriptorKey(com.enonic.xp.page.DescriptorKey)

Example 7 with MacroKey

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);
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) Form(com.enonic.xp.form.Form)

Example 8 with MacroKey

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);
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) Form(com.enonic.xp.form.Form)

Example 9 with MacroKey

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);
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test)

Example 10 with MacroKey

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());
    }
}
Also used : MacroKey(com.enonic.xp.macro.MacroKey) RenderException(com.enonic.xp.portal.impl.rendering.RenderException) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

MacroKey (com.enonic.xp.macro.MacroKey)14 MacroDescriptor (com.enonic.xp.macro.MacroDescriptor)12 Test (org.junit.jupiter.api.Test)9 Form (com.enonic.xp.form.Form)7 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)5 ApplicationKey (com.enonic.xp.app.ApplicationKey)4 ContentId (com.enonic.xp.content.ContentId)4 ContentPath (com.enonic.xp.content.ContentPath)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 Input (com.enonic.xp.form.Input)4 InputTypeName (com.enonic.xp.inputtype.InputTypeName)4 MacroDescriptorService (com.enonic.xp.macro.MacroDescriptorService)4 MacroDescriptors (com.enonic.xp.macro.MacroDescriptors)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 PortalResponse (com.enonic.xp.portal.PortalResponse)4 MacroProcessor (com.enonic.xp.portal.macro.MacroProcessor)4 MacroProcessorFactory (com.enonic.xp.portal.macro.MacroProcessorFactory)4 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)4 PrincipalKey (com.enonic.xp.security.PrincipalKey)4 Site (com.enonic.xp.site.Site)4