示例#1
0
    def load_pages(self):
        """
        Preload all config'd pages, not just target pages, to get them
        default name values.
        """

        self.page_cache = []
        skip_pp = self.config.get("skip_preprocessor", False)
        for page_data in self.config["pages"]:
            if OPENAPI_SPEC_KEY not in page_data:
                # Try loading page now; but if it fails, that might be OK
                # depending on whether we need the file later.
                try:
                    self.page_cache.append(DactylPage(self, page_data,
                                                      skip_pp))
                except Exception as e:
                    logger.warning("Couldn't load page '%s': %s" %
                                   (page_data, e))
                    self.page_cache.append(NOT_LOADED_PLACEHOLDER)
            else:
                # OpenAPI specs are too much work to load at this time
                self.page_cache.append(OPENAPI_SPEC_PLACEHOLDER)

        # Check consistency here instead of earlier so that we have frontmatter
        # from pages first. (Otherwise, we raise false alarms about pages not
        # being part of any target.)
        self.check_consistency()
示例#2
0
 def add_cover(self):
     """
     Instantiate the default cover page so self.load_pages() can include it.
     """
     coverpage_data = self.config["cover_page"]
     coverpage_data["targets"] = [self.name]
     skip_pp = self.config.get("skip_preprocessor", False)
     more_filters = self.data.get("filters", [])
     self.cover = DactylPage(self.config, coverpage_data, skip_pp, more_filters)
示例#3
0
    def expand_openapi_spec(self, page_data):
        """Expand OpenAPI Spec placeholders into a full page list"""
        assert OPENAPI_SPEC_KEY in page_data.keys()

        logger.debug("Expanding OpenAPI spec from placeholder: %s" % page_data)
        api_slug = page_data.get(API_SLUG_KEY, None)
        extra_fields = {}
        merge_dicts(self.data, extra_fields, RESERVED_KEYS_TARGET)
        merge_dicts(page_data, extra_fields, [OPENAPI_SPEC_KEY, API_SLUG_KEY])

        template_path = page_data.get(OPENAPI_TEMPLATE_PATH_KEY, None)
        swagger = ApiDef.from_path(page_data[OPENAPI_SPEC_KEY], api_slug,
                                   extra_fields, template_path)
        skip_pp = self.config.get("skip_preprocessor", False)
        made_pages = []
        for p in swagger.create_pagelist():
            more_filters = self.data.get("filters", [])
            po = DactylPage(self.config, p, skip_pp, more_filters)
            # Special case for filters; concatenate filter lists,
            # with target's filters first.
            if "filters" in self.data:
                po.gain_filters(self.data["filters"])
            made_pages.append(po)
        return made_pages
示例#4
0
文件: config.py 项目: meonBot/dactyl
    def load_pages(self):
        """
        Preload all config'd pages, not just target pages, to get them
        default name values.
        """

        self.page_cache = []
        skip_pp = self.config.get("skip_preprocessor", False)
        for page_data in self.config["pages"]:
            if OPENAPI_SPEC_KEY not in page_data:
                # Try loading page now; but if it fails, that might be OK
                # depending on whether we need the file later.
                try:
                    self.page_cache.append(DactylPage(self, page_data, skip_pp))
                except Exception as e:
                    logger.warning("Couldn't load page '%s': %s"%(page_data,e))
                    self.page_cache.append(NOT_LOADED_PLACEHOLDER)
            else:
                # OpenAPI specs are too much work to load at this time
                self.page_cache.append(OPENAPI_SPEC_PLACEHOLDER)
示例#5
0
 def test_get_filters_for_page(self):
     # Please note: due to the mock setup for unit testing, this function will always return an empty set.  Refactoring is recommended to verify the remaining functionality for this method.
     page = DactylPage(mockconfig, {})
     assert page.filters() == set()
示例#6
0
 def test_preprocess(self):
     page = DactylPage(mockconfig, {"name": "Testpage"})
     page.pp_template = mocktemplate
     page.preprocess({"currentpage": page.data})
     print(page.md)
     assert page.md == "This page is Testpage."
示例#7
0
 def test_frontmatter(self):
     page = DactylPage(mockconfig, {"md": "with-frontmatter.md"})
     assert page.data["desc"] == "This file has Jekyll-style frontmatter"
示例#8
0
 def test_default_filename(self):
     page = DactylPage(mockconfig, {"name": "TeSt1!"})
     assert page.data["html"] == "test1.html"
示例#9
0
 def test_page_init(self):
     page = DactylPage(mockconfig, {})