Skip to content

Commit

Permalink
v0.22.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian committed Dec 4, 2019
1 parent 1c94ffd commit e604d3e
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 67 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.22.5 - 2019-12-04

* added support for `if` blocks
* performance optimisations

## v0.22.5 - 2019-12-03

* bug fixes
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Genie"
uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e"
authors = ["Adrian Salceanu <[email protected]>"]
version = "0.22.6"
version = "0.22.7"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
8 changes: 4 additions & 4 deletions src/AppServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end
Adds a signature header to the response using the value in `Genie.config.server_signature`.
If `Genie.config.server_signature` is empty, the header is not added.
"""
@inline function sign_response!(res::HTTP.Response) :: HTTP.Response
function sign_response!(res::HTTP.Response) :: HTTP.Response
headers = Dict(res.headers)
isempty(Genie.config.server_signature) || (headers["Server"] = Genie.config.server_signature)

Expand All @@ -117,7 +117,7 @@ end
Http server handler function - invoked when the server gets a request.
"""
@inline function handle_request(req::HTTP.Request, res::HTTP.Response, ip::Sockets.IPv4 = Sockets.IPv4(Genie.config.server_host)) :: HTTP.Response
function handle_request(req::HTTP.Request, res::HTTP.Response, ip::Sockets.IPv4 = Sockets.IPv4(Genie.config.server_host)) :: HTTP.Response
isempty(Genie.config.server_signature) && sign_response!(res)

try
Expand Down Expand Up @@ -159,7 +159,7 @@ end
Configures the handler for the HTTP Request and handles errors.
"""
@inline function setup_http_handler(req::HTTP.Request, res::HTTP.Response = HTTP.Response()) :: HTTP.Response
function setup_http_handler(req::HTTP.Request, res::HTTP.Response = HTTP.Response()) :: HTTP.Response
try
Distributed.@fetch handle_request(req, res)
catch ex # ex is a Distributed.RemoteException
Expand Down Expand Up @@ -189,7 +189,7 @@ end
Configures the handler for WebSockets requests.
"""
@inline function setup_ws_handler(req::HTTP.Request, ws_client) :: Nothing
function setup_ws_handler(req::HTTP.Request, ws_client) :: Nothing
while ! eof(ws_client)
write(ws_client, String(Distributed.@fetch handle_ws_request(req, String(readavailable(ws_client)), ws_client)))
end
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Core genie configuration / settings functionality.
"""
module Configuration

const GENIE_VERSION = v"0.22.6"
const GENIE_VERSION = v"0.22.7"

import Logging
import Genie
Expand Down
37 changes: 22 additions & 15 deletions src/Flax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ end
Renders a template file.
"""
@inline function template(path::String; partial::Bool = true, context::Module = @__MODULE__) :: String
function template(path::String; partial::Bool = true, context::Module = @__MODULE__) :: String
Base.invokelatest(HTMLRenderer.get_template(path, partial = partial, context = context))::String
end

Expand Down Expand Up @@ -90,15 +90,15 @@ end
Loads the rendering vars into the task's scope
"""
@inline function registervars(vars...) :: Nothing
function registervars(vars...) :: Nothing
init_task_local_storage()
task_local_storage(:__vars, merge(task_local_storage(:__vars), Dict{Symbol,Any}(vars)))

nothing
end


@inline function vars_signature() :: String
function vars_signature() :: String
task_local_storage(:__vars) |> keys |> collect |> sort |> string
end

Expand All @@ -108,7 +108,7 @@ end
Generates function name for generated Flax views.
"""
@inline function function_name(file_path::String) :: String
function function_name(file_path::String) :: String
"func_$(SHA.sha1( relpath(isempty(file_path) ? " " : file_path) * vars_signature() ) |> bytes2hex)"
end

Expand All @@ -118,7 +118,7 @@ end
Generates module name for generated Flax views.
"""
@inline function m_name(file_path::String) :: String
function m_name(file_path::String) :: String
string(SHA.sha1( relpath(isempty(file_path) ? " " : file_path) * vars_signature()) |> bytes2hex)
end

Expand All @@ -128,7 +128,7 @@ end
Converts a HTML document to a Flax document.
"""
@inline function html_to_flax(file_path::String; partial = true) :: String
function html_to_flax(file_path::String; partial = true) :: String
to_flax(file_path, parse_template, partial = partial)
end

Expand All @@ -138,7 +138,7 @@ end
Converts string view data to Flax code
"""
@inline function string_to_flax(content::String; partial = true, f_name::Union{Symbol,Nothing} = nothing, prepend = "") :: String
function string_to_flax(content::String; partial = true, f_name::Union{Symbol,Nothing} = nothing, prepend = "") :: String
to_flax(content, parse_string, partial = partial, f_name = f_name, prepend = prepend)
end

Expand All @@ -148,7 +148,7 @@ end
Converts an input file to Flax code
"""
@inline function to_flax(input::String, f::Function; partial = true, f_name::Union{Symbol,Nothing} = nothing, prepend = "\n") :: String
function to_flax(input::String, f::Function; partial = true, f_name::Union{Symbol,Nothing} = nothing, prepend = "\n") :: String
f_name = (f_name === nothing) ? function_name(string(input, partial)) : f_name

string("function $(f_name)() \n",
Expand Down Expand Up @@ -220,7 +220,7 @@ end
Parses a HTML file into Flax code.
"""
@inline function parse_template(file_path::String; partial::Bool = true) :: String
function parse_template(file_path::String; partial::Bool = true) :: String
parse(read_template_file(file_path), partial = partial)
end

Expand All @@ -230,12 +230,12 @@ end
Parses a HTML string into Flax code.
"""
@inline function parse_string(data::String; partial::Bool = true) :: String
function parse_string(data::String; partial::Bool = true) :: String
parse(parsetags(data), partial = partial)
end


@inline function parse(input::String; partial::Bool = true) :: String
function parse(input::String; partial::Bool = true) :: String
HTMLRenderer.parsehtml(input, partial = partial)
end

Expand All @@ -245,11 +245,12 @@ end
Parses special Flax tags.
"""
@inline function parsetags(line::Tuple{Int,String}) :: String
function parsetags(line::Tuple{Int,String}) :: String
parsetags(line[2])
end
@inline function parsetags(code::String) :: String
function parsetags(code::String) :: String
code = replace(code, "<%"=>"""<script type="julia/eval">""")
occursin(" if ", code) && (code = replace(code, " if "=>" Flax.@condblock if "))
replace(code, "%>"=>"""</script>""")
end

Expand All @@ -259,7 +260,7 @@ end
Generated functions that represent Flax functions definitions corresponding to HTML elements.
"""
@inline function register_elements() :: Nothing
function register_elements() :: Nothing
for elem in HTMLRenderer.NORMAL_ELEMENTS
register_normal_element(elem)
end
Expand All @@ -272,7 +273,7 @@ Generated functions that represent Flax functions definitions corresponding to H
end


@inline function register_element(elem::Union{Symbol,String}, elem_type::Union{Symbol,String} = :normal; context = Flax) :: Nothing
function register_element(elem::Union{Symbol,String}, elem_type::Union{Symbol,String} = :normal; context = Flax) :: Nothing
elem = string(elem)
occursin('-', elem) && (elem = HTMLRenderer.denormalize_element(elem))

Expand Down Expand Up @@ -335,6 +336,12 @@ macro foreach(f, arr)
end


macro condblock(expr)
expr.args[2] = esc(:([$([arg for arg in expr.args[2].args if !isa(arg, LineNumberNode)]...),]))
expr
end


register_elements()


Expand Down
34 changes: 17 additions & 17 deletions src/HTMLRenderer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ export HTMLString
Generates a HTML element in the form <...></...>
"""
@inline function normal_element(f::Function, elem::String, args = [], attrs::Vector{Pair{Symbol,Any}} = Pair{Symbol,Any}[]) :: HTMLString
function normal_element(f::Function, elem::String, args = [], attrs::Vector{Pair{Symbol,Any}} = Pair{Symbol,Any}[]) :: HTMLString
normal_element(f(), elem, args, attrs...)
end
@inline function normal_element(children::Union{String,Vector{String}}, elem::String, args, attrs::Pair{Symbol,Any}) :: HTMLString
function normal_element(children::Union{String,Vector{String}}, elem::String, args, attrs::Pair{Symbol,Any}) :: HTMLString
normal_element(children, elem, args, Pair{Symbol,Any}[attrs])
end
@inline function normal_element(children::Union{String,Vector{String}}, elem::String, args, attrs...) :: HTMLString
function normal_element(children::Union{String,Vector{String}}, elem::String, args, attrs...) :: HTMLString
normal_element(children, elem, args, Pair{Symbol,Any}[attrs...])
end
@inline function normal_element(children::Union{String,Vector{String}}, elem::String, args = [], attrs::Vector{Pair{Symbol,Any}} = Pair{Symbol,Any}[]) :: HTMLString
function normal_element(children::Union{String,Vector{String}}, elem::String, args = [], attrs::Vector{Pair{Symbol,Any}} = Pair{Symbol,Any}[]) :: HTMLString
children = join(children)
elem = normalize_element(elem)
attribs = rstrip(attributes(attrs))
string("<", elem, (isempty(attribs) ? "" : " $attribs"), (isempty(args) ? "" : " $(join(args, " "))"), ">", prepare_template(children), "</", elem, ">")
end
@inline function normal_element(elem::String, attrs::Vector{Pair{Symbol,Any}} = Pair{Symbol,Any}[]) :: HTMLString
function normal_element(elem::String, attrs::Vector{Pair{Symbol,Any}} = Pair{Symbol,Any}[]) :: HTMLString
normal_element("", elem, attrs...)
end
@inline function normal_element(elems::Vector, elem::String, args = [], attrs...) :: HTMLString
function normal_element(elems::Vector, elem::String, args = [], attrs...) :: HTMLString
io = IOBuffer()

for e in elems
Expand All @@ -74,7 +74,7 @@ end

normal_element(String(take!(io)), elem, args, attrs...)
end
@inline function normal_element(_::Nothing, __::Any) :: HTMLString
function normal_element(_::Nothing, __::Any) :: HTMLString
""
end

Expand All @@ -85,10 +85,10 @@ end
Cleans up the template before rendering (ex by removing empty nodes).
"""
@inline function prepare_template(s::String) :: String
function prepare_template(s::String) :: String
s
end
@inline function prepare_template(v::Vector{T})::String where {T}
function prepare_template(v::Vector{T})::String where {T}
filter!(v) do (x)
! isa(x, Nothing)
end
Expand Down Expand Up @@ -118,10 +118,10 @@ end
Cleans up problematic characters or DOM elements.
"""
@inline function normalize_element(elem::String)
function normalize_element(elem::String)
replace(string(lowercase(elem)), "_____"=>"-")
end
@inline function denormalize_element(elem::String)
function denormalize_element(elem::String)
replace(string(lowercase(elem)), "-"=>"_____")
end

Expand All @@ -131,7 +131,7 @@ end
Generates a void HTML element in the form <...>
"""
@inline function void_element(elem::String, args = [], attrs::Vector{Pair{Symbol,Any}} = Pair{Symbol,Any}[]) :: HTMLString
function void_element(elem::String, args = [], attrs::Vector{Pair{Symbol,Any}} = Pair{Symbol,Any}[]) :: HTMLString
attribs = rstrip(attributes(attrs))
string("<", normalize_element(elem), (isempty(attribs) ? "" : " $attribs"), (isempty(args) ? "" : " $(join(args, " "))"), ">")
end
Expand All @@ -143,10 +143,10 @@ end
Cleans up empty elements.
"""
@inline function skip_element(f::Function) :: HTMLString
function skip_element(f::Function) :: HTMLString
"$(prepare_template(f()))"
end
@inline function skip_element() :: HTMLString
function skip_element() :: HTMLString
""
end

Expand Down Expand Up @@ -215,18 +215,18 @@ end
"""
Outputs document's doctype.
"""
@inline function doctype(doctype::Symbol = :html) :: HTMLString
function doctype(doctype::Symbol = :html) :: HTMLString
"<!DOCTYPE $doctype>"
end


"""
Outputs document's doctype.
"""
@inline function doc(html::String) :: HTMLString
function doc(html::String) :: HTMLString
doctype() * "\n" * html
end
@inline function doc(doctype::Symbol, html::String) :: HTMLString
function doc(doctype::Symbol, html::String) :: HTMLString
doctype(doctype) * "\n" * html
end

Expand Down
2 changes: 1 addition & 1 deletion src/JSRenderer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end

"""
"""
@inline function to_js(data::String; prepend = "\n") :: String
function to_js(data::String; prepend = "\n") :: String
string("function $(Flax.function_name(data))() \n",
Flax.injectvars(),
prepend,
Expand Down
Loading

2 comments on commit e604d3e

@essenciary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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 Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.22.7 -m "<description of version>" e604d3ef36ad72e90bc75a1ba2dec7501d277e62
git push origin v0.22.7

Please sign in to comment.