1313from typing import Dict , List , Tuple
1414
1515import config
16+ from aws_doc_sdk_examples_tools .categories import Category
1617from aws_doc_sdk_examples_tools .entities import expand_all_entities
1718from aws_doc_sdk_examples_tools .metadata import Example
1819from aws_doc_sdk_examples_tools .sdks import Sdk
@@ -128,6 +129,7 @@ def _transform_examples(
128129 "api" : api ,
129130 "category" : pre .category ,
130131 }
132+ self ._apply_defaults_and_overrides (action )
131133 post_examples .append (action )
132134 return sorted (post_examples , key = itemgetter (sort_key ))
133135
@@ -153,22 +155,44 @@ def _find_files(self, example: Example, api: str, github: bool = False):
153155
154156 return file , run_file
155157
158+ def _make_plain_text (self , s : str , example : Dict [str , str ]) -> [str , None ]:
159+ """Work around strings being Go templates and including XML tags by brute forcing them away."""
160+ if s is None :
161+ return s
162+ return s .replace ("<code>" , "" )\
163+ .replace ("</code>" , "" )\
164+ .replace ("{{.Action}}" , example ["api" ])\
165+ .replace ("{{.ServiceEntity.Short}}" , self .scanner .doc_gen .services [self .scanner .svc_name ].short )
166+
167+ def _apply_defaults_and_overrides (self , example : Dict [str , str ]):
168+ ex_cat = "Actions" if example ["category" ] == "Api" else example ["category" ]
169+ cat = self .scanner .doc_gen .categories .get (ex_cat , None )
170+ if cat is not None :
171+ if cat .overrides :
172+ example ["title" ] = self ._make_plain_text (cat .overrides .title , example )
173+ example ["title_abbrev" ] = self ._make_plain_text (cat .overrides .title_abbrev , example )
174+ example ["synopsis" ] = self ._make_plain_text (cat .overrides .synopsis , example )
175+ elif cat .defaults :
176+ if not example .get ("title" ):
177+ example ["title" ] = self ._make_plain_text (cat .defaults .title , example )
178+ if not example .get ("title_abbrev" ):
179+ example ["title_abbrev" ] = self ._make_plain_text (cat .defaults .title_abbrev , example )
180+ if not example .get ("synopsis" ):
181+ example ["synopsis" ] = self ._make_plain_text (cat .defaults .synopsis , example )
182+
156183 def _transform_hellos (self ) -> List [Dict [str , str ]]:
157184 examples = self ._transform_examples (self .scanner .hellos )
158185 return examples
159186
160187 def _transform_actions (self ) -> List [Dict [str , str ]]:
161188 examples = self ._transform_examples (self .scanner .actions , sort_key = "api" )
162189 for example in examples :
163- example ["title_abbrev" ] = example ["api" ]
164190 del example ["api" ]
165191 return examples
166192
167193 def _transform_basics (self ) -> List [Dict [str , str ]]:
168194 examples = self ._transform_examples (self .scanner .basics )
169195 for example in examples :
170- if not example ["title_abbrev" ]:
171- example ["title_abbrev" ] = config .basics_title_abbrev
172196 example ["file" ] = example ["run_file" ]
173197 del example ["run_file" ]
174198 del example ["api" ]
@@ -196,7 +220,8 @@ def _transform_custom_categories(self) -> Dict[str, List[Dict[str, str]]]:
196220 post_cats [example ["category" ]].append (example )
197221
198222 sorted_cats = {}
199- for key in sorted (post_cats .keys ()):
223+ for key in sorted (post_cats .keys (),
224+ key = lambda x : self .scanner .doc_gen .categories .get (x , Category (x , x )).display ):
200225 if len (post_cats [key ]) == 0 :
201226 del sorted_cats [key ]
202227 else :
@@ -295,6 +320,7 @@ def render(self) -> RenderStatus:
295320 lang_config = self .lang_config ,
296321 sdk = sdk ,
297322 service = svc ,
323+ categories = self .scanner .doc_gen .categories ,
298324 hello = hello ,
299325 actions = actions ,
300326 basics = basics ,
0 commit comments