Skip to content

Commit

Permalink
#742 XeChain with Scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 8, 2017
1 parent 6e31a42 commit 5888370
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/takes/rs/xe/RsXembly.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public RsXembly(final Node dom, final Iterable<XeSource> sources) {
* @param src Source
*/
public RsXembly(final XeSource src) {
this(emptyDocument(), src);
this(RsXembly.emptyDocument(), src);
}

/**
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/org/takes/rs/xe/XeChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.IOException;
import java.util.Arrays;
import lombok.EqualsAndHashCode;
import org.takes.Scalar;
import org.xembly.Directive;
import org.xembly.Directives;

Expand Down Expand Up @@ -54,12 +55,28 @@ public XeChain(final XeSource... src) {
* @param items Sources
*/
public XeChain(final Iterable<XeSource> items) {
this(
new Scalar<Iterable<XeSource>>() {
@Override
public Iterable<XeSource> get() {
return items;
}
}
);
}

/**
* Ctor.
* @param items Sources
* @since 1.5
*/
public XeChain(final Scalar<Iterable<XeSource>> items) {
super(
new XeSource() {
@Override
public Iterable<Directive> toXembly() throws IOException {
final Directives dirs = new Directives();
for (final XeSource src : items) {
for (final XeSource src : items.get()) {
dirs.push().append(src.toXembly()).pop();
}
return dirs;
Expand Down
41 changes: 39 additions & 2 deletions src/main/java/org/takes/rs/xe/XeWhen.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,57 @@ public XeSource get() {
* @param condition Condition
* @param source Xembly source
*/
public XeWhen(final boolean condition, final Scalar<XeSource> source) {
this(
new Scalar<Boolean>() {
@Override
public Boolean get() {
return condition;
}
},
source
);
}

/**
* Ctor.
* @param condition Condition
* @param source Xembly source
* @since 1.5
*/
public XeWhen(final Scalar<Boolean> condition, final XeSource source) {
this(
condition,
new Scalar<XeSource>() {
@Override
public XeSource get() {
return source;
}
}
);
}

/**
* Ctor.
* @param condition Condition
* @param source Xembly source
* @since 1.5
*/
@SuppressWarnings
(
{
"PMD.CallSuperInConstructor",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"
}
)
public XeWhen(final boolean condition, final Scalar<XeSource> source) {
public XeWhen(final Scalar<Boolean> condition,
final Scalar<XeSource> source) {
super(
new XeSource() {
@Override
public Iterable<Directive> toXembly() throws IOException {
final Iterable<Directive> dirs;
if (condition) {
if (condition.get()) {
dirs = source.get().toXembly();
} else {
dirs = Collections.emptyList();
Expand Down
18 changes: 10 additions & 8 deletions src/main/resources/org/takes/facets/flash/flash.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:template name="takes_flash">
<xsl:param name="flash"/>
<p>
<xsl:attribute name="class">
<xsl:text>flash</xsl:text>
<xsl:text> flash-</xsl:text>
<xsl:value-of select="$flash/level"/>
</xsl:attribute>
<xsl:value-of select="$flash/message"/>
</p>
<xsl:if test="$flash/message">
<p>
<xsl:attribute name="class">
<xsl:text>flash</xsl:text>
<xsl:text> flash-</xsl:text>
<xsl:value-of select="$flash/level"/>
</xsl:attribute>
<xsl:value-of select="$flash/message"/>
</p>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 5888370

Please sign in to comment.