Skip to content

Commit

Permalink
fix tests for flexgrid kwargs with new class options
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Dec 17, 2023
1 parent 2a48285 commit ed05b8d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
23 changes: 19 additions & 4 deletions src/Layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...)
Expand All @@ -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...)
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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...)
Expand Down
20 changes: 12 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,39 +319,43 @@ 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']\"")

# ---------

el = row(col = 2, sm = 9, class = "myclass")
@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']\"")

# ---------

el = cell(col = 2, sm = 9, class = "myclass")
@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) == "<div class=\"st-col col col-sm-9\"></div>"

@test cell(col = -1, sm = 9) == "<div class=\"st-col col-sm-9\"></div>"

@test htmldiv(col = 9, class = "a b c") == "<div class=\"a b c col-9\"></div>"

@test htmldiv(col = 9, class = split("a b c")) == "<div :class=\"['a','b','c','col-9']\"></div>"
end

@testset "Vue Conditionals and Iterator" begin
Expand Down

0 comments on commit ed05b8d

Please sign in to comment.