about summary refs log tree commit diff stats
path: root/src/css
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-03-10 15:33:31 +0100
committerbptato <nincsnevem662@gmail.com>2023-03-10 15:33:31 +0100
commit64d96d51bf6603e88d315979212e2985225a3712 (patch)
treea0276b494c39c239b43397bd018ddb7adc78ff91 /src/css
parent263c368458806d322c1ff6b46ed3b0f45afe0953 (diff)
downloadchawan-64d96d51bf6603e88d315979212e2985225a3712.tar.gz
css/values: add some stringifiers
Diffstat (limited to 'src/css')
-rw-r--r--src/css/values.nim17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/css/values.nim b/src/css/values.nim
index 5d8cc2fb..c786e47e 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -337,16 +337,25 @@ func propertyType(s: string): CSSPropertyType =
 func valueType(prop: CSSPropertyType): CSSValueType =
   return ValueTypes[prop]
 
+func `$`*(length: CSSLength): string =
+  if length.auto:
+    return "auto"
+  return $length.num & ($length.unit).split('_')[1..^1].join("_").tolower()
+
+func `$`*(content: CSSContent): string =
+  if content.s != "":
+    return "url(" & content.s & ")"
+  return "none"
+
 func `$`*(val: CSSComputedValue): string =
   result = ($val.t).toLowerAscii().split('_')[1..^1].join('-') & ": "
   case val.v
   of VALUE_COLOR:
     result &= $val.color
   of VALUE_IMAGE:
-    if val.image.s != "":
-      result &= "url(" & val.image.s & ")"
-    else:
-      result &= "none"
+    result &= $val.image
+  of VALUE_LENGTH:
+    result &= $val.length
   else: discard
 
 macro `{}`*(vals: CSSComputedValues, s: string): untyped =