-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use "load" not "template_from_file" or "render_from_file" (#118)
* use "load" not "template_from_file" or "render_from_file" * dont deprecate; reorganize code
- Loading branch information
Showing
6 changed files
with
121 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
render([io], tokens, view) | ||
Render a set of tokens with a view, using optional `io` object to print or store. | ||
Arguments | ||
--------- | ||
* `io::IO`: Optional `IO` object. | ||
* `tokens`: Either Mustache tokens, or a string to parse into tokens | ||
* `view`: A view provides a context to look up unresolved symbols | ||
demarcated by mustache braces. A view may be specified by a | ||
dictionary, a module, a composite type, a vector, a named tuple, a | ||
data frame, a `Tables` object, or keyword arguments. | ||
""" | ||
function render(io::IO, tokens::MustacheTokens, view) | ||
_writer = Writer() | ||
render(io, _writer, tokens, view) | ||
end | ||
function render(io::IO, tokens::MustacheTokens; kwargs...) | ||
render(io, tokens, kwargs) | ||
end | ||
|
||
render(tokens::MustacheTokens, view) = sprint(io -> render(io, tokens, view)) | ||
render(tokens::MustacheTokens; kwargs...) = sprint(io -> render(io, tokens, Dict(kwargs...))) | ||
|
||
## Exported call without first parsing tokens via mt"literal" | ||
## | ||
## @param template a string containing the template for expansion | ||
## @param view a Dict, Module, CompositeType, DataFrame holding variables for expansion | ||
function render(io::IO, template::AbstractString, view; tags= ("{{", "}}")) | ||
_writer = Writer() | ||
render(io, _writer, parse(template, tags), view) | ||
end | ||
function render(io::IO, template::AbstractString; kwargs...) | ||
_writer = Writer() | ||
render(io, _writer, parse(template), Dict(kwargs...)) | ||
end | ||
render(template::AbstractString, view; tags=("{{", "}}")) = sprint(io -> render(io, template, view, tags=tags)) | ||
render(template::AbstractString; kwargs...) = sprint(io -> render(io, template, Dict(kwargs...))) | ||
|
||
|
||
# Exported, but should be deprecated.... | ||
""" | ||
render_from_file(filepath, view) | ||
render_from_file(filepath; kwargs...) | ||
Renders a template from `filepath` and `view`. | ||
""" | ||
render_from_file(filepath, view) = render(Mustache.load(filepath), view) | ||
render_from_file(filepath::AbstractString; kwargs...) = render(Mustache.load(filepath); kwargs...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
07d4d44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
07d4d44
There was a problem hiding this comment.
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/20384
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: