aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/config.toml1
-rw-r--r--src/config/config.nim55
-rw-r--r--src/config/toml.nim11
-rw-r--r--test/js/config.toml4
-rw-r--r--test/js/style.html4
5 files changed, 35 insertions, 40 deletions
diff --git a/res/config.toml b/res/config.toml
index 121e0509..9a18e65f 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -57,7 +57,6 @@ history-file = "history.uri"
history-size = 100
cookie-file = "cookies.txt"
tmpdir = "${TMPDIR:-/tmp}/cha-tmp-$LOGNAME"
-sockdir = "${TMPDIR:-/tmp}/cha-sock-$LOGNAME"
editor = "${EDITOR:-vi}"
cgi-dir = ["cgi-bin", "$CHA_LIBEXEC_DIR/cgi-bin"]
download-dir = "${TMPDIR:-/tmp}/"
diff --git a/src/config/config.nim b/src/config/config.nim
index 5627cdd0..ef138ca5 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -399,20 +399,25 @@ proc typeCheck(v: TomlValue; t: set[TomlValueType]; k: string): Err[string] =
return err(k & ": invalid type (got " & $v.t & ", expected " & $t & ")")
ok()
+proc warnValuesLeft(ctx: var ConfigParser; v: TomlValue; k: string) =
+ for fk in v.keys:
+ let kk = if k != "": k & '.' & fk else: fk
+ ctx.warnings.add("unrecognized option " & kk)
+
proc parseConfigValue(ctx: var ConfigParser; x: var object; v: TomlValue;
k: string): Err[string] =
?typeCheck(v, tvtTable, k)
if v.tab.clear:
x = default(typeof(x))
+ when x isnot typeof(Config()[]):
+ let k = k & '.'
for fk, fv in x.fieldPairs:
when fk notin ["jsvfns", "arraySeen", "dir"]:
- let kebabk = camelToKebabCase(fk)
- if kebabk in v:
- let kkk = if k != "":
- k & "." & fk
- else:
- fk
- ?ctx.parseConfigValue(fv, v[kebabk], kkk)
+ const kebabk = camelToKebabCase(fk)
+ var x: TomlValue
+ if v.pop(kebabk, x):
+ ?ctx.parseConfigValue(fv, x, k & kebabk)
+ ctx.warnValuesLeft(v, k)
ok()
proc parseConfigValue(ctx: var ConfigParser; x: var ref object; v: TomlValue;
@@ -444,13 +449,9 @@ proc parseConfigValue[U, V](ctx: var ConfigParser; x: var OrderedTable[U, V];
proc parseConfigValue[U, V](ctx: var ConfigParser; x: var TableRef[U, V];
v: TomlValue; k: string): Err[string] =
- ?typeCheck(v, tvtTable, k)
- if v.tab.clear or x == nil:
+ if x == nil:
x = TableRef[U, V]()
- for kk, vv in v:
- let kkk = k & "[" & kk & "]"
- ?ctx.parseConfigValue(x.mgetOrPut(kk, default(V)), vv, kkk)
- ok()
+ ctx.parseConfigValue(x[], v, k)
proc parseConfigValue(ctx: var ConfigParser; x: var bool; v: TomlValue;
k: string): Err[string] =
@@ -608,24 +609,18 @@ proc parseConfigValue(ctx: var ConfigParser; x: var CSSConfig; v: TomlValue;
k: string): Err[string] =
?typeCheck(v, tvtTable, k)
ctx.warnings.add("[css] is deprecated; use buffer.user-style instead")
- for kk, vv in v:
- let kkk = if k != "":
- k & "." & kk
- else:
- kk
- case kk
- of "include":
- ?typeCheck(vv, {tvtString, tvtArray}, kkk)
- case vv.t
- of tvtString:
+ var vv: TomlValue
+ if v.pop("include", vv):
+ ?typeCheck(vv, {tvtString, tvtArray}, k & ".include")
+ if vv.t == tvtString:
+ ?x.stylesheet.readUserStylesheet(ctx.dir, vv.s)
+ else: # array
+ for child in vv.a:
?x.stylesheet.readUserStylesheet(ctx.dir, vv.s)
- of tvtArray:
- for child in vv.a:
- ?x.stylesheet.readUserStylesheet(ctx.dir, vv.s)
- else: discard
- of "inline":
- ?typeCheck(vv, tvtString, kkk)
- x.stylesheet &= vv.s
+ if v.pop("inline", vv):
+ ?typeCheck(vv, tvtString, k & ".inline")
+ x.stylesheet &= vv.s
+ ctx.warnValuesLeft(v, k)
ok()
proc parseConfigValue(ctx: var ConfigParser; x: var Regex; v: TomlValue;
diff --git a/src/config/toml.nim b/src/config/toml.nim
index 1866a036..66a59120 100644
--- a/src/config/toml.nim
+++ b/src/config/toml.nim
@@ -121,16 +121,17 @@ func `$`*(val: TomlValue): string =
result &= $it
result &= ']'
-func `[]`*(val: TomlValue; key: string): TomlValue =
- return val.tab.map[key]
+template pop*(val: TomlValue; key: string; x: typed): bool =
+ val.tab.map.pop(key, x)
+
+iterator keys*(val: TomlValue): string {.inline.} =
+ for k in val.tab.map.keys:
+ yield k
iterator pairs*(val: TomlValue): (string, TomlValue) {.inline.} =
for k, v in val.tab.map:
yield (k, v)
-func contains*(val: TomlValue; key: string): bool =
- return key in val.tab.map
-
const ValidBare = AsciiAlphaNumeric + {'-', '_'}
func peek(state: TomlParser; buf: openArray[char]; i: int): char =
diff --git a/test/js/config.toml b/test/js/config.toml
index 0224c241..51fefbd7 100644
--- a/test/js/config.toml
+++ b/test/js/config.toml
@@ -2,11 +2,11 @@
history = false
[[siteconf]]
-match = 'file:///.*'
+url = 'file:///.*'
scripting = true
[[siteconf]]
-match = 'file:///.*\.app\.html'
+url = 'file:///.*\.app\.html'
scripting = 'app'
[display]
diff --git a/test/js/style.html b/test/js/style.html
index dad596df..8fe5ae44 100644
--- a/test/js/style.html
+++ b/test/js/style.html
@@ -1,6 +1,6 @@
<!doctype html>
<style>
-y::before { color: blue }
+#y::before { color: blue }
</style>
<title>Style test</title>
<div id=x>Fail</div>
@@ -10,7 +10,7 @@ y::before { color: blue }
const y = document.getElementById("y");
assertEquals(y.style.cssText, "color: red; display: inline;");
assertEquals(window.getComputedStyle(y).cssText, "");
-assertEquals(window.getComputedStyle(y, "::before").color, "rgb(255, 0, 0)");
+assertEquals(window.getComputedStyle(y, "::before").color, "red");
y.remove();
document.getElementById("x").textContent = "Success";
</script>