Skip to content

Commit

Permalink
fixing isempty hfun
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Sep 16, 2021
1 parent 7fddc79 commit 13fa169
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Franklin"
uuid = "713c75ef-9fc9-4b05-94a9-213340da978e"
authors = ["Thibaut Lienart <[email protected]>"]
version = "0.10.53"
version = "0.10.54"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
2 changes: 1 addition & 1 deletion docs/syntax/page-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ You can also use some dedicated conditional blocks:
| `{{isnotpage path/to/page}}` | opposite of previous
| `{{isdef vname}}` | whether `vname` is defined
| `{{isnotdef vname}}` | opposite of previous
| `{{isempty vname}}`| whether `vname` is empty
| `{{isempty vname}}`| whether `vname` is nothing, empty, or if a date `0001-01-01`
| `{{isnotempty vname}}`| opposite of previous
@@

Expand Down
8 changes: 7 additions & 1 deletion src/converter/html/blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function process_html_cond(hs::AS, qblocks::Vector{AbstractBlock},
k ⊻= βi isa HIsNotDef
elseif βi isa Union{HIsEmpty, HIsNotEmpty}
v = locvar(βi.vname)
e = isnothing(v) || isempty(v)
e = _isempty(v)
k = ifelse(βi isa HIsEmpty, e, !e)
end
else
Expand Down Expand Up @@ -154,6 +154,12 @@ function process_html_cond(hs::AS, qblocks::Vector{AbstractBlock},
return content, head, i_close
end

# used for the HIsEmpty, HIsNotEmpty
_isempty(v::T) where T = hasmethod(isempty, (T,)) ? isempty(v) : false
_isempty(::Nothing) = true
_isempty(v::Date) = (v == Date(1,1,1))


"""
$SIGNATURES
Expand Down
13 changes: 13 additions & 0 deletions test/converter/html/html_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ end
# must end with html
@test_throws F.HTMLFunctionError ("{{redirect foo}}" |> fd2html)
end

@testset "isempty" begin
s = """
+++
using Dates
d = Date(1,1,1)
x = nothing
+++
{{isempty d}}A{{end}}
{{isempty x}}B{{end}}
""" |> fd2html_td
@test isapproxstr(s, "<p>AB</p>")
end

2 comments on commit 13fa169

@tlienart
Copy link
Owner Author

Choose a reason for hiding this comment

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

@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/44968

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.10.54 -m "<description of version>" 13fa1694a85a81805e75c9cb3a6fc562e9614525
git push origin v0.10.54

Please sign in to comment.