Mercurial Hosting > nabble
diff src/nabble/view/web/template/HtmlNamespace.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/nabble/view/web/template/HtmlNamespace.java Thu Mar 21 19:15:52 2019 -0600 @@ -0,0 +1,94 @@ +package nabble.view.web.template; + +import fschmidt.util.java.ObjectUtils; +import nabble.view.lib.Recaptcha; +import nabble.naml.compiler.Command; +import nabble.naml.compiler.CommandSpec; +import nabble.naml.compiler.Encoder; +import nabble.naml.compiler.IPrintWriter; +import nabble.naml.compiler.Interpreter; +import nabble.naml.compiler.Namespace; +import nabble.naml.compiler.ScopedInterpreter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedHashSet; +import java.util.Set; + + +@Namespace ( + name = "html", + global = true +) +public final class HtmlNamespace { + private static final Logger logger = LoggerFactory.getLogger(HtmlNamespace.class); + + private final Set<String> headSet = new LinkedHashSet<String>(); + private final String body; + + HtmlNamespace(ScopedInterpreter<HtmlNamespace> interp) { + interp.setEncoder(Encoder.HTML); + this.body = interp.getArgString(this,"do"); + } + + @Command public void html_head_content(IPrintWriter out,Interpreter interp) { + String head = ObjectUtils.join(headSet); + out.print(head); + } + + @Command public void html_body_content(IPrintWriter out,Interpreter interp) { + out.print(body); + } + + public static final CommandSpec put_in_head = CommandSpec.NO_OUTPUT() + .dotParameter("in_head") + .build() + ; + + @Command public void put_in_head(IPrintWriter out,Interpreter interp) { + String s = interp.getArgString("in_head"); + if( s == null ) + throw new NullPointerException(); + headSet.add(s); + } + + public static final CommandSpec style = new CommandSpec.Builder() + .parameters("property") + .dotParameter("value") + .optionalParameters("value") + .build() + ; + + @Command public static void style(IPrintWriter out,Interpreter interp) { + String property = interp.getArgString("property"); + String value = interp.getArgString("value"); + if( value != null ) { + out.print( property + ':' + value ); + } + } + + public static final CommandSpec calendar = CalendarWidget._calendar; + + @Command public void calendar(IPrintWriter out,Interpreter interp) { + CalendarWidget._calendar(out, interp); + } + + @Command public void page_template(IPrintWriter out,Interpreter interp) { + out.print(interp.template().name()); + } + + @Command public void page_template_command_id(IPrintWriter out,Interpreter interp) { + out.print(interp.template().macro.getId()); + } + + @Command public void page_base_classes(IPrintWriter out,Interpreter interp) { + out.print(ServletNamespace.class.getName()); + } + + @Command public void captcha_div(IPrintWriter out, Interpreter interp) { + headSet.add( Recaptcha.JS ); + out.print( Recaptcha.DIV ); + } + + +} \ No newline at end of file