Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom content #521

Merged
merged 4 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.8.2"
version = "0.8.3"

[deps]
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Expand Down
4 changes: 3 additions & 1 deletion src/converter/markdown/tags.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ that the user has to modify it. This will help users transition when they may
have used a template that did not define `_layout/tag.html`.
"""
function write_default_tag_layout()::Nothing
dc = globvar("div_content")
dc = ifelse(isempty(dc), globvar("content_class"), dc)
html = """
<!doctype html>
<html lang="en">
Expand All @@ -118,7 +120,7 @@ function write_default_tag_layout()::Nothing
<title>Tag: {{fill fd_tag}}</title>
</head>
<body>
<div class="{{div_content}} tagpage">
<div class="$dc tagpage">
{{taglist}}
</div>
</body>
Expand Down
20 changes: 17 additions & 3 deletions src/manager/file_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function write_page(root::String, file::String, head::String,
# f1/blah/page1.md or index.md etc... this is useful in the code evaluation
# and management of paths
set_cur_rpath(fpath)
# conversion
# conversion
content = convert_md(read(fpath, String))

# Check if should add item
Expand Down Expand Up @@ -230,8 +230,22 @@ $(SIGNATURES)

Convenience function to assemble the html out of its parts.
"""
build_page(head::String, content::String, pgfoot::String, foot::String) =
head * html_div(locvar("div_content"), content * pgfoot) * foot
function build_page(head, content, pgfoot, foot)
# (legacy support) if div_content is offered explicitly, it takes
# precedence
dc = globvar("div_content")
if isempty(dc)
content_tag = globvar("content_tag")
content_class = globvar("content_class")
content_id = globvar("content_id")
else
content_tag = "div"
content_class = dc
content_id = ""
end
return head * html_content(content_tag, content * pgfoot;
class=content_class, id=content_id) * foot
end


"""
Expand Down
9 changes: 7 additions & 2 deletions src/utils/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
attr(name::Symbol, val::AS) = ifelse(isempty(val), "", " $name=\"$val\"")

"""Convenience function for a sup item."""
html_sup(id::String, in::AS) = "<sup id=\"$id\">$in</sup>"
html_sup(id::String, in::AS) = "<sup id=\"$id\">$in</sup>"

"""Convenience function for a header."""
html_hk(hk::String, t::AS; id::String="") = "<$hk$(attr(:id, id))>$t</$hk>"
html_hk(hk::String, t::AS; id::String="", class::String="") =
"<$hk$(attr(:id, id))>$t</$hk>"

"""Convenience function for content tagging (see `build_page`)"""
html_content(tag::String, content::AS; class::String, id::String) =
"<$tag$(attr(:class, class))$(attr(:id, id))>$content</$tag>"

"""Convenience function to introduce a hyper reference."""
function html_ahref(link::AS, name::Union{Int,AS};
Expand Down
6 changes: 5 additions & 1 deletion src/utils/vars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ const GLOBAL_VARS_DEFAULT = [
"website_url" => Pair("", (String,)),
"generate_rss" => Pair(true, (Bool,)),
# div names
"div_content" => Pair("franklin-content", (String,)),
"content_tag" => Pair("div", (String,)),
"content_class" => Pair("franklin-content", (String,)),
"content_id" => Pair("", (String,)),
# auto detection of code / math (see hasmath/hascode)
"autocode" => Pair(true, (Bool,)),
"automath" => Pair(true, (Bool,)),
# keep track page=>tags and tag=>pages
"fd_page_tags" => Pair(nothing, (DTAG, Nothing)),
"fd_tag_pages" => Pair(nothing, (DTAGI, Nothing)),
# LEGACY
"div_content" => Pair("", (String,)), # see build_page
]

"""
Expand Down
5 changes: 5 additions & 0 deletions test/utils/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ end
a = randn()
b = a + 5</code></pre>"""
end

@testset "html_content" begin
h = F.html_content("div", "foo bar"; class="container", id="body")
@test h == "<div class=\"container\" id=\"body\">foo bar</div>"
end