def render_html(data_dir, output_dir):
env = Environment(loader=PackageLoader('<STR_LIT>', '<STR_LIT>'))<EOL>env.globals["<STR_LIT>"] = wcag_refs<EOL>pages = []<EOL>counter = collections.Counter()<EOL>grouped_violations = collections.defaultdict(dict)<EOL>for data_file in data_dir.files('<STR_LIT>'):<EOL><INDENT>data = json.load(data_file.open())<EOL>num_error, num_warning, num_notice = pa11y_counts(data['<STR_LIT>'])<EOL>data["<STR_LIT>"] = num_error<EOL>data["<STR_LIT>"] = num_warning<EOL>data["<STR_LIT>"] = num_notice<EOL>fname = data_file.namebase + "<STR_LIT>"<EOL>html_path = output_dir / fname<EOL>render_template(env, html_path, '<STR_LIT>', data)<EOL>data["<STR_LIT:filename>"] = fname<EOL>pages.append(data)<EOL>for violation in data['<STR_LIT>']:<EOL><INDENT>violation_id = hashlib.md5(<EOL>(violation['<STR_LIT>'] + violation['<STR_LIT:code>']).encode('<STR_LIT:utf-8>')<EOL>).hexdigest()<EOL>if violation_id not in grouped_violations[violation['<STR_LIT:type>']]:<EOL><INDENT>violation['<STR_LIT>'] = []<EOL>grouped_violations[violation['<STR_LIT:type>']][violation_id] = violation<EOL>counter[violation['<STR_LIT:type>']] += <NUM_LIT:1><EOL><DEDENT>grouped_violations[violation['<STR_LIT:type>']][violation_id]['<STR_LIT>'].append({<EOL>'<STR_LIT:url>': data['<STR_LIT:url>'],<EOL>'<STR_LIT>': data['<STR_LIT>']<EOL>})<EOL><DEDENT><DEDENT>def extract_nums(page):<EOL><INDENT>"<STR_LIT>"<EOL>return (<EOL>page["<STR_LIT>"],<EOL>page["<STR_LIT>"],<EOL>page["<STR_LIT>"],<EOL>)<EOL><DEDENT>index_path = output_dir / INDEX_TEMPLATE<EOL>render_template(env, index_path, INDEX_TEMPLATE, {<EOL>"<STR_LIT>": sorted(pages, key=extract_nums, reverse=True),<EOL>"<STR_LIT>": counter["<STR_LIT:error>"],<EOL>"<STR_LIT>": counter["<STR_LIT>"],<EOL>"<STR_LIT>": counter["<STR_LIT>"]<EOL>})<EOL>for violation_type in grouped_violations:<EOL><INDENT>unique_path = output_dir / u'<STR_LIT>'.format(violation_type)<EOL>render_template(env, unique_path, UNIQUE_TEMPLATE, {<EOL>"<STR_LIT>": sorted(<EOL>grouped_violations[violation_type].values(),<EOL>key=lambda item: len(item['<STR_LIT>']),<EOL>reverse=True<EOL>),<EOL>"<STR_LIT>": violation_type,<EOL>"<STR_LIT>": counter<EOL>})<EOL><DEDENT>
The main workhorse of this script. Finds all the JSON data files
from pa11ycrawler, and transforms them into HTML files via Jinja2 templating.