Skip to content

Commit

Permalink
adding Joker (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart authored Nov 27, 2019
1 parent d133aed commit e52393a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/converter/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ function process_html_qblocks(hs::AS, allvars::PageVars, qblocks::Vector{Abstrac
end


function match_url(base::AS, cand::AS)
endswith(cand, "/*") && return startswith(base, cand[1:prevind(cand, lastindex(cand))])
return splitext(cand)[1] == base
end


"""
$SIGNATURES
Expand Down Expand Up @@ -159,13 +165,16 @@ function process_html_cond(hs::AS, allvars::PageVars, qblocks::Vector{AbstractBl
elseif βi isa HIsNotDef
k = Int(!haskey(allvars, βi.vname))
else
# HIsPage//HIsNotPage
#
# current path is relative to /src/ for instance
# /src/pages/blah.md -> pages/blah
# if starts with `pages/`, replaces by `pub/`: pages/blah => pub/blah
rpath = splitext(unixify(JD_ENV[:CUR_PATH]))[1]
rpath = replace(rpath, Regex("^pages") => "pub")

# compare with β.pages
inpage = any(p -> splitext(p)[1] == rpath, βi.pages)
inpage = any(p -> match_url(rpath, p), βi.pages)

if βi isa HIsPage
k = Int(inpage)
Expand Down
9 changes: 8 additions & 1 deletion test/converter/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ end
@test "{{if b2}} {{ else }} blih {{ end }}" |> jdc == " " # if, empty
end


@testset "Cond ispage" begin
allvars = J.PageVars()

Expand All @@ -114,4 +113,12 @@ end

J.JD_ENV[:CUR_PATH] = "index.md"
@test J.convert_html(hs, allvars) == "Some text then blah but\n blih done.\n"

J.JD_ENV[:CUR_PATH] = "blah/blih.md"
hs = raw"""
A then {{ispage blah/*}}yes{{end}} but not {{isnotpage blih/*}}no{{end}} E.
"""
@test J.convert_html(hs, allvars) == "A then yes but not no E.\n"

J.JD_ENV[:CUR_PATH] = "index.md"
end

0 comments on commit e52393a

Please sign in to comment.