def get_test_library2(libnames): package = dir_from_package_name('mcdp_data') all_libraries = os.path.join(package, 'libraries') librarian = Librarian() librarian.find_libraries(all_libraries) l = MCDPLibrary() for lib in libnames: data = librarian.libraries[lib] path = data['path'] l.add_search_dir(path) l.load_library_hooks.append(librarian.load_library) return l
def render_book(src_dirs, generate_pdf, data, realpath, main_file, use_mathjax, out_part_basename, raise_errors, filter_soup=None, extra_css=None, symbols=None): from mcdp_docs.pipeline import render_complete librarian = get_test_librarian() # XXX: these might need to be changed if not MCDPConstants.softy_mode: librarian.find_libraries('.') load_library_hooks = [librarian.load_library] library = MCDPLibrary(load_library_hooks=load_library_hooks) for src_dir in src_dirs: library.add_search_dir(src_dir) d = tempfile.mkdtemp() library.use_cache_dir(d) def filter_soup0(soup, library): if filter_soup is not None: filter_soup(soup=soup, library=library) add_edit_links(soup, realpath) try: html_contents = render_complete(library=library, s=data, raise_errors=raise_errors, realpath=realpath, use_mathjax=use_mathjax, symbols=symbols, generate_pdf=generate_pdf, filter_soup=filter_soup0) except DPSyntaxError as e: msg = 'Could not compile %s' % realpath raise_wrapped(DPSyntaxError, e, msg, compact=True) doc = get_minimal_document(html_contents, add_markdown_css=True, extra_css=extra_css) dirname = main_file + '.parts' if dirname and not os.path.exists(dirname): try: os.makedirs(dirname) except: pass fn = os.path.join(dirname, '%s.html' % out_part_basename) write_data_to_file(doc, fn) return html_contents
def view_shelf(self, e): desc_long_md = e.shelf.get_desc_long() if desc_long_md is None: desc_long = '' else: library = MCDPLibrary() desc_long = render_complete( library=library, s=desc_long_md, raise_errors=True, realpath=e.shelf_name, use_mathjax=False) res = { 'shelf': e.shelf, 'sname': e.shelf_name, 'desc_long': unicode(desc_long, 'utf8'), } return res
def __init__(self, the_context, repo_name, shelf_name, library_name): self.the_context = the_context self.repo_name = repo_name self.shelf_name = shelf_name self.library_name = library_name MCDPLibrary.__init__(self)
def render_book( src_dirs, generate_pdf, data, realpath, use_mathjax, raise_errors, filter_soup=None, symbols=None, ignore_ref_errors=False, ): """ Returns an AugmentedResult(str) """ res = AugmentedResult() from mcdp_docs.pipeline import render_complete librarian = get_test_librarian() # XXX: these might need to be changed if not MCDPConstants.softy_mode: for src_dir in src_dirs: librarian.find_libraries(src_dir) load_library_hooks = [librarian.load_library] library_ = MCDPLibrary(load_library_hooks=load_library_hooks) for src_dir in src_dirs: library_.add_search_dir(src_dir) d = tempfile.mkdtemp() library_.use_cache_dir(d) location = LocalFile(realpath) # print('location:\n%s' % location) def filter_soup0(soup, library): if filter_soup is not None: filter_soup(soup=soup, library=library) add_edit_links2(soup, location) add_last_modified_info(soup, location) try: html_contents = render_complete(library=library_, s=data, raise_errors=raise_errors, realpath=realpath, use_mathjax=use_mathjax, symbols=symbols, generate_pdf=generate_pdf, filter_soup=filter_soup0, location=location, res=res, ignore_ref_errors=ignore_ref_errors) except DPSyntaxError as e: msg = 'Could not compile %s' % realpath location0 = LocationInString(e.where, location) res.note_error(msg, locations=location0) fail = "<p>This file could not be compiled</p>" res.set_result(fail) return res # raise_wrapped(DPSyntaxError, e, msg, compact=True) if False: # write minimal doc doc = get_minimal_document(html_contents, add_markdown_css=True, extra_css=extra_css) dirname = main_file + '.parts' if dirname and not os.path.exists(dirname): try: os.makedirs(dirname) except: pass fn = os.path.join(dirname, '%s.html' % out_part_basename) write_data_to_file(doc, fn) res.set_result(html_contents) return res