13
13
from ._all_keywords import julia_keywords
14
14
from ._py_components_generation import reorder_props
15
15
16
+ # uuid of DashBase Julia package.
17
+ jl_dash_base_uuid = "03207cf0-e2b3-4b91-9ca8-690cf0fb507e"
18
+
16
19
# uuid of Dash Julia package. Used as base for component package uuid
17
20
jl_dash_uuid = "1b08a953-4be3-4667-9a23-3db579824955"
18
21
23
26
export {funcname}
24
27
25
28
"""
26
- {funcname}(;kwargs...)
27
- {funcname}(children::Any;kwargs...)
28
- {funcname}(children_maker::Function;kwargs...)
29
+ {funcname}(;kwargs...){children_signatures}
29
30
30
31
{docstring}
31
32
"""
32
33
function {funcname}(; kwargs...)
33
- available_props = Set(Symbol[{component_props}])
34
- wild_props = Set(Symbol[{wildcard_symbols}])
35
- wild_regs = r"^(?<prop>{wildcard_names})"
36
-
37
- result = Component("{element_name}", "{module_name}", Dict{{Symbol, Any}}(), available_props, Set(Symbol[{wildcard_symbols}]))
38
-
39
- for (prop, value) = pairs(kwargs)
40
- m = match(wild_regs, string(prop))
41
- if (length(wild_props) == 0 || isnothing(m)) && !(prop in available_props)
42
- throw(ArgumentError("Invalid property $(string(prop)) for component " * "{funcname}"))
43
- end
44
-
45
- push!(result.props, prop => Front.to_dash(value))
46
- end
47
-
48
- return result
34
+ available_props = Symbol[{component_props}]
35
+ wild_props = Symbol[{wildcard_symbols}]
36
+ return Component("{funcname}", "{element_name}", "{module_name}", available_props, wild_props; kwargs...)
49
37
end
38
+ {children_definitions}
39
+ ''' # noqa:E501
50
40
51
- function {funcname}(children::Any; kwargs...)
52
- result = {funcname}(;kwargs...)
53
- push!(result.props, :children => Front.to_dash(children))
54
- return result
55
- end
41
+ jl_children_signatures = '''
42
+ {funcname}(children::Any;kwargs...)
43
+ {funcname}(children_maker::Function;kwargs...)
44
+ '''
56
45
46
+ jl_children_definitions = '''
47
+ {funcname}(children::Any; kwargs...) = {funcname}(;kwargs..., children = children)
57
48
{funcname}(children_maker::Function; kwargs...) = {funcname}(children_maker(); kwargs...)
58
- ''' # noqa:E501
49
+ '''
59
50
60
51
jl_package_file_string = '''
61
52
module {package_name}
62
- using Dash
53
+ using {base_package}
63
54
64
55
const resources_path = realpath(joinpath( @__DIR__, "..", "deps"))
65
56
const version = "{version}"
66
57
67
58
{component_includes}
68
59
69
60
function __init__()
70
- Dash .register_package(
71
- Dash .ResourcePkg(
61
+ DashBase .register_package(
62
+ DashBase .ResourcePkg(
72
63
"{project_shortname}",
73
64
resources_path,
74
65
version = version,
75
66
[
76
67
{resources_dist}
77
68
]
78
69
)
70
+
79
71
)
80
72
end
81
73
end
87
79
{authors}version = "{version}"
88
80
89
81
[deps]
90
- Dash = "{dash_uuid}"
82
+ {base_package} = "{dash_uuid}"
91
83
92
84
[compact]
93
- julia = "1.1 "
94
- Dash = ">=0.1"
85
+ julia = "1.2 "
86
+ {base_package} = ">=0.1"
95
87
'''
96
88
97
89
jl_component_include_string = 'include("{name}.jl")'
98
90
99
- jl_resource_tuple_string = '''Dash .Resource(
91
+ jl_resource_tuple_string = '''DashBase .Resource(
100
92
relative_package_path = {relative_package_path},
101
93
external_url = {external_url},
102
94
dynamic = {dynamic},
103
95
async = {async_string},
104
96
type = :{type}
105
97
)'''
106
98
99
+ core_packages = ['dash_html_components' , 'dash_core_components' , 'dash_table' ]
107
100
108
101
def jl_package_name (namestring ):
109
102
s = namestring .split ("_" )
@@ -370,6 +363,14 @@ def nothing_or_string(v):
370
363
else 'nothing'
371
364
) for resource in resources ]
372
365
366
+ def is_core_package (project_shortname ):
367
+ return project_shortname in core_packages
368
+
369
+ def base_package_name (project_shortname ):
370
+ return "DashBase" if is_core_package (project_shortname ) else "Dash"
371
+
372
+ def base_package_uid (project_shortname ):
373
+ return jl_dash_base_uuid if is_core_package (project_shortname ) else jl_base_uuid
373
374
374
375
def generate_package_file (project_shortname , components , pkg_data , prefix ):
375
376
package_name = jl_package_name (project_shortname )
@@ -391,15 +392,15 @@ def generate_package_file(project_shortname, components, pkg_data, prefix):
391
392
),
392
393
resources_dist = resources_dist ,
393
394
version = project_ver ,
394
- project_shortname = project_shortname
395
+ project_shortname = project_shortname ,
396
+ base_package = base_package_name (project_shortname )
395
397
396
398
)
397
399
file_path = os .path .join ("src" , package_name + ".jl" )
398
400
with open (file_path , "w" ) as f :
399
401
f .write (package_string )
400
402
print ("Generated {}" .format (file_path ))
401
403
402
-
403
404
def generate_toml_file (project_shortname , pkg_data ):
404
405
package_author = pkg_data .get ("author" , "" )
405
406
project_ver = pkg_data .get ("version" )
@@ -414,14 +415,14 @@ def generate_toml_file(project_shortname, pkg_data):
414
415
package_uuid = package_uuid ,
415
416
version = project_ver ,
416
417
authors = authors_string ,
417
- dash_uuid = jl_dash_uuid
418
+ base_package = base_package_name (project_shortname ),
419
+ dash_uuid = base_package_uid (project_shortname ),
418
420
)
419
421
file_path = "Project.toml"
420
422
with open (file_path , "w" ) as f :
421
423
f .write (toml_string )
422
424
print ("Generated {}" .format (file_path ))
423
425
424
-
425
426
def generate_class_string (name , props , description , project_shortname , prefix ):
426
427
# Ensure props are ordered with children first
427
428
filtered_props = reorder_props (filter_props (props ))
@@ -430,7 +431,7 @@ def generate_class_string(name, props, description, project_shortname, prefix):
430
431
431
432
docstring = create_docstring_jl (
432
433
component_name = name , props = filtered_props , description = description
433
- ).replace ("\r \n " , "\n " )
434
+ ).replace ("\r \n " , "\n " ). replace ( '$' , '\$' )
434
435
435
436
wclist = get_wildcards_jl (props )
436
437
default_paramtext = ""
@@ -453,6 +454,10 @@ def generate_class_string(name, props, description, project_shortname, prefix):
453
454
for p in prop_keys
454
455
)
455
456
457
+ has_children = "children" in prop_keys
458
+ funcname = format_fn_name (prefix , name )
459
+ children_signatures = jl_children_signatures .format (funcname = funcname ) if has_children else ""
460
+ children_definitions = jl_children_definitions .format (funcname = funcname ) if has_children else ""
456
461
return jl_component_string .format (
457
462
funcname = format_fn_name (prefix , name ),
458
463
docstring = docstring ,
@@ -461,6 +466,8 @@ def generate_class_string(name, props, description, project_shortname, prefix):
461
466
wildcard_names = stringify_wildcards (wclist , no_symbol = True ),
462
467
element_name = name ,
463
468
module_name = project_shortname ,
469
+ children_signatures = children_signatures ,
470
+ children_definitions = children_definitions
464
471
)
465
472
466
473
0 commit comments