Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core Components Integration #131

Merged
merged 11 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Manifest.toml
docs/build
venv
*.pyc
tmp
tmp
gen_resources/build
6 changes: 6 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[dash_resources]
git-tree-sha1 = "c857e355d2c21dfc458fb315371431dda2506109"

[[dash_resources.download]]
sha256 = "4ff3910a8ff1f5420784397cfc6ad80341bbe03f1010eab38dcb9b8ce2423310"
url = "https://github.com/waralex/DashCoreResources/releases/download/v2.0.0+0/DashCoreResources.v2.0.0.tar.gz"
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Dash"
uuid = "1b08a953-4be3-4667-9a23-3db579824955"
authors = ["Chris Parmer <chris@plotly.com>", "Alexandr Romanenko <waralex@gmail.com>"]
version = "0.1.6"
version = "1.0.0"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Expand All @@ -14,10 +14,12 @@ HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
MD5 = "6ac74813-4b46-53a4-afec-0b5dc9d7885c"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
CodecZlib = "0.6, 0.7"
Expand All @@ -31,7 +33,7 @@ JSON = "0.21"
JSON2 = "0.3"
MD5 = "0.2"
PlotlyBase = "0.8.5, 0.8.6"
julia = "1.2"
julia = "1.3"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
13 changes: 13 additions & 0 deletions gen_resources/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[deps]
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
GitHub = "bc5e4493-9b4d-5f90-b8aa-2b2bcaad7a26"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
ghr_jll = "07c12ed4-43bc-5495-8a2a-d5838ef8d533"
24 changes: 24 additions & 0 deletions gen_resources/Sources.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[deploy]
repo = "waralex/DashCoreResources"
[dash]
url = "https://github.com/plotly/dash.git"
tag = "v2.0.0"
[dash_renderer]
module = "dash_renderer"
resources_path = "."
[components]
[components.dash_html_components]
module = "dash.html"
prefix = "html"
resources_path = ".."
metadata_file = "metadata.json"
[components.dash_core_components]
module = "dash.dcc"
prefix = "dcc"
resources_path = ".."
metadata_file = "metadata.json"
[components.dash_table]
module = "dash.dash_table"
prefix = "dash"
resources_path = ".."
metadata_file = "metadata.json"
21 changes: 21 additions & 0 deletions gen_resources/generate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import TOML
using OrderedCollections
using Conda
using PyCall
import YAML
using Pkg.Artifacts
import GitHub
import GitHub: gh_get_json, DEFAULT_API
using HTTP
import JSON
using ghr_jll

include("generator/generator.jl")

sources = TOML.parsefile(joinpath(@__DIR__, "Sources.toml"))

build_dir = joinpath(@__DIR__, "build")

artifact_file = joinpath(@__DIR__, "..", "Artifacts.toml")

generate(ARGS, sources, build_dir, artifact_file)
188 changes: 188 additions & 0 deletions gen_resources/generator/components.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
using JSON3
function process_components_meta(metafile)
metadata = JSON3.read(
read(metafile, String)
)
result = []
for (file, props) in metadata
name = split(split(string(file), "/")[end], ".")[1]
push!(result, make_component_meta(name, props))
end
return result
end

function make_component_meta(name, props)
args = filter(filter_arg, props["props"])
regular_args = filter(collect(keys(args))) do name
!endswith(string(name), "-*")
end
wild_args =
filter(collect(keys(args))) do name
endswith(string(name), "-*")
end
return OrderedDict(
:name => Symbol(name),
:args => regular_args,
:wild_args => [Symbol(replace(string(a), "-*"=>"")) for a in wild_args],
:docstr => docstring(name, args, props["description"]),
)
end


const _reserwed_words = Set(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const _reserwed_words = Set(
const _reserved_words = Set(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed in dbf86ff

["baremodule",
"begin",
"break",
"catch",
"const",
"continue",
"do",
"else",
"elseif",
"end",
"export",
"false",
"finally",
"for",
"function",
"global",
"if",
"import",
"let",
"local",
"macro",
"module",
"quote",
"return",
"struct",
"true",
"try",
"using",
"while"]
)
function is_reserved_world(w)
return w in _reserwed_words
end

function filter_arg(argpair)
name, props = argpair
is_reserved_world(name) && return false
if haskey(props, "type")
arg_type = props["type"]["name"]
return !in(arg_type, ["func", "symbol", "instanceOf"])
end
if "flowType" in props
arg_type_name = props["flowType"]["name"]
if arg_type_name == "signature"
# This does the same as the PropTypes filter above, but "func"
# is under "type" if "name" is "signature" vs just in "name"
if !in("type", props["FlowType"]) || props["FlowType"]["type"] != "object"
return false
end
end
return true
end
return false
end

function docstring(name, props, description)
article = lowercase(first(name)) in ['a', 'e', 'i', 'o', 'u'] ? "An " : "A "
result = string(
article, name, " component", "\n",
description, "\n\n"
)
if haskey(props, :children)
result *= arg_docstring("children", props[:children]) * "\n"
end
if haskey(props, :id)
result *= arg_docstring("id", props[:id]) * "\n"
end
other_props = sort(
collect(filter(v->!in(v.first, [:children, :id]), props)),
lt = (a, b) -> a[1] < b[1]
)
result *= join(arg_docstring.(other_props), "\n")
return result

end

_jl_type(::Val{:array}, type_object) = "Array"
_jl_type(::Val{:bool}, type_object) = "Bool"
_jl_type(::Val{:string}, type_object) = "String"
_jl_type(::Val{:object}, type_object) = "Dict"
_jl_type(::Val{:any}, type_object) = "Bool | Real | String | Dict | Array"
_jl_type(::Val{:element}, type_object) = "dash component"
_jl_type(::Val{:node}, type_object) = "a list of or a singular dash component, string or number"

_jl_type(::Val{:enum}, type_object) = join(
string.(
getindex.(type_object["value"], :value)
), ", "
)

function _jl_type(::Val{:union}, type_object)
join(
filter(a->!isempty(a), jl_type.(type_object["value"])),
" | "
)
end

function _jl_type(::Val{:arrayOf}, type_object)
result = "Array"
if type_object["value"] != ""
result *= string(" of ", jl_type(type_object["value"]), "s")
end
return result
end

_jl_type(::Val{:objectOf}, type_object) =
string("Dict with Strings as keys and values of type ", jl_type(type_object["value"]))

function _jl_type(::Val{:shape}, type_object)
child_names = join(string.(keys(type_object["value"])), ", ")
result = "lists containing elements $(child_names)"
result *= join(
[
arg_docstring(name, prop, prop["required"], get(prop, "description", ""), 1)
for (name, prop) in type_object["value"]
]
)
return result
end
_jl_type(::Val{:exact}, type_object) = _jl_type(Val(:shape), type_object)
_jl_type(val, type_object) = ""


jl_type(type_object) = _jl_type(Val(Symbol(type_object["name"])), type_object)

arg_docstring(name_prop::Pair, indent_num = 0) = arg_docstring(name_prop[1], name_prop[2], indent_num)
arg_docstring(name, prop, indent_num = 0) =
arg_docstring(
string(name),
haskey(prop, "type") ? prop["type"] : prop["flowType"],
prop["required"],
prop["description"],
indent_num
)

function arg_docstring(prop_name, type_object, required, description, indent_num)
typename = jl_type(type_object)
indent_spacing = repeat(" ", indent_num)
if occursin("\n", typename)
return string(
indent_spacing, "- `", prop_name, "` ",
"(", required ? "required" : "optional", "):",
description, ". ",
prop_name, " has the following type: ", typename
)
end

return string(
indent_spacing, "- `", prop_name, "` ",
"(",
isempty(typename) ? "" : string(typename, "; "),
required ? "required" : "optional",
")",
isempty(description) ? "" : string(": ", description)
)
end
Loading