Mercurial Hosting > nabble
comparison src/nabble/view/web/template/NamlConfigurationNamespace.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 nabble.model.Site; | |
4 import nabble.naml.compiler.Command; | |
5 import nabble.naml.compiler.CommandSpec; | |
6 import nabble.naml.compiler.IPrintWriter; | |
7 import nabble.naml.compiler.Interpreter; | |
8 import nabble.naml.compiler.Namespace; | |
9 | |
10 | |
11 @Namespace( | |
12 name = "naml_configuration", | |
13 global = false | |
14 ) | |
15 public class NamlConfigurationNamespace { | |
16 | |
17 public static final CommandSpec get_value = new CommandSpec.Builder() | |
18 .parameters("name", "default") | |
19 .build() | |
20 ; | |
21 | |
22 @Command public void get_value(IPrintWriter out, Interpreter interp) { | |
23 Site site = NabbleNamespace.current().site(); | |
24 String name = interp.getArgString("name"); | |
25 String value = site.getConfigurationValue(name); | |
26 if( value == null ) | |
27 value = interp.getArgString("default"); | |
28 out.print(value); | |
29 } | |
30 | |
31 public static final CommandSpec set = new CommandSpec.Builder() | |
32 .parameters("name", "value", "naml") | |
33 .optionalParameters("default") | |
34 .build() | |
35 ; | |
36 | |
37 @Command public void set(IPrintWriter out, Interpreter interp) { | |
38 Site site = NabbleNamespace.current().site(); | |
39 String name = interp.getArgString("name"); | |
40 String value = interp.getArgString("value"); | |
41 String defaultValue = interp.getArgString("default"); | |
42 if (defaultValue != null && value.equals(defaultValue)) { | |
43 site.deleteConfiguration(name); | |
44 } else { | |
45 String naml = interp.getArgString("naml"); | |
46 site.saveConfiguration(name,value,naml); | |
47 } | |
48 out.print(name); | |
49 } | |
50 | |
51 @Command public void apply(IPrintWriter out, Interpreter interp) { | |
52 Site site = NabbleNamespace.current().site(); | |
53 site.update(); | |
54 } | |
55 | |
56 } |