From 64d96d51bf6603e88d315979212e2985225a3712 Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 10 Mar 2023 15:33:31 +0100 Subject: css/values: add some stringifiers --- src/css/values.nim | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/css') 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 = -- cgit 1.4.1-2-gfad0