--
You received this message because you are subscribed to the Google Groups "rythmengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rythmengine...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank you for your help!
Indeed, I did not need a custom dialect for that. I' be had a second look at the verbatim parser that didn't use dialects.
But I still cannot call a custom method defined in java from template. Is there a documentation for that?
Thanks
> You received this message because you are subscribed to a topic in the Google Groups "rythmengine" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/rythmengine/cTRciR3Fjjw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to rythmengine...@googlegroups.com.
Yes, I have.
Thank you for your help!
Map<String, Object> conf = new HashMap<String, Object>();
conf.put("home.template", "/home/cory/testrythm/src/main/resources/");
Rythm.init(conf);
RythmEngine engine = Rythm.engine();
engine.extensionManager().registerUserDefinedParsers(new WebjarsAtParser());
Map<String, Object> params = new HashMap<String, Object>();
params.put("who", "World");
params.put("greeting", "My greetings!");
System.out.println(engine.render("/home/cory/testrythm/src/main/resources/hello.html", params));
public class WebjarsAtParser extends KeywordParserFactory {
private static final Pattern P = Pattern.compile(
getRegex(), Pattern.DOTALL);
private static String getRegex(){
return "((@webjarsAt)(\\(\\\"(.*)\\\",\\\"(js|css)\\\"\\))(.*))";
}
private static String getTestRegex(){
return "@webjarsAt(\"test\",\"css\")</h5>\n</body>\n</html>";
}
public static void main(String[] args) {
//@webjarsAt("test","css")</h5></body></html>
String s = getTestRegex();
Matcher m = P.matcher(s);
if (m.matches()) {
for (int i = 1; i <= m.groupCount(); i++){
System.out.println(m.group(i));
}
}
}
public IParser create(IContext ctx) {
return new ParserBase(ctx) {
public Token go() {
String remain = remain();
Matcher m = P.matcher(remain);
if (m.matches()) {
for (int i = 1; i <= m.groupCount(); i++){
System.out.println(i + ">>>" + m.group(i));
}
step(m.group(1).length());
return new CodeToken("p(org.rythmengine.utils.S.raw(\"" +getLine(m.group(3), m.group(4))+"\"));", ctx()).pline();
} else {
return null;
}
}
};
}
private String getLine(String uri, String type){
if (type.equals("css")){
String ret = "<link href=\"${webjarsAt('"+uri+"')}\" rel=\"stylesheet\">";
// System.out.println(ret);
return ret;
}else if (type.equals("js")){
return "<script src=\"${webjarsAt('"+uri+"')}\"></script>";
}
return null;
}
@Override
public IKeyword keyword() {
return ExtendedKeyword.WEBJARSAT;
}
@Override
protected String patternStr() {
return null;
}
}
public enum ExtendedKeyword implements IKeyword{
WEBJARSAT, PUBLICAT;
private final String s;
private ExtendedKeyword() {
this.s = name().toLowerCase();
}
private ExtendedKeyword(String s) {
this.s = (null == s) ? name().toLowerCase() : s;
}
@Override
public String toString() {
return s;
}
public boolean isRegexp() {
return !s.equals(name().toLowerCase());
}
}