Mercurial Hosting > nabble
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 package nabble.view.web.template; | |
2 | |
3 import fschmidt.util.java.ObjectUtils; | |
4 import nabble.view.lib.Recaptcha; | |
5 import nabble.naml.compiler.Command; | |
6 import nabble.naml.compiler.CommandSpec; | |
7 import nabble.naml.compiler.Encoder; | |
8 import nabble.naml.compiler.IPrintWriter; | |
9 import nabble.naml.compiler.Interpreter; | |
10 import nabble.naml.compiler.Namespace; | |
11 import nabble.naml.compiler.ScopedInterpreter; | |
12 import org.slf4j.Logger; | |
13 import org.slf4j.LoggerFactory; | |
14 | |
15 import java.util.LinkedHashSet; | |
16 import java.util.Set; | |
17 | |
18 | |
19 @Namespace ( | |
20 name = "html", | |
21 global = true | |
22 ) | |
23 public final class HtmlNamespace { | |
24 private static final Logger logger = LoggerFactory.getLogger(HtmlNamespace.class); | |
25 | |
26 private final Set<String> headSet = new LinkedHashSet<String>(); | |
27 private final String body; | |
28 | |
29 HtmlNamespace(ScopedInterpreter<HtmlNamespace> interp) { | |
30 interp.setEncoder(Encoder.HTML); | |
31 this.body = interp.getArgString(this,"do"); | |
32 } | |
33 | |
34 @Command public void html_head_content(IPrintWriter out,Interpreter interp) { | |
35 String head = ObjectUtils.join(headSet); | |
36 out.print(head); | |
37 } | |
38 | |
39 @Command public void html_body_content(IPrintWriter out,Interpreter interp) { | |
40 out.print(body); | |
41 } | |
42 | |
43 public static final CommandSpec put_in_head = CommandSpec.NO_OUTPUT() | |
44 .dotParameter("in_head") | |
45 .build() | |
46 ; | |
47 | |
48 @Command public void put_in_head(IPrintWriter out,Interpreter interp) { | |
49 String s = interp.getArgString("in_head"); | |
50 if( s == null ) | |
51 throw new NullPointerException(); | |
52 headSet.add(s); | |
53 } | |
54 | |
55 public static final CommandSpec style = new CommandSpec.Builder() | |
56 .parameters("property") | |
57 .dotParameter("value") | |
58 .optionalParameters("value") | |
59 .build() | |
60 ; | |
61 | |
62 @Command public static void style(IPrintWriter out,Interpreter interp) { | |
63 String property = interp.getArgString("property"); | |
64 String value = interp.getArgString("value"); | |
65 if( value != null ) { | |
66 out.print( property + ':' + value ); | |
67 } | |
68 } | |
69 | |
70 public static final CommandSpec calendar = CalendarWidget._calendar; | |
71 | |
72 @Command public void calendar(IPrintWriter out,Interpreter interp) { | |
73 CalendarWidget._calendar(out, interp); | |
74 } | |
75 | |
76 @Command public void page_template(IPrintWriter out,Interpreter interp) { | |
77 out.print(interp.template().name()); | |
78 } | |
79 | |
80 @Command public void page_template_command_id(IPrintWriter out,Interpreter interp) { | |
81 out.print(interp.template().macro.getId()); | |
82 } | |
83 | |
84 @Command public void page_base_classes(IPrintWriter out,Interpreter interp) { | |
85 out.print(ServletNamespace.class.getName()); | |
86 } | |
87 | |
88 @Command public void captcha_div(IPrintWriter out, Interpreter interp) { | |
89 headSet.add( Recaptcha.JS ); | |
90 out.print( Recaptcha.DIV ); | |
91 } | |
92 | |
93 | |
94 } |