def _render_with_finding_data_first(self, data_file_index): for (data_file, template_output_pairs) in data_file_index.items(): data = self.context.get_data(data_file) for (template_file, output) in template_output_pairs: try: template = self.engine.get_template(template_file) if isinstance(template, bool): if template: reporter.report_templating(self.engine_action, template_file, None) self.templated_count += 1 else: template_abs_path = self.template_fs.geturl( template_file, purpose="fs") flag = self.apply_template(template_abs_path, template, data, output) if flag: reporter.report_templating(self.engine_action, template_file, output) self.templated_count += 1 self.file_count += 1 except exceptions.PassOn: self.fall_out_targets.append( TemplateTarget( template_file, data_file, output, template_type=constants.TEMPLATE_COPY, )) reporter.report_info_message( f"{self.engine_action} is switched to copy:" + f" {template_file} to {output}") continue
def render_string_to_file(self, template_in_string, data_file, output_file): template = self.engine.get_template_from_string(template_in_string) template_abs_path = f"{template_in_string[:10]}..." data = self.context.get_data(data_file) flag = self.apply_template(template_abs_path, template, data, output_file) if flag: reporter.report_templating(self.engine_action, template_abs_path, output_file) self.templated_count += 1 self.file_count += 1 self.buffered_writer.close()
def _render_with_finding_data_first(self, data_file_index): for (data_file, template_output_pairs) in data_file_index.items(): data = self.context.get_data(data_file) for (template_file, output) in template_output_pairs: template = self.engine.get_template(template_file) template_abs_path = self.template_fs.geturl(template_file, purpose="fs") flag = self.apply_template(template_abs_path, template, data, output) if flag: reporter.report_templating(self.engine_action, template_file, output) self.templated_count += 1 self.file_count += 1
def render_to_file(self, template_file, data_file, output_file): data = self.context.get_data(data_file) template = self.engine.get_template(template_file) try: template_abs_path = self.template_fs.geturl(template_file, purpose="fs") except ResourceNotFound: template_abs_path = template_file flag = self.apply_template(template_abs_path, template, data, output_file) if flag: reporter.report_templating(self.engine_action, template_file, output_file) self.templated_count += 1 self.file_count += 1 self.buffered_writer.close()
def test_report_templating(): patcher = patch("sys.stdout", new_callable=StringIO) fake_stdout = patcher.start() reporter.report_templating("Transforming", "a", "b") patcher.stop() eq_(fake_stdout.getvalue(), "Transforming a to b\n")