示例#1
0
文件: hpages.py 项目: mchaput/bookish
    def apply(self, block, context):
        # At the document root
        if block.get("type") == "root":
            attrs = block.get("attrs", {})
            path = context["path"]
            dirpath, filename = paths.split_dirpath(path)

            is_node_eg = (path.startswith("/examples/nodes/") and
                          not filename.startswith("_"))
            is_panel_eg = (path.startswith("/examples/python_panels/") and
                           not filename.startswith("_"))

            if is_node_eg or is_panel_eg:
                # This file is an example
                self._process_example_page(block, context, is_node_eg,
                                           is_panel_eg)

            elif attrs.get("type") == "node":
                # This is a node, add associated examples
                self._process_node_page(block, context)

        # The other stuff needs a searcher to work
        if not context.searcher:
            return

        # Look for :load_example: items
        body = block.get("body")
        blocktype = block.get("type")
        if blocktype == "load_example":
            self._process_load_block(block, context)
        elif blocktype == "list_examples":
            self._process_list_block(block, context)
        elif body:
            for sub in body:
                self.apply(sub, context)
示例#2
0
 def available_languages(self, path):
     store = self.store
     dirpath, filename = paths.split_dirpath(path)
     basename, ext = paths.split_extension(filename)
     result = []
     for lang in self.langauges:
         if lang == self.default_language:
             langfilename = filename
         else:
             langfilename = "%s.%s.%s" % (basename, lang, ext)
         if store.exists(paths.join(dirpath, langfilename)):
             result.append(lang)
     return result
示例#3
0
 def is_index_page(self, path):
     assert path.startswith("/")
     dirpath, filename = paths.split_dirpath(path)
     return (filename == self.index_page_name
             or filename.startswith(self.index_page_name + "."))