Example #1
0
    def render(self, site=None):
        try:
            env = Registry.get('plywood_environment')
            template_path = fix_path(self.source_path)
            with open(template_path) as f:
                contents = f.read()
                front_matter_match = re.match(
                    r"\A([-]{3,}|[`]{3,})(\r\n|\r|\n)", contents)
                number_yaml_lines = 0
                if front_matter_match:
                    newline = front_matter_match.group(
                        2)  # group(2) contains the newline/CRLF
                    number_yaml_lines += 1
                    offset = len(front_matter_match.group(0))
                    delim = re.compile("^" + front_matter_match.group(1) + "$")
                    lines = contents.splitlines()
                    for line in lines[
                            1:]:  # skip the first line, the opening front matter
                        offset += len(line) + len(newline)
                        number_yaml_lines += 1
                        if delim.match(line):
                            break
                    contents = (newline *
                                number_yaml_lines) + contents[offset:]

        except UnicodeDecodeError as e:
            e.args += "Could not process '%s' because of unicode error." % self.source_path
            raise
        env.scope.push()
        env.scope['site'] = site
        env.scope['my'] = self
        retval = Plywood(contents).run(self.config, env)
        env.scope.pop()
        return retval
Example #2
0
    def render(self, site=None):
        try:
            env = Registry.get("plywood_environment")
            template_path = fix_path(self.source_path)
            with open(template_path) as f:
                contents = f.read()
                front_matter_match = re.match(r"\A([-]{3,}|[`]{3,})(\r\n|\r|\n)", contents)
                number_yaml_lines = 0
                if front_matter_match:
                    newline = front_matter_match.group(2)  # group(2) contains the newline/CRLF
                    number_yaml_lines += 1
                    offset = len(front_matter_match.group(0))
                    delim = re.compile("^" + front_matter_match.group(1) + "$")
                    lines = contents.splitlines()
                    for line in lines[1:]:  # skip the first line, the opening front matter
                        offset += len(line) + len(newline)
                        number_yaml_lines += 1
                        if delim.match(line):
                            break
                    contents = (newline * number_yaml_lines) + contents[offset:]

        except UnicodeDecodeError as e:
            e.args += "Could not process '%s' because of unicode error." % self.source_path
            raise
        env.scope.push()
        env.scope["site"] = site
        env.scope["my"] = self
        retval = Plywood(contents).run(self.config, env)
        env.scope.pop()
        return retval
Example #3
0
 def render(self, site=None):
     try:
         template = Registry.get('jinja_environment').get_template(fix_path(self.source_path))
     except UnicodeDecodeError as e:
         e.args += "Could not process '%s' because of unicode error." % self.source_path
         raise
     return template.render(self.config, my=self, site=site)
Example #4
0
 def render(self, site=None):
     # print "self.source_path is '{}', fixed to '{}'".format(self.source_path, fix_path(self.source_path))
     try:
         template = Registry.get("jinja_environment").get_template(fix_path(os.path.relpath(self.source_path)))
     except UnicodeDecodeError as e:
         e.args += "Could not process '%s' because of unicode error." % self.source_path
         raise
     return template.render(self.config, my=self, site=site)