Exemplo n.º 1
0
 def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None):
     """Compile docstrings into HTML strings, with shortcode support."""
     if not is_two_file:
         _, data = self.split_metadata(data, None, lang)
     new_data, shortcodes = sc.extract_shortcodes(data)
     # The way pdoc generates output is a bit inflexible
     path_templates = os.path.join(self.plugin_path, "tempaltes")
     LOGGER.info(f"set path tempaltes to {path_templates}")
     with tempfile.TemporaryDirectory() as tmpdir:
         subprocess.check_call(['pdoc', '--html', '--html-no-source', '--html-dir', tmpdir, "--template-dir", path_templates] + shlex.split(new_data.strip()))
         fname = os.listdir(tmpdir)[0]
         tmd_subdir = os.path.join(tmpdir, fname)
         fname = os.listdir(tmd_subdir)[0]
         LOGGER.info(f"tmpdir = {tmd_subdir}, fname = {fname}")
         with open(os.path.join(tmd_subdir, fname), 'r', encoding='utf8') as inf:
             output = inf.read()
     return self.site.apply_shortcodes_uuid(output, shortcodes, filename=source_path, extra_context={'post': post})
Exemplo n.º 2
0
    def gen_tasks(self):
        for in_name in get_entries(os.path.join(base_path, "../examples")):
            name_image = os.path.basename(in_name)
            out_name = "output/gallery/" + name_image

            # in_name = "/home/blackbird/Projects_heavy/pycontextfree/examples/paper/paper.png"
            # out_name = "output/gallery/paper.png"
            # out_name = "gallery/paper.png"
            LOGGER.info(f"emiting copyi task {in_name} to {out_name}")
            yield utils.apply_filters(
                {
                    'basename': self.name,
                    'name': out_name,
                    'file_dep': [in_name],
                    'targets': [out_name],
                    'actions': [(utils.copy_file, [in_name, out_name])],
                    'clean': True,
                }, {})
Exemplo n.º 3
0
    def read_files(self):
        self.rows = []
        cnt = 0
        for fname in get_entries(os.path.join(base_path, "../examples")):
            LOGGER.info("processing " + fname)
            try:
                # data = load_json(fname)
                data = {}
                data["path"] = fname
                data["path_image"] = fname[:-3] + ".png"
                data["name"] = os.path.basename(os.path.dirname(fname))
                data["url"] = "https://github.com/undertherain/pycontextfree/blob/master/examples/" + data["name"] + "/" + os.path.basename(fname)
                data["id"] = cnt
                name_image = os.path.basename(fname)[:-3] + ".png"

                data["image"] = "/gallery/" + name_image
                cnt += 1
                self.rows.append(data)
            except Exception as e:
                LOGGER.warning("error processing " + fname + str(e))
Exemplo n.º 4
0
 def __init__(self):
     self.plugin_path = os.path.dirname(os.path.realpath(__file__))
     base_path = self.plugin_path.split("plugins")[0]
     LOGGER.info(f"base path = {base_path}")
     sys.path.insert(0, os.path.join(base_path, "../"))
     super().__init__()