From ed05b8d22cfe215dfa4cb7efa6e296372298afcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20H=C3=A4nsel?= Date: Sun, 17 Dec 2023 23:27:18 +0100 Subject: [PATCH] fix tests for flexgrid kwargs with new class options --- src/Layout.jl | 23 +++++++++++++++++++---- test/runtests.jl | 20 ++++++++++++-------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/Layout.jl b/src/Layout.jl index cb5eaa4c..1fdd0ea6 100644 --- a/src/Layout.jl +++ b/src/Layout.jl @@ -141,6 +141,7 @@ function flexgrid_kwargs(; class = "", class! = nothing, symbol_class::Bool = tr vcat([JSONText(class)], classes) elseif class isa AbstractDict T = first(typeof(class).parameters) + class = convert(Dict{T, Any}, class) for c in classes push!(class, T(c) => true) end @@ -165,6 +166,19 @@ function flexgrid_kwargs(; class = "", class! = nothing, symbol_class::Bool = tr return kwargs end +function append_class(class, subclass) + subclass isa Symbol && (subclass = JSONText(subclass)) + if class isa Symbol + [JSONText(class), subclass] + elseif class isa String + subclass isa String ? join(push!(split(class), subclass), " ") : vcat(split(class), [subclass]) + elseif class isa Vector + vcat(class, [subclass]) + else # Dict + [class, subclass] + end +end + """ function row(args...; size=-1, xs=-1, sm=-1, md=-1, lg=-1, xl=-1, kwargs...) @@ -188,7 +202,8 @@ function row(args...; # for backward compatibility with `size` kwarg col == -1 && size != -1 && (col = size) - class = class isa Symbol ? Symbol("$class + ' row'") : class isa Vector ? push!(class, "row") : join(push!(split(class), "row"), " ") + # class = class isa Symbol ? Symbol("$class + ' row'") : class isa Vector ? push!(class, "row") : join(push!(split(class), "row"), " ") + class = append_class(class, "row") kwargs = Stipple.attributes(flexgrid_kwargs(; class, col, xs, sm, md, lg, xl, symbol_class = false, kwargs...)) Genie.Renderer.Html.div(args...; kwargs...) @@ -217,8 +232,7 @@ function column(args...; # for backward compatibility with `size` kwarg col == -1 && size != -1 && (col = size) - - class = class isa Symbol ? Symbol("$class + ' column'") : join(push!(split(class), "column"), " ") + class = append_class(class, "column") kwargs = Stipple.attributes(flexgrid_kwargs(; class, col, xs, sm, md, lg, xl, symbol_class = false, kwargs...)) Genie.Renderer.Html.div(args...; kwargs...) @@ -261,7 +275,8 @@ function cell(args...; # for backward compatibility with `size` kwarg col == 0 && size != 0 && (col = size) - class = class isa Symbol ? Symbol("$class + ' st-col'") : join(push!(split(class), "st-col"), " ") + # class = class isa Symbol ? Symbol("$class + ' st-col'") : join(push!(split(class), "st-col"), " ") + class = append_class(class, "st-col") kwargs = Stipple.attributes(flexgrid_kwargs(; class, col, xs, sm, md, lg, xl, symbol_class = false, kwargs...)) Genie.Renderer.Html.div(args...; kwargs...) diff --git a/test/runtests.jl b/test/runtests.jl index d2d3d9fe..40c2eed8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -319,13 +319,13 @@ end @test contains(el, "class=\"myclass column col-2 col-sm-9") el = column(col = 2, sm = 9, class = :myclass) - @test contains(el, r":class=\"myclass \+ .*column.* col-2 col-sm-9'") + @test contains(el, ":class=\"[myclass,'column','col-2','col-sm-9']\"") el = column(col = 2, sm = 9, class! = "myclass") - @test contains(el, r":class=\"myclass \+ .*column.* col-2 col-sm-9'") + @test contains(el, ":class=\"[myclass,'column','col-2','col-sm-9']\"") el = column(col = 2, sm = 9, class! = :myclass) - @test contains(el, r":class=\"myclass \+ .*column.* col-2 col-sm-9'") + @test contains(el, ":class=\"[myclass,'column','col-2','col-sm-9']\"") # --------- @@ -333,10 +333,10 @@ end @test contains(el, "class=\"myclass row col-2 col-sm-9") el = row(col = 2, sm = 9, class = :myclass) - @test contains(el, r":class=\"myclass \+ .*row.* col-2 col-sm-9'") - + @test contains(el, ":class=\"[myclass,'row','col-2','col-sm-9']\"") + el = row(col = 2, sm = 9, class! = "myclass") - @test contains(el, r":class=\"myclass \+ .*row.* col-2 col-sm-9'") + @test contains(el, ":class=\"[myclass,'row','col-2','col-sm-9']\"") # --------- @@ -344,14 +344,18 @@ end @test contains(el, "class=\"myclass st-col col-2 col-sm-9") el = cell(col = 2, sm = 9, class = :myclass) - @test contains(el, r":class=\"myclass \+ .*st-col.* col-2 col-sm-9'") + @test contains(el, ":class=\"[myclass,'st-col','col-2','col-sm-9']\"") el = column(col = 2, sm = 9, class! = "myclass") - @test contains(el, r":class=\"myclass \+ .*column.* col-2 col-sm-9'") + @test contains(el, ":class=\"[myclass,'column','col-2','col-sm-9']\"") @test cell(sm = 9) == "
" @test cell(col = -1, sm = 9) == "
" + + @test htmldiv(col = 9, class = "a b c") == "
" + + @test htmldiv(col = 9, class = split("a b c")) == "
" end @testset "Vue Conditionals and Iterator" begin