Skip to content

Commit

Permalink
introduced an intermediate abstract class to allow for easier definit…
Browse files Browse the repository at this point in the history
…ion of special purpose HTML template objects.
  • Loading branch information
Harald Kirsch committed Feb 1, 2015
1 parent c8dfec6 commit b3de0bd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 45 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Also provides a way to handle servlet GET and POST parameters.

See the current <a href="http://haraldki.github.io/htmlJgen/htmlJgen-javadoc/">javadoc</a> for more information.

Test coverage reporting is also <a href="http://haraldki.github.io/htmlJgen/coverage-report/">available</a>.
Test <a href="http://haraldki.github.io/htmlJgen/coverage-report/">coverage reporting</a> is also available.

## Why that?

Expand Down Expand Up @@ -100,10 +100,10 @@ possibly catering for different HTML4, 4.01, 5 versions out
there. Feel free to prepare a pull request.-)

I even retracted the `EmptyElem.setClass(String classes)` method again
despite the fact that `setAttr("class", "yada")` is the
most frequently used call. But once you start with these convenience
methods it is hard to stop. And any stop would be arbitrary, so kept it
all clean and simple for now.
despite the fact that `setAttr("class", "yada")` is the most
frequently used call. But once you start with these convenience
methods it is hard to stop. And any stop would be arbitrary, so I kept
it all clean and simple for now.



2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<include file="src/ant-macros/cobertura.xml"/>
<include file="src/ant-macros/javac.xml"/>

<property name="version" value="1.2.0"/>
<property name="version" value="1.3.0"/>

<path id="compile-classpath">
<fileset dir="libs/build" includes="**/*.jar"/>
Expand Down
47 changes: 9 additions & 38 deletions src/java/de/pifpafpuf/web/html/Html.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package de.pifpafpuf.web.html;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

/**
* is a node in an HTML DOM tree intended for HTML code generation. It always
* generates a close tag.
*/
public class Html extends EmptyElem {
public final class Html extends FormattingHtml {
private final List<Stringable> children;
private boolean tight = false;
/*+******************************************************************/
/**
* creates an HTML element for the given {@code tagname}.
Expand Down Expand Up @@ -55,13 +53,6 @@ public Html addEncoded(String text) {
return this;
}
/*+******************************************************************/
/**
* adds the given text as child element.
*/
public void add(HtmlText child) {
children.add(child);
}
/*+******************************************************************/
/**
* adds a child element for the given {@code tagname} and returns it.
* @param tagname name of the element to generate
Expand All @@ -76,7 +67,7 @@ public Html add(String tagname) {
/**
* adds the given child element
*/
public void add(EmptyElem child) {
public void add(Stringable child) {
children.add(child);
}
/*+**********************************************************************/
Expand All @@ -87,15 +78,12 @@ public EmptyElem addEmpty(String tagname) {
}
/*+**********************************************************************/
/**
* requests tight output of this HTML element. The children of this element
* are printed out inside the element's tags without any additional
* whitespace like line breaks and indentation. Tightness is inherited by
* all children.
* <p>calls {@link FormattingHtml#setTight} with {@code true}.</p>
*
* @return {@code this}
*/
public Html setTight() {
tight = true;
super.setTight(true);
return this;
}
/*+******************************************************************/
Expand All @@ -119,27 +107,10 @@ public Html addTight(String tagname) {
return child;
}
/*+******************************************************************/
@Override
public void print(Appendable out, int indent) throws IOException {
super.print(out, indent);
if (tight) {
indent = Integer.MIN_VALUE;
}
printChildren(out, indent);
if (indent>=0) {
out.append('\n');
TextUtils.doIndent(out, indent);
}
out.append("</").append(super.getName()).append('>');
}
/*+******************************************************************/
private void printChildren(Appendable out, int indent) throws IOException {
for(Stringable child : children) {
if (indent>=0) {
out.append('\n');
}
child.print(out, indent+2);
}
/**
* returns the child elements.
*/
public final Iterable<Stringable> getChildren() {
return children;
}
/*+******************************************************************/
}
2 changes: 1 addition & 1 deletion src/java/de/pifpafpuf/web/html/Stringable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* describes objects that can append themselves in a readable manner to an
* {@code Appendable}.
*/
interface Stringable {
public interface Stringable {
/**
* appends the object's string representation to {@code out}, possibly using
* an indent of the given number of whitespace characters. Whether and
Expand Down

0 comments on commit b3de0bd

Please sign in to comment.