Mercurial > piecrust2
comparison piecrust/rendering.py @ 876:d1095774bfcf
refactor: Fix some issues with record/cache entry collisions, add counters.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 15 Jun 2017 07:33:40 -0700 |
parents | 58e28ba02fb7 |
children | d6d35b2efd04 |
comparison
equal
deleted
inserted
replaced
875:7169bf42ec60 | 876:d1095774bfcf |
---|---|
320 | 320 |
321 pass_info = ctx.render_passes[PASS_FORMATTING] | 321 pass_info = ctx.render_passes[PASS_FORMATTING] |
322 res = { | 322 res = { |
323 'segments': formatted_segments, | 323 'segments': formatted_segments, |
324 'pass_info': _pickle_object(pass_info)} | 324 'pass_info': _pickle_object(pass_info)} |
325 | |
326 app.env.stats.stepCounter('PageRenderSegments') | |
327 | |
325 return res | 328 return res |
326 | 329 |
327 | 330 |
328 def _do_render_layout(layout_name, page, layout_data): | 331 def _do_render_layout(layout_name, page, layout_data): |
329 cur_ctx = page.app.env.render_ctx_stack.current_ctx | 332 app = page.app |
333 cur_ctx = app.env.render_ctx_stack.current_ctx | |
330 assert cur_ctx is not None | 334 assert cur_ctx is not None |
331 assert cur_ctx.page == page | 335 assert cur_ctx.page == page |
332 | 336 |
333 names = layout_name.split(',') | 337 names = layout_name.split(',') |
334 full_names = [] | 338 full_names = [] |
338 else: | 342 else: |
339 full_names.append(name) | 343 full_names.append(name) |
340 | 344 |
341 _, engine_name = os.path.splitext(full_names[0]) | 345 _, engine_name = os.path.splitext(full_names[0]) |
342 engine_name = engine_name.lstrip('.') | 346 engine_name = engine_name.lstrip('.') |
343 engine = get_template_engine(page.app, engine_name) | 347 engine = get_template_engine(app, engine_name) |
344 | 348 |
345 try: | 349 try: |
346 with page.app.env.stats.timerScope( | 350 with app.env.stats.timerScope( |
347 engine.__class__.__name__ + '_layout'): | 351 engine.__class__.__name__ + '_layout'): |
348 output = engine.renderFile(full_names, layout_data) | 352 output = engine.renderFile(full_names, layout_data) |
349 except TemplateNotFoundError as ex: | 353 except TemplateNotFoundError as ex: |
350 logger.exception(ex) | 354 logger.exception(ex) |
351 msg = "Can't find template for page: %s\n" % page.content_item.spec | 355 msg = "Can't find template for page: %s\n" % page.content_item.spec |
352 msg += "Looked for: %s" % ', '.join(full_names) | 356 msg += "Looked for: %s" % ', '.join(full_names) |
353 raise Exception(msg) from ex | 357 raise Exception(msg) from ex |
354 | 358 |
355 pass_info = cur_ctx.render_passes[PASS_RENDERING] | 359 pass_info = cur_ctx.render_passes[PASS_RENDERING] |
356 res = {'content': output, 'pass_info': _pickle_object(pass_info)} | 360 res = {'content': output, 'pass_info': _pickle_object(pass_info)} |
361 | |
362 app.env.stats.stepCounter('PageRenderLayout') | |
363 | |
357 return res | 364 return res |
358 | 365 |
359 | 366 |
360 def get_template_engine(app, engine_name): | 367 def get_template_engine(app, engine_name): |
361 if engine_name == 'html': | 368 if engine_name == 'html': |