-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adrian
committed
Nov 24, 2019
1 parent
e2d3720
commit 4637f36
Showing
10 changed files
with
244 additions
and
60 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
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.21.0" | ||
version = "0.22.0" | ||
|
||
[deps] | ||
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" | ||
|
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,89 @@ | ||
module JSRenderer | ||
|
||
|
||
import Revise | ||
import Logging, FilePaths | ||
using Genie, Genie.Flax | ||
|
||
|
||
const JS_FILE_EXT = ["js.jl"] | ||
const TEMPLATE_EXT = [".flax.js", ".jl.js"] | ||
|
||
const SUPPORTED_JS_OUTPUT_FILE_FORMATS = TEMPLATE_EXT | ||
|
||
const JSString = String | ||
|
||
const NBSP_REPLACEMENT = (" "=>"!!nbsp;;") | ||
|
||
export JSString | ||
|
||
|
||
""" | ||
""" | ||
function get_template(path::String; context::Module = @__MODULE__) :: Function | ||
orig_path = path | ||
|
||
path, extension = Flax.view_file_info(path, SUPPORTED_JS_OUTPUT_FILE_FORMATS) | ||
|
||
isfile(path) || error("JS file \"$orig_path\" with extensions $SUPPORTED_JS_OUTPUT_FILE_FORMATS does not exist") | ||
|
||
extension in JS_FILE_EXT && return (() -> Base.include(context, path)) | ||
|
||
f_name = Flax.function_name(path) |> Symbol | ||
mod_name = Flax.m_name(path) * ".jl" | ||
f_path = joinpath(Genie.config.path_build, Flax.BUILD_NAME, mod_name) | ||
f_stale = Flax.build_is_stale(path, f_path) | ||
|
||
if f_stale || ! isdefined(context, func_name) | ||
f_stale && Flax.build_module(Flax.to_js(data), path, mod_name) | ||
|
||
return Base.include(context, joinpath(Genie.config.path_build, Flax.BUILD_NAME, mod_name)) | ||
end | ||
|
||
getfield(context, f_name) | ||
end | ||
|
||
|
||
""" | ||
""" | ||
@inline function to_js(data::String; prepend = "\n") :: String | ||
string("function $(Flax.function_name(data))() \n", | ||
Flax.injectvars(), | ||
prepend, | ||
"\"\"\"$data\"\"\"", | ||
"\nend \n") | ||
end | ||
|
||
|
||
""" | ||
""" | ||
function render(data::String; context::Module = @__MODULE__, vars...) :: Function | ||
Flax.registervars(vars...) | ||
|
||
data_hash = hash(data) | ||
path = "Flax_" * string(data_hash) | ||
|
||
func_name = Flax.function_name(string(data_hash)) |> Symbol | ||
mod_name = Flax.m_name(path) * ".jl" | ||
f_path = joinpath(Genie.config.path_build, Flax.BUILD_NAME, mod_name) | ||
f_stale = Flax.build_is_stale(f_path, f_path) | ||
|
||
if f_stale || ! isdefined(context, func_name) | ||
f_stale && Flax.build_module(to_js(data), path, mod_name) | ||
|
||
return Base.include(context, joinpath(Genie.config.path_build, Flax.BUILD_NAME, mod_name)) | ||
end | ||
|
||
getfield(context, func_name) | ||
end | ||
|
||
|
||
""" | ||
""" | ||
function render(viewfile::FilePaths.PosixPath; context::Module = @__MODULE__, vars...) :: Function | ||
Flax.registervars(vars...) | ||
|
||
get_template(string(viewfile), partial = false, context = context) | ||
end | ||
|
||
end |
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
Oops, something went wrong.