Exemplo n.º 1
0
	def problem_part(part_name, metadata_sorter):
		prob.parts[part_name].sort(key = metadata_sorter)
		raw_htmls = []
		for part in getattr(prob, part_name):
			fp = path.join(prob.prob_meta['prob_base'], part_name)

			if (part.endswith('.inline.html')):
				with open(part, encoding='utf-8') as f:
					raw_html = f.read()
				raw_htmls.append(raw_html.strip())
				continue
			elif (part.endswith('.inline.md')):
				(html, _) = convert_markdown(part)
				raw_htmls.append(html.strip())
				continue

		template = apply_template(part_name + ".html", metadata=prob.parts[part_name], rel_path=part_name, prob=prob,
									raw_htmls=raw_htmls, base_template=prob.pagetype['base_template'], **prob.prob_meta)

		write(template, part_name + "/index.html")
Exemplo n.º 2
0
		if type in language.metadata['title']:
			return True
		# Now try to match the file extension
		for ext in language.metadata['extensions']:
			if type == ext:
				model['meta']['type'] = language.metadata['title']
				return True
	return False


# PROB_DATA is shared with mdx_prob_link
PROB_DATA = {}
# We need the title to for referencing problems, so we preprocess the specification
for prob in probs:
	try:
		(_,meta) = util.convert_markdown(prob.specification)
		PROB_DATA[prob.name] = dict(title=meta['title'][0],is_language=False)
	except Exception as e:
		logger.info("Failure in page %s", prob.name)
		logger.info("Error: %s", e)
		raise
	# Only for categories,html
	prob.meta_title = meta['title'][0]


logger.debug("Before source_types:%s", pformat(util.source_types))
logger.debug("Before source_mapping:%s", pformat(util.source_mapping))


# Fill in extension -> filetype mappings
# Also update the source_types to allow syntax highligting
Exemplo n.º 3
0
def process_problem(prob, apply_template, output_dir, base):
	"Creates the problem's html"

	(content, metadata) = convert_markdown(prob.specification)
	prob.content = content

	if not "category" in metadata:
		metadata['category'] = ['Unclassified']
	else:
		metadata['category'] = [ m for m in metadata['category'] if m ]
		if len(metadata['category']) == 0:
			metadata['category'] = ['Unclassified']

	metadata['id'] = [prob.name]
	metadata['shortid'] = [prob.name[4:]]
	prob.metadata = metadata

	title = prob.pagetype['title'](metadata)
	prob.prob_meta = {"title": title, "prob_base": prob.pagetype['class_dir'] + "/" + prob.name, "prob_name": prob.name}

	#todo: remove?
	prob.prob_dir = path.join(output_dir, prob.pagetype['class_dir'] +"/{0}".format(prob.name))
	def write(data, name):
		with open(path.join(prob.prob_dir, name), "w", encoding='utf-8') as f:
			f.write(data)


	def problem_part(part_name, metadata_sorter):
		part_metadata = []
		part_dir = prob.prob_dir + "/" + part_name + "/"
		makedirs_exist_ok(part_dir)

		raw_htmls = []
		for part in getattr(prob, part_name):
			fp = path.join(prob.prob_meta['prob_base'], part_name)

			if (part.endswith('.inline.html')) or (part.endswith('.inline.md')):
				continue

			(content, metadata, url) = get_content_and_metadata(part, fp)
			logger.debug( (part, metadata, content[0:5]))
			if not url:
				name = path.basename(part)
				filename = name + ".html"
				res = apply_template("file.html", problemContent=content,
					name=name, part=part_name, rel_path="{0}/{1}".format(part_name, name), prob=prob,
					**prob.prob_meta)
				write(res, part_name + "/" + filename)
				file_util.copy_file(part, path.join(part_dir, name))
			else:
				filename = path.basename(url)
				name = path.basename(filename)
				file_util.copy_file(part, path.join(part_dir, name))

			part_metadata.append({"name": name, "filename": filename, "meta": metadata})

		prob.parts[part_name] = part_metadata

	for p in prob.pagetype['parts']:
		problem_part(p[0], p[1])

	# Copying assets bindly
	prob_dir_in = path.join(base, prob.pagetype['class_dir'] + "/{0}".format(prob.name))
	assets_in = path.join(prob_dir_in, "assets")
	assets_out = path.join(prob.prob_dir, "assets")

	if path.exists(assets_in):
		logger.debug("Copying assets from %s to %s", assets_in, assets_out )
		dir_util.copy_tree(assets_in, assets_out)


	prob.has_bibtex=None
	prob.bib_html=""
	prob.ref_notes_html=""
	if prob.bib:
		makedirs_exist_ok(path.join(prob.prob_dir, "references"))
		file_util.copy_file(prob.bib.bibfile, path.join(prob.prob_dir, "references",  prob.name +"-refs.bib"))
		prob.has_bibtex = True
		prob.bib_html = prob.bib.to_html(apply_template)

	if prob.ref_notes:
		(prob.ref_notes_html, _) = convert_markdown(prob.ref_notes)
Exemplo n.º 4
0
        if type in language.metadata['title']:
            return True
        # Now try to match the file extension
        for ext in language.metadata['extensions']:
            if type == ext:
                model['meta']['type'] = language.metadata['title']
                return True
    return False


# PROB_DATA is shared with mdx_prob_link
PROB_DATA = {}
# We need the title to for referencing problems, so we preprocess the specification
for prob in probs:
    try:
        (_, meta) = util.convert_markdown(prob.specification)
        PROB_DATA[prob.name] = dict(title=meta['title'][0], is_language=False)
    except Exception as e:
        logger.info("Failure in page %s", prob.name)
        logger.info("Error: %s", e)
        raise
    # Only for categories,html
    prob.meta_title = meta['title'][0]

logger.debug("Before source_types:%s", pformat(util.source_types))
logger.debug("Before source_mapping:%s", pformat(util.source_mapping))

# Fill in extension -> filetype mappings
# Also update the source_types to allow syntax highligting
for lang in langs:
    (_, meta) = util.convert_markdown(lang.specification)