Пример #1
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]
    parser = argparse.ArgumentParser(description=__doc__)
    args = parser.parse_args(argv)

    templates = {t for t in glob.glob("%s/*.html" % templates_path)}
    for template_name in templates:
        print("Extracting template %r links" % template_name)
        with open(template_name) as t:
            links = extract_links(t.read())
        if links:
            print("%i links found" % len(links))
            for url in links:
                template_name = url_to_template(url)
                path, ext = os.path.splitext(template_name)
                if ext == ".html":
                    # Transform path/to/page.html into path/to/page/index.html
                    path = path + "/index.html"
                else:
                    path += ext
                output = compile_dir + path
                compile_template(template_name, output)
        else:
            print("No links found")
    output = compile_dir + "/index.html"
    compile_template("index.html", output)
    for entry in Entry.objects.all():
        output = compile_dir + entry.slug + "index.html"
        compile_template("entry.html", output, context={"entry": entry})
    for snippet in Snippet.objects.all():
        output = compile_dir + snippet.slug + "index.html"
        compile_template("snippet.html", output, context={"snippet": snippet})
Пример #2
0
 def test_absolute_url(self):
     url = "http://domain.com/path/subpath/"
     self.assertEqual("/path/subpath.html", url_to_template(url))
Пример #3
0
 def test_relative_url_without_begining_slash(self):
     url = "path/subpath"
     self.assertEqual("path/subpath.html", url_to_template(url))
Пример #4
0
 def test_relative_resource(self):
     url = "/path/subpath/style.css"
     self.assertEqual("/path/subpath/style.css", url_to_template(url))
Пример #5
0
 def test_relative_url(self):
     url = "/path/subpath/"
     self.assertEqual("/path/subpath.html", url_to_template(url))
Пример #6
0
 def test_absolute_url_without_trailing_slash(self):
     url = "http://domain.com/path/subpath"
     self.assertEqual("/path/subpath.html", url_to_template(url))
Пример #7
0
 def test_absolute_resource(self):
     url = "http://domain.com/path/subpath/style.css"
     self.assertEqual("/path/subpath/style.css", url_to_template(url))