fitnesse.wikitext.parser.Help Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse Show documentation
Show all versions of fitnesse Show documentation
The fully integrated standalone wiki, and acceptance testing framework.
package fitnesse.wikitext.parser;
import fitnesse.wiki.WikiPageProperty;
import java.util.List;
public class Help extends SymbolType implements Rule, Translation {
private static final String editableOption = "-editable";
public Help() {
super("Help");
wikiMatcher(new Matcher().string("!help"));
wikiRule(this);
htmlTranslation(this);
}
@Override
public Maybe parse(Symbol current, Parser parser) {
List lookAhead = parser.peek(new SymbolType[] {SymbolType.Whitespace, SymbolType.Text});
if (!lookAhead.isEmpty()) {
String option = lookAhead.get(1).getContent();
if (option.equals(editableOption)) {
current.putProperty(editableOption, "");
parser.moveNext(2);
}
}
return new Maybe<>(current);
}
@Override
public String toTarget(Translator translator, Symbol symbol) {
String helpText = translator.getPage().getProperty(WikiPageProperty.HELP);
String editText = helpText.isEmpty() ? "edit help text" : "edit";
if (symbol.hasProperty(editableOption)) {
helpText += " (" + editText + ")";
}
return helpText;
}
}