From 6b53ababecdba0c13a79601e0876fdd51df29c25 Mon Sep 17 00:00:00 2001 From: Julien Verneuil Date: Tue, 3 May 2016 18:33:23 +0200 Subject: [PATCH] make format_attrs function for CoreAttrs assemble classes and styles into a single attribute for each one --- web/CXM_making_a_web_site.anubis | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index 4dd5cb0..4083b3b 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -2954,7 +2954,6 @@ public define String ( List(CoreAttrs) attributs ). - public define String format_extra_operands @@ -3238,7 +3237,7 @@ define Printable_tree . format(t)] }. -public define String + public define String format_attrs ( List(CoreAttrs) attributs @@ -3297,15 +3296,15 @@ define String if length(classes) = 0 then "" else " class=\""+join(" ",classes)+"\""+ if length(styles) = 0 then "" else " style=\""+join(";",styles)+"\"", [h . t] then - with current = if h is + with new_classes = if h is class(class_name) then [class_name. classes] else classes, + new_styles = if h is style(style_string) then [style_string . styles] else styles, + current = if h is { id(id_name) then " id=\"" + id_name + "\"", - class(class_name) then - format_attrs(t, [class_name. classes], styles), - style(style_string) then - format_attrs(t, classes, [style_string . styles]), - title(title_string) then + class(class_name) then "", + style(style_string) then "", + title(title_string) then " title=\"" + title_string + "\"", lang(lang) then @@ -3336,10 +3335,66 @@ define String define String format_attrs ( + List(CoreAttrs) attributs, + List(String) classes, + List(String) styles + )= + if attributs is + { + [] then + (if length(classes) = 0 then "" else " class=\""+join(" ",classes)+"\"")+ + if length(styles) = 0 then "" else " style=\""+join(";",styles)+"\"", + [h . t] then + with new_classes = if h is class(class_name) then [class_name. classes] else classes, + new_styles = if h is style(style_string) then [style_string . styles] else styles, + current = if h is + { + id(id_name) then + " id=\"" + id_name + "\"", + class(class_name) then "", + style(style_string) then "", + title(title_string) then + " title=\"" + title_string + "\"", + + lang(lang) then + " xml:lang=" + lang, + dir(reading_Way) then + if reading_Way is + { + ltr then " dir=ltr", + rtl then " dir=rtl" + }, + + accesskey(key) then + " accesskey=\"" + key + "\"", + tabindex(index) then + " tabindex=\"" + index + "\"", + + attr(name, value) then + " " + name + "=\"" + value + "\"", + + event(e, value) then + " " + event_name(e) + "=\"" + value + "\"", + data(name, value) then + " data-" + to_lower(name) + "=\"" + value + "\"", + }, + current + format_attrs(t, new_classes, new_styles) + }. + +define String + format_attrs + ( List(InputAttrs) attributs )= format_attrs(attributs, [], []). +public define String + format_attrs + ( + List(CoreAttrs) attributs + )= + format_attrs(attributs, [], []). + define String format_text_options ( -- libgit2 0.21.4