@@ -234,6 +234,7 @@ def make_filename_template(
234
234
pdf_format = False ,
235
235
placeholders = False ,
236
236
empty_dirs = None ,
237
+ show_entities = tuple (),
237
238
** kwargs ,
238
239
):
239
240
"""Create codeblocks containing example filename patterns for a given datatype.
@@ -271,6 +272,10 @@ def make_filename_template(
271
272
If False, empty datatype directories are not included. If ``placeholders`` is True,
272
273
this option is set False.
273
274
Default is True.
275
+ show_entities: tuple, optional
276
+ If ``placeholders`` is ``False`` this argument is ignored.
277
+ When using placeholders, this argument can be set to a list or tuple of entity
278
+ names that will be "extracted" out of the placeholder.
274
279
275
280
Other Parameters
276
281
----------------
@@ -325,9 +330,11 @@ def make_filename_template(
325
330
if empty_dirs is None :
326
331
empty_dirs = not placeholders
327
332
333
+ entity_list = schema .rules .entities
334
+ start_string = ""
328
335
if placeholders :
329
336
metaentity_name = "matches" if dstype == "raw" else "source_entities"
330
- ent_string = (
337
+ start_string = (
331
338
lt
332
339
+ utils ._link_with_html (
333
340
metaentity_name ,
@@ -337,6 +344,7 @@ def make_filename_template(
337
344
)
338
345
+ gt
339
346
)
347
+ entity_list = show_entities
340
348
341
349
for datatype in sorted (file_groups ):
342
350
group_lines = []
@@ -350,44 +358,43 @@ def make_filename_template(
350
358
351
359
# Unique filename patterns
352
360
for group in file_groups [datatype ]:
353
- if not placeholders :
354
- ent_string = ""
355
- for ent in schema .rules .entities :
356
- if ent not in group .entities :
357
- continue
358
-
359
- # Add level and any overrides to entity
360
- ent_obj = group .entities [ent ]
361
- if isinstance (ent_obj , str ):
362
- ent_obj = {"level" : ent_obj }
363
- entity = {** schema .objects .entities [ent ], ** ent_obj }
364
-
365
- if "enum" in entity :
366
- # Link full entity
367
- pattern = utils ._link_with_html (
368
- _format_entity (entity , lt , gt ),
369
- html_path = f"{ ENTITIES_PATH } .html" ,
370
- heading = entity ["name" ],
371
- pdf_format = pdf_format ,
372
- )
373
- else :
374
- # Link entity and format separately
375
- entity ["name" ] = utils ._link_with_html (
376
- entity ["name" ],
377
- html_path = f"{ ENTITIES_PATH } .html" ,
378
- heading = entity ["name" ],
379
- pdf_format = pdf_format ,
380
- )
381
- fmt = entity .get ("format" , "label" )
382
- entity ["format" ] = utils ._link_with_html (
383
- entity .get ("format" , "label" ),
384
- html_path = f"{ GLOSSARY_PATH } .html" ,
385
- heading = f"{ fmt } -common_principles" ,
386
- pdf_format = pdf_format ,
387
- )
388
- pattern = _format_entity (entity , lt , gt )
389
-
390
- ent_string = _add_entity (ent_string , pattern , entity ["level" ])
361
+ ent_string = start_string
362
+ for ent in entity_list :
363
+ if ent not in group .entities :
364
+ continue
365
+
366
+ # Add level and any overrides to entity
367
+ ent_obj = group .entities [ent ]
368
+ if isinstance (ent_obj , str ):
369
+ ent_obj = {"level" : ent_obj }
370
+ entity = {** schema .objects .entities [ent ], ** ent_obj }
371
+
372
+ if "enum" in entity :
373
+ # Link full entity
374
+ pattern = utils ._link_with_html (
375
+ _format_entity (entity , lt , gt ),
376
+ html_path = f"{ ENTITIES_PATH } .html" ,
377
+ heading = entity ["name" ],
378
+ pdf_format = pdf_format ,
379
+ )
380
+ else :
381
+ # Link entity and format separately
382
+ entity ["name" ] = utils ._link_with_html (
383
+ entity ["name" ],
384
+ html_path = f"{ ENTITIES_PATH } .html" ,
385
+ heading = entity ["name" ],
386
+ pdf_format = pdf_format ,
387
+ )
388
+ fmt = entity .get ("format" , "label" )
389
+ entity ["format" ] = utils ._link_with_html (
390
+ entity .get ("format" , "label" ),
391
+ html_path = f"{ GLOSSARY_PATH } .html" ,
392
+ heading = f"{ fmt } -common_principles" ,
393
+ pdf_format = pdf_format ,
394
+ )
395
+ pattern = _format_entity (entity , lt , gt )
396
+
397
+ ent_string = _add_entity (ent_string , pattern , entity ["level" ])
391
398
392
399
# In cases of large numbers of suffixes,
393
400
# we use the "suffix" variable and expect a table later in the spec
0 commit comments