Skip to content

Commit

Permalink
fix edge cases of class handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Dec 18, 2023
1 parent aa2b634 commit 65b2f3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ end

function flexgrid_kwargs(; class = "", class! = nothing, symbol_class::Bool = true, flexgrid_mappings::Dict{Symbol,Symbol} = Dict{Symbol,Symbol}(), kwargs...)
kwargs = Dict{Symbol,Any}(kwargs...)

# support all different types of classes that vue supports: String, Expressions (Symbols), Arrays, Dicts
# todo check if vector contains only strings ...
if class! !== nothing
class = if class isa Symbol
Any[JSONText(class!) + JSONText(class)]
Any[JSONText(class!), JSONText(class)]
elseif class isa String
vcat(Any[JSONText(class!)], split(class))
vcat(JSONText(class!), split(class))
elseif class isa AbstractDict
class = LittleDict(k => JSONText(v) for (k, v) in class)
Any[JSONText(class!), class]
elseif class isa Vector
vcat([JSONText(class!)], class)
Expand All @@ -140,18 +141,15 @@ function flexgrid_kwargs(; class = "", class! = nothing, symbol_class::Bool = tr
class = if class isa Symbol
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
class = LittleDict(k => JSONText(v) for (k, v) in class)
vcat(class, classes)
elseif class isa Vector
vcat(class, classes)
else
join(pushfirst!(classes, class), ' ')
end
end

(class isa Symbol || class isa String && length(class) > 0) && (kwargs[:class] = class)

if ! symbol_class && class isa Symbol || class isa Vector || class isa AbstractDict
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ end
@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>"

@test htmldiv(col = 9, class = Dict(:myclass => "b"), class! = "test") == "<div :class=\"[test,{'myclass':b},'col-9']\"></div>"
end

@testset "Vue Conditionals and Iterator" begin
Expand Down

2 comments on commit 65b2f3d

@hhaensel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Stipple v0.27.26

Diff since v0.27.25

  • support Vectors and Dicts for class attributes
    • Vectors are no longer concatenated with ' + ' but converted to js vectors
    • Dicts can be used to switch on and off classes, e.g. cell(class = Dict(:myclass => js"myclass_on"). myclass_on needs to be part of the app variables

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/97316

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.27.26 -m "<description of version>" 65b2f3dd02add39b7fc65a9aca842cfe21f14500
git push origin v0.27.26

Please sign in to comment.