Example #1
0
    def _process_example_page(self, block, context, is_node_eg, is_panel_eg):
        path = context["path"]
        attrs = block.get("attrs", {})

        # Example authors are very lax about giving the example documents
        # titles; if the document doesn't have a title, make one up from the
        # file name
        title = functions.first_subblock_of_type(block, "title")
        if not title:
            name = text_type(paths.barename(path))
            body = block.setdefault("body", [])
            body.insert(0, {
                "type": "title", "indent": 0, "text": [name]
            })

        # Check for an explicit exampleFor property, otherwise guess it
        # from the example's directory tree
        if is_node_eg:
            block.setdefault("attrs", {})["type"] = "example"

            if "exampleFor" in attrs:
                egfor = attrs["exampleFor"]
            elif "examplefor" in attrs:
                egfor = attrs["examplefor"]
            else:
                egfor = self._node_path_from_example_path(path)
            # Attach the list of nodes to the root
            block["examplefor"] = egfor

        egpath = None
        # Check for an explicit exampleFile property, otherwise guess it
        # by looking for the example name with an extension
        if "exampleFile" in attrs:
            egpath = attrs["exampleFile"]
        elif "examplefile" in attrs:
            egpath = attrs["examplefile"]
        elif is_node_eg:
            base = paths.basepath(path)
            for ext in (".hda", ".otl"):
                egpath = base + ext
                if context.pages.exists(egpath):
                    break
        elif is_panel_eg:
            egpath = self._file_path_from_panel_path(path)

        if egpath:
            egpath = paths.join(path, egpath)
            if context.pages.exists(egpath):
                block["examplefile"] = egpath
Example #2
0
    def compile_scss(self, path):
        import os.path

        name = paths.barename(path)

        fp = self.store.file_path(path)
        outfp = os.path.join(os.path.dirname(fp), name + ".css")

        self.app.logger.info("SCSS compiling %s", fp)
        try:
            import sass
            css = sass.compile(filename=fp, precision=3)
        except:
            import sys
            e = sys.exc_info()[1]
            self.app.logger.error(str(e))
            raise
        else:
            with open(outfp, "w") as f:
                f.write(css)