Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #57 #60

Merged
merged 1 commit into from
Nov 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Source/nz/net/ultraq/thymeleaf/AbstractContentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
/**
* Common code for processors that fetch the content of other pages to include
* into the current template.
*
*
* @author Emanuel Rabina
*/
public abstract class AbstractContentProcessor extends AbstractAttrProcessor {

/**
* Subclass constructor, set the attribute name that this processor will
* respond to.
*
*
* @param attribute
*/
protected AbstractContentProcessor(String attribute) {
Expand All @@ -54,7 +54,7 @@ protected AbstractContentProcessor(String attribute) {
* Find and return clones of all fragments within the given elements without
* delving into <tt>layout:include</tt>, <tt>layout:replace</tt>, or
* <tt>layout:substituteby</tt> elements.
*
*
* @param elements
* @return Map of prefixed fragment names and their fragment elements.
*/
Expand All @@ -69,7 +69,7 @@ protected static Map<String,Object> findFragments(List<Element> elements) {
* Recursive clone of all fragment elements without delving into delving
* into <tt>layout:include</tt>, <tt>layout:replace</tt>, or
* <tt>layout:substituteby</tt> elements.
*
*
* @param fragments
* @param elements
*/
Expand All @@ -81,11 +81,12 @@ private static void findFragments(HashMap<String,Object> fragments, List<Element
Element fragment = (Element)element.cloneNode(null, true);
removeAttribute(fragment, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_FRAGMENT);
fragments.put(FRAGMENT_NAME_PREFIX + fragmentname, fragment);
}
if (!hasAttribute(element, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_INCLUDE) &&
!hasAttribute(element, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_REPLACE) &&
!hasAttribute(element, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_SUBSTITUTEBY)) {
findFragments(fragments, element.getElementChildren());
} else {
if (!hasAttribute(element, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_INCLUDE) &&
!hasAttribute(element, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_REPLACE) &&
!hasAttribute(element, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_SUBSTITUTEBY)) {
findFragments(fragments, element.getElementChildren());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# Test the reference of a fragment content within a nested fragment call using include
# Based off GitHub issue #57 - https://github.com/ultraq/thymeleaf-layout-dialect/issues/57

%TEMPLATE_MODE HTML5

%INPUT
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">

<div id="fragment-outer" layout:fragment="outer" th:remove="all">
<div id="include-inner" layout:include="this :: inner">
<div id="inner-content" layout:fragment="inner-content">
<div id="ref-outer" layout:fragment="outer-content">This should not be visible</div>
</div>
</div>
</div>

<div id="fragment-inner" layout:fragment="inner" th:remove="all">
<div id="ref-inner" layout:fragment="inner-content"/>
</div>

<div id="include-outer" layout:include="this :: outer">
<div id="outer-content" layout:fragment="outer-content">Outer content</div>
</div>
</html>


%OUTPUT
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<div id="include-outer">
<div id="include-inner">
<div id="ref-inner">
<div id="ref-outer">Outer content</div>
</div>
</div>
</div>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

# Test the reference of a fragment content within a nested fragment call using replace
# Based off GitHub issue #57 - https://github.com/ultraq/thymeleaf-layout-dialect/issues/57

%TEMPLATE_MODE HTML5

%INPUT
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">

<th:block th:remove="all">
<div id="fragment-outer" layout:fragment="outer">
<div id="replace-inner" layout:replace="this :: inner">
<div id="inner-content" layout:fragment="inner-content">
<div id="ref-outer" layout:fragment="outer-content">This should not be visible</div>
</div>
</div>
</div>

<div id="fragment-inner" layout:fragment="inner">
<div id="ref-inner" layout:fragment="inner-content"/>
</div>
</th:block>

<div id="replace-outer" layout:replace="this :: outer">
<div id="outer-content" layout:fragment="outer-content">Outer content</div>
</div>
</html>


%OUTPUT
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<div id="fragment-outer">
<div id="fragment-inner">
<div id="ref-inner">
<div id="ref-outer">Outer content</div>
</div>
</div>
</div>
</html>