normal_element(f::Function, elem::String, attrs::Vector{Pair{Symbol,Any}} = Pair{Symbol,Any}[]) :: HTMLString
Generates a HTML element in the form <...></...>
prepare_template(s::String)
prepare_template{T}(v::Vector{T})
Cleans up the template before rendering (ex by removing empty nodes).
attributes(attrs::Vector{Pair{Symbol,String}} = Vector{Pair{Symbol,String}}()) :: Vector{String}
Parses HTML attributes.
parseattr(attr) :: String
Converts Julia keyword arguments to HTML attributes with illegal Julia chars.
denormalize_element(elem::String)
Replaces -
with the char defined to replace dashes, as Julia does not support them in names.
void_element(elem::String, attrs::Vector{Pair{Symbol,String}} = Vector{Pair{Symbol,String}}()) :: HTMLString
Generates a void HTML element in the form <...>
get_template(path::String; partial::Bool = true, context::Module = @__MODULE__, vars...) :: Function
Resolves the inclusion and rendering of a template file
parseview(data::String; partial = false, context::Module = @__MODULE__) :: Function
Parses a view file, returning a rendering function. If necessary, the function is JIT-compiled, persisted and loaded into memory.
render(data::String; context::Module = @__MODULE__, layout::Union{String,Nothing} = nothing, vars...) :: Function
Renders the string as an HTML view.
render(viewfile::Genie.Renderer.FilePath; layout::Union{Nothing,Genie.Renderer.FilePath} = nothing, context::Module = @__MODULE__, vars...) :: Function
Renders the template file as an HTML view.
html(data::String; context::Module = @__MODULE__, status::Int = 200, headers::HTTPHeaders = HTTPHeaders(), layout::Union{String,Nothing} = nothing, vars...) :: HTTP.Response
Parses the data
input as HTML, returning a HTML HTTP Response.
Arguments
data::String
: the HTML string to be renderedcontext::Module
: the module in which the variables are evaluated (in order to provide the scope for vars). Usually the controller.status::Int
: status code of the responseheaders::HTTPHeaders
: HTTP response headerslayout::Union{String,Nothing}
: layout file for renderingdata
Example
julia> html("<h1>Welcome $(vars(:name))</h1>", layout = "<div><% @yield %></div>", name = "Adrian")
HTTP.Messages.Response:
"
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
<html><head></head><body><div><h1>Welcome Adrian</h1>
</div></body></html>"
html(md::Markdown.MD; context::Module = @__MODULE__, status::Int = 200, headers::Genie.Renderer.HTTPHeaders = Genie.Renderer.HTTPHeaders(), layout::Union{String,Nothing} = nothing, forceparse::Bool = false, vars...) :: Genie.Renderer.HTTP.Response
Markdown view rendering
html(viewfile::FilePath; layout::Union{Nothing,FilePath} = nothing,
context::Module = @__MODULE__, status::Int = 200, headers::HTTPHeaders = HTTPHeaders(), vars...) :: HTTP.Response
Parses and renders the HTML viewfile
, optionally rendering it within the layout
file. Valid file format is .html.jl
.
Arguments
viewfile::FilePath
: filesystem path to the view file as aRenderer.FilePath
, ieRenderer.filepath("/path/to/file.html.jl")
orpath"/path/to/file.html.jl"
layout::FilePath
: filesystem path to the layout file as aRenderer.FilePath
, ieRenderer.FilePath("/path/to/file.html.jl")
orpath"/path/to/file.html.jl"
context::Module
: the module in which the variables are evaluated (in order to provide the scope for vars). Usually the controller.status::Int
: status code of the responseheaders::HTTPHeaders
: HTTP response headers
safe_attr(attr) :: String
Replaces illegal Julia characters from HTML attributes with safe ones, to be used as keyword arguments.
html_to_julia(file_path::String; partial = true) :: String
Converts a HTML document to Julia code.
string_to_julia(content::String; partial = true, f_name::Union{Symbol,Nothing} = nothing, prepend = "") :: String
Converts string view data to Julia code
to_julia(input::String, f::Function; partial = true, f_name::Union{Symbol,Nothing} = nothing, prepend = "") :: String
Converts an input file to Julia code
partial(path::String; context::Module = @__MODULE__, vars...) :: String
Renders (includes) a view partial within a larger view or layout file.
template(path::String; partial::Bool = true, context::Module = @__MODULE__, vars...) :: String
Renders a template file.
parse_template(file_path::String; partial = true) :: String
Parses a HTML file into Julia code.
register_elements() :: Nothing
Generated functions that represent Julia functions definitions corresponding to HTML elements.
register_element(elem::Union{Symbol,String}, elem_type::Union{Symbol,String} = :normal; context = @__MODULE__) :: Nothing
Generates a Julia function representing an HTML element.
register_normal_element(elem::Union{Symbol,String}; context = @__MODULE__) :: Nothing
Generates a Julia function representing a "normal" HTML element: that is an element with a closing tag, <tag>...</tag>
register_void_element(elem::Union{Symbol,String}; context::Module = @__MODULE__) :: Nothing
Generates a Julia function representing a "void" HTML element: that is an element without a closing tag, <tag />
for_each(f::Function, v)
Iterates over the v
Vector and applies function f
for each element. The results of each iteration are concatenated and the final string is returned.
collection(template::Function, collection::Vector{T})::String where {T}
Creates a view fragment by repeateadly applying a function to each element of the collection.
serve_error_file(error_code::Int, error_message::String = "", params::Dict{Symbol,Any} = Dict{Symbol,Any}()) :: Response
Serves the error file correspoding to error_code
and current environment.