Skip to content

Commit

Permalink
Merge pull request #158 from surli/XRENDERING-518-fix-macro-message
Browse files Browse the repository at this point in the history
XRENDERING-518: The macro content descriptor should specify if it can be edited inline
  • Loading branch information
tmortagne committed Nov 16, 2018
2 parents e6b16ee + 32262e0 commit 8394231
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
Expand Up @@ -19,6 +19,7 @@
*/
package org.xwiki.rendering.internal.macro.box;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -46,6 +47,13 @@
@Singleton
public class DefaultBoxMacro<P extends BoxMacroParameters> extends AbstractBoxMacro<P>
{
/**
* All the macro that needs to display an unchanged content div around the content.
* // TODO: this nasty hack will be removed as soon as message macro is refactored to use the AbstractBoxMacro
*/
private static final List<String> ACCEPTED_MACRO_UNCHANGED_CONTENT = Arrays.asList("box", "info", "error",
"warning", "success");

/**
* The description of the macro.
*/
Expand Down Expand Up @@ -73,8 +81,8 @@ protected List<Block> parseContent(P parameters, String content, MacroTransforma
// Don't execute transformations explicitly. They'll be executed on the generated content later on.
List<Block> children = getMacroContentParser().parse(content, context, false, context.isInline()).getChildren();

// if we are really in the context of this macro, it's an unchanged content
if (context.getCurrentMacroBlock().getId().equals("box")) {
// TODO: this nasty hack will be removed as soon as message macro is refactored to use the AbstractBoxMacro
if (ACCEPTED_MACRO_UNCHANGED_CONTENT.contains(context.getCurrentMacroBlock().getId())) {
return Collections.singletonList(new MetaDataBlock(children, this.getUnchangedContentMetaData()));

// else we cannot guarantee it
Expand Down
Expand Up @@ -19,15 +19,13 @@
*/
package org.xwiki.rendering.internal.macro.message;

import java.util.Collections;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.apache.commons.lang3.StringUtils;
import org.xwiki.rendering.block.Block;
import org.xwiki.rendering.block.MetaDataBlock;
import org.xwiki.rendering.macro.AbstractMacro;
import org.xwiki.rendering.macro.Macro;
import org.xwiki.rendering.macro.MacroExecutionException;
Expand Down Expand Up @@ -79,10 +77,8 @@ public List<Block> execute(Object parameters, String content, MacroTransformatio

boxParameters.setCssClass(context.getCurrentMacroBlock().getId() + "message");

return Collections.singletonList(
new MetaDataBlock(this.boxMacro.execute(boxParameters, content, context),
this.getUnchangedContentMetaData())
);
// TODO: we should not rely directly on the concrete macro, but only on the AbstractBoxMacro
return this.boxMacro.execute(boxParameters, content, context);
}

@Override
Expand Down
Expand Up @@ -16,8 +16,8 @@ beginMacroMarkerStandalone [info] [] [Failed to do this action. The correct poss
* use another value
* you don't have right
* another possibility]
beginMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
beginGroup [[class]=[box infomessage]]
beginMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
beginParagraph
onWord [Failed]
onSpace
Expand Down Expand Up @@ -64,8 +64,8 @@ onSpace
onWord [possibility]
endListItem
endList [BULLETED]
endGroup [[class]=[box infomessage]]
endMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
endGroup [[class]=[box infomessage]]
endMacroMarkerStandalone [info] [] [Failed to do this action. The correct possibilities are:
* use another value
* you don't have right
Expand Down
Expand Up @@ -16,8 +16,8 @@ beginMacroMarkerStandalone [warning] [] [Failed to do this action. The correct p
* use another value
* you don't have right
* another possibility]
beginMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
beginGroup [[class]=[box warningmessage]]
beginMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
beginParagraph
onWord [Failed]
onSpace
Expand Down Expand Up @@ -64,8 +64,8 @@ onSpace
onWord [possibility]
endListItem
endList [BULLETED]
endGroup [[class]=[box warningmessage]]
endMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
endGroup [[class]=[box warningmessage]]
endMacroMarkerStandalone [warning] [] [Failed to do this action. The correct possibilities are:
* use another value
* you don't have right
Expand Down
Expand Up @@ -16,8 +16,8 @@ beginMacroMarkerStandalone [error] [] [Failed to do this action. The correct pos
* use another value
* you don't have right
* another possibility]
beginMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
beginGroup [[class]=[box errormessage]]
beginMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
beginParagraph
onWord [Failed]
onSpace
Expand Down Expand Up @@ -64,8 +64,8 @@ onSpace
onWord [possibility]
endListItem
endList [BULLETED]
endGroup [[class]=[box errormessage]]
endMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
endGroup [[class]=[box errormessage]]
endMacroMarkerStandalone [error] [] [Failed to do this action. The correct possibilities are:
* use another value
* you don't have right
Expand Down
Expand Up @@ -13,8 +13,8 @@
beginDocument
beginMacroMarkerStandalone [info] [] [* item1
* item2]
beginMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
beginGroup [[class]=[box infomessage]]
beginMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
beginList [BULLETED]
beginListItem
onWord [item1]
Expand All @@ -23,8 +23,8 @@ beginListItem
onWord [item2]
endListItem
endList [BULLETED]
endGroup [[class]=[box infomessage]]
endMetaData [[unchanged-content]=[java.util.List< org.xwiki.rendering.block.Block >]]
endGroup [[class]=[box infomessage]]
endMacroMarkerStandalone [info] [] [* item1
* item2]
endDocument

0 comments on commit 8394231

Please sign in to comment.