def render_source(self, meta): """Render a reference to the source file. Args: meta: A metadata dict object. Returns: A string of HTML to be spliced inside an HTML template. """ return printer.render_source(meta)
def render_htmldiv(self, entries, errors, options_map, file): dcontext = options_map['dcontext'] file.write('<div id="errors">\n') for error in errors: file.write('<div class="error">\n') if hasattr(error, 'source'): file.write('<a class="source" href="{}">{}</a><br/>\n'.format( self.formatter.render_source(error.source), printer.render_source(error.source))) file.write('<span class="error-message">{}</span>\n'.format( error.message)) if error.entry is not None: file.write('<pre class="syntax">\n') file.write(textwrap.indent( printer.format_entry(error.entry, dcontext), ' ')) file.write('</pre>\n') file.write('</div>\n') file.write('</div>\n')
def main(): optparser = argparse.ArgumentParser(description=__doc__) optparser.add_argument('filename', help='Transactions to be considered') optparser.add_argument('filename_diff', help='Transactions to be removed') optparser.add_argument('-q', '--quiet', action='store_true', help="Don't print file or line numbers.") args = optparser.parse_args() # Parse the ledger files. entries, errors, options = loader.load_file(args.filename, log_errors=logging.error) entries_diff, errors_diff, options_diff = loader.load_file( args.filename_diff, log_errors=logging.error) # Create a mapping from links to lists of transactions to find. link_map = collections.defaultdict(list) for entry in data.filter_txns(entries_diff): for link in entry.links: link_map[link].append(entry) # Filter out the transactions. filtered_entries = [] for entry in data.filter_txns(entries): for link in entry.links: if link in link_map: break else: filtered_entries.append(entry) # Print out something about each entry. for entry in filtered_entries: if not args.quiet: print() print('{}'.format(printer.render_source(entry.meta))) print() print(printer.format_entry(entry))
def test_render_source(self): source_str = printer.render_source(META) self.assertTrue(isinstance(source_str, str)) self.assertRegex(source_str, '12345') self.assertRegex(source_str, META['filename'])
def test_render_source(self): source_str = printer.render_source(META) self.assertTrue(isinstance(source_str, str)) self.assertTrue(re.search('12345', source_str)) self.assertTrue(re.search(META['filename'], source_str))