16
16
# Declaring longer string templates as globals to improve
17
17
# readability, make method logic clearer to anyone inspecting
18
18
# code below
19
- r_component_string = """{prefix}{name } <- function({default_argtext}{wildcards}) {{
19
+ r_component_string = """{funcname } <- function({default_argtext}{wildcards}) {{
20
20
{wildcard_declaration}
21
21
component <- list(
22
22
props = list({default_paramtext}{wildcards}),
60
60
"""
61
61
62
62
help_string = """% Auto-generated: do not edit by hand
63
- \\ name{{{prefix}{name }}}
63
+ \\ name{{{funcname }}}
64
64
65
- \\ alias{{{prefix}{name }}}
65
+ \\ alias{{{funcname }}}
66
66
67
67
\\ title{{{name} component}}
68
68
71
71
}}
72
72
73
73
\\ usage{{
74
- {argtext}
74
+ {funcname}({default_argtext})
75
75
}}
76
76
77
77
\\ arguments{{
@@ -205,18 +205,16 @@ def generate_class_string(name, props, project_shortname, prefix):
205
205
for p in prop_keys
206
206
)
207
207
208
- return r_component_string .format (
209
- prefix = prefix ,
210
- name = name ,
211
- default_argtext = default_argtext ,
212
- wildcards = wildcards ,
213
- wildcard_declaration = wildcard_declaration ,
214
- default_paramtext = default_paramtext ,
215
- project_shortname = project_shortname ,
216
- prop_names = prop_names ,
217
- wildcard_names = wildcard_names ,
218
- package_name = package_name ,
219
- )
208
+ return r_component_string .format (funcname = format_fn_name (prefix , name ),
209
+ name = name ,
210
+ default_argtext = default_argtext ,
211
+ wildcards = wildcards ,
212
+ wildcard_declaration = wildcard_declaration ,
213
+ default_paramtext = default_paramtext ,
214
+ project_shortname = project_shortname ,
215
+ prop_names = prop_names ,
216
+ wildcard_names = wildcard_names ,
217
+ package_name = package_name )
220
218
221
219
222
220
# pylint: disable=R0914
@@ -319,7 +317,7 @@ def write_help_file(name, props, description, prefix):
319
317
writes an R help file to the man directory for the generated R package
320
318
321
319
"""
322
- file_name = "{}{}.Rd" . format (prefix , name )
320
+ file_name = format_fn_name (prefix , name ) + ".Rd"
323
321
324
322
default_argtext = ""
325
323
item_text = ""
@@ -356,32 +354,23 @@ def write_help_file(name, props, description, prefix):
356
354
file_path = os .path .join ('man' , file_name )
357
355
with open (file_path , 'w' ) as f :
358
356
f .write (help_string .format (
359
- prefix = prefix ,
357
+ funcname = format_fn_name ( prefix , name ) ,
360
358
name = name ,
361
- argtext = textwrap .fill (argtext ,
362
- width = 80 ,
363
- break_long_words = False ),
359
+ default_argtext = textwrap .fill (argtext ,
360
+ width = 80 ,
361
+ break_long_words = False ),
364
362
item_text = item_text ,
365
363
description = description .replace ('\n ' , ' ' )
366
364
))
367
365
368
366
369
- def write_class_file (name , props , description , project_shortname , prefix = None ):
367
+ def write_class_file (name ,
368
+ props ,
369
+ description ,
370
+ project_shortname ,
371
+ prefix = None ):
370
372
props = reorder_props (props = props )
371
373
372
- import_string = "# AUTO GENERATED FILE - DO NOT EDIT\n \n "
373
- class_string = generate_class_string (name ,
374
- props ,
375
- project_shortname ,
376
- prefix )
377
-
378
- file_name = "{}{}.R" .format (prefix , name )
379
-
380
- file_path = os .path .join ("R" , file_name )
381
- with open (file_path , "w" ) as f :
382
- f .write (import_string )
383
- f .write (class_string )
384
-
385
374
# generate the R help pages for each of the Dash components that we
386
375
# are transpiling -- this is done to avoid using Roxygen2 syntax,
387
376
# we may eventually be able to generate similar documentation using
@@ -394,6 +383,22 @@ def write_class_file(name, props, description, project_shortname, prefix=None):
394
383
prefix
395
384
)
396
385
386
+ import_string = \
387
+ "# AUTO GENERATED FILE - DO NOT EDIT\n \n "
388
+ class_string = generate_class_string (
389
+ name ,
390
+ props ,
391
+ project_shortname ,
392
+ prefix
393
+ )
394
+
395
+ file_name = format_fn_name (prefix , name ) + ".R"
396
+
397
+ file_path = os .path .join ("R" , file_name )
398
+ with open (file_path , "w" ) as f :
399
+ f .write (import_string )
400
+ f .write (class_string )
401
+
397
402
print ("Generated {}" .format (file_name ))
398
403
399
404
@@ -596,6 +601,16 @@ def snake_case_to_camel_case(namestring):
596
601
return s [0 ] + "" .join (w .capitalize () for w in s [1 :])
597
602
598
603
604
+ # this logic will permit passing blank R prefixes to
605
+ # dash-generate-components, while also enforcing
606
+ # camelCase for the resulting functions; if a prefix
607
+ # is supplied, leave it as-is
608
+ def format_fn_name (prefix , name ):
609
+ if prefix :
610
+ return prefix + snake_case_to_camel_case (name )
611
+ return snake_case_to_camel_case (name [0 ].lower () + name [1 :])
612
+
613
+
599
614
# pylint: disable=unused-argument
600
615
def generate_exports (
601
616
project_shortname ,
0 commit comments