Skip to content

Commit

Permalink
Custom content (#521)
Browse files Browse the repository at this point in the history
* allow configuring div-content

* bringing in Jun's changes

* forgot to push a basic test

Co-authored-by: Jun Tian <[email protected]>
  • Loading branch information
tlienart and findmyway authored Jun 11, 2020
1 parent ed3e665 commit 21102ca
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 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.8.2"
version = "0.8.3"

This comment has been minimized.

Copy link
@tlienart

tlienart Jun 11, 2020

Author Owner

[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

1 comment on commit 21102ca

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

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.8.3 -m "<description of version>" 21102ca36db951dcc0c9669e7d1e4fb177dd7885
git push origin v0.8.3

Please sign in to comment.