27
27
from sphinx_antsibull_ext .directive_helper import YAMLDirective
28
28
from sphinx_antsibull_ext .schemas .ansible_output_data import (
29
29
AnsibleOutputData ,
30
+ AnsibleOutputTemplate ,
30
31
NonRefPostprocessor ,
31
32
PostprocessorNameRef ,
33
+ combine ,
32
34
)
33
35
from sphinx_antsibull_ext .schemas .ansible_output_meta import (
34
36
ActionResetPreviousBlocks ,
37
+ ActionSetTemplate ,
35
38
AnsibleOutputMeta ,
36
39
)
37
40
@@ -188,12 +191,16 @@ def __init__(
188
191
self .blocks : list [Block ] = []
189
192
self .data : _AnsibleOutputDataExt | None = None
190
193
self .previous_blocks : list [CodeBlockInfo ] = []
194
+ self .template = AnsibleOutputTemplate ()
191
195
192
196
def _process_reset_previous_blocks (
193
197
self , action : ActionResetPreviousBlocks # pylint: disable=unused-argument
194
198
) -> None :
195
199
self .previous_blocks .clear ()
196
200
201
+ def _process_set_template (self , action : ActionSetTemplate ) -> None :
202
+ self .template = action .template
203
+
197
204
def process_meta (
198
205
self ,
199
206
meta : AnsibleOutputMeta ,
@@ -204,6 +211,8 @@ def process_meta(
204
211
for action in meta .actions :
205
212
if isinstance (action , ActionResetPreviousBlocks ):
206
213
self ._process_reset_previous_blocks (action )
214
+ elif isinstance (action , ActionSetTemplate ):
215
+ self ._process_set_template (action )
207
216
else :
208
217
raise AssertionError ("Unknown action" ) # pragma: no cover
209
218
@@ -227,11 +236,25 @@ def process_special_block(
227
236
self .errors .append (Error (self .path , line , col , message ))
228
237
if "antsibull-other-data" in block .attributes :
229
238
if directive == "ansible-output-data" :
230
- self .data = _AnsibleOutputDataExt (
231
- data = block .attributes ["antsibull-other-data" ],
232
- line = block .row_offset + 1 ,
233
- col = block .col_offset + 1 ,
234
- )
239
+ try :
240
+ data = combine (
241
+ data = block .attributes ["antsibull-other-data" ],
242
+ template = self .template ,
243
+ )
244
+ self .data = _AnsibleOutputDataExt (
245
+ data = data ,
246
+ line = block .row_offset + 1 ,
247
+ col = block .col_offset + 1 ,
248
+ )
249
+ except ValueError as exc :
250
+ self .errors .append (
251
+ Error (
252
+ self .path ,
253
+ block .row_offset + 1 ,
254
+ block .col_offset + 1 ,
255
+ str (exc ),
256
+ )
257
+ )
235
258
if directive == "ansible-output-meta" :
236
259
self .process_meta (
237
260
block .attributes ["antsibull-other-data" ],
@@ -249,23 +272,24 @@ def _add_block(
249
272
env .update (data .data .env )
250
273
postprocessors = []
251
274
error = False
252
- for postprocessor in data .data .postprocessors :
253
- if isinstance (postprocessor , PostprocessorNameRef ):
254
- ref = postprocessor .name
255
- try :
256
- postprocessor = self .environment .global_postprocessors [ref ]
257
- except KeyError :
258
- self .errors .append (
259
- Error (
260
- self .path ,
261
- data .line ,
262
- data .col ,
263
- f"No global postprocessor of name { ref !r} defined" ,
275
+ if data .data .postprocessors :
276
+ for postprocessor in data .data .postprocessors :
277
+ if isinstance (postprocessor , PostprocessorNameRef ):
278
+ ref = postprocessor .name
279
+ try :
280
+ postprocessor = self .environment .global_postprocessors [ref ]
281
+ except KeyError :
282
+ self .errors .append (
283
+ Error (
284
+ self .path ,
285
+ data .line ,
286
+ data .col ,
287
+ f"No global postprocessor of name { ref !r} defined" ,
288
+ )
264
289
)
265
- )
266
- error = True
267
- continue
268
- postprocessors .append (postprocessor )
290
+ error = True
291
+ continue
292
+ postprocessors .append (postprocessor )
269
293
if error :
270
294
return
271
295
self .blocks .append (
0 commit comments