mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Initial doc layout and build script.
This commit is contained in:
parent
caba92d937
commit
b7cce49f65
122
doc/buildweb.py
Executable file
122
doc/buildweb.py
Executable file
@ -0,0 +1,122 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -
|
||||||
|
#
|
||||||
|
# This file is part of gunicorn released under the MIT license.
|
||||||
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
|
import codecs
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from docutils.core import publish_parts
|
||||||
|
from jinja2 import Environment
|
||||||
|
from jinja2.loaders import FileSystemLoader
|
||||||
|
from jinja2.utils import open_if_exists
|
||||||
|
|
||||||
|
import conf
|
||||||
|
|
||||||
|
class Site(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.url = conf.SITE_URL.rstrip('/')
|
||||||
|
|
||||||
|
fs_loader = FileSystemLoader(conf.TEMPLATES_PATH, encoding="utf-8")
|
||||||
|
self.env = Environment(loader=fs_loader)
|
||||||
|
self.env.charset = 'utf-8'
|
||||||
|
self.env.filters['rel_url'] = self.rel_url
|
||||||
|
|
||||||
|
def rel_url(self, value):
|
||||||
|
return value.split(self.url)[1]
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
for curr_path, dirs, files in os.walk(conf.INPUT_PATH):
|
||||||
|
tgt_path = curr_path.replace(conf.INPUT_PATH, conf.OUTPUT_PATH)
|
||||||
|
if not os.path.isdir(tgt_path):
|
||||||
|
os.makedirs(tgt_path)
|
||||||
|
self.process(files, curr_path, tgt_path)
|
||||||
|
|
||||||
|
def process(self, files, curr_path, tgt_path):
|
||||||
|
files = [f for f in files if os.path.splitext(f)[1] in conf.EXTENSIONS]
|
||||||
|
for f in files:
|
||||||
|
if os.path.splitext(f)[1] not in conf.EXTENSIONS:
|
||||||
|
continue
|
||||||
|
|
||||||
|
page = Page(self, f, curr_path, tgt_path)
|
||||||
|
if not page.needed():
|
||||||
|
continue
|
||||||
|
|
||||||
|
print "Page: %s" % page.source
|
||||||
|
page.write()
|
||||||
|
|
||||||
|
def get_template(self, name):
|
||||||
|
return self.env.get_template(name)
|
||||||
|
|
||||||
|
class Page(object):
|
||||||
|
|
||||||
|
def __init__(self, site, filename, curr_path, tgt_path):
|
||||||
|
self.site = site
|
||||||
|
self.filename = filename
|
||||||
|
self.source = os.path.join(curr_path, filename)
|
||||||
|
self.headers = {}
|
||||||
|
self.body = ""
|
||||||
|
|
||||||
|
with open(self.source, 'Ur') as handle:
|
||||||
|
headers, body = handle.read().split("\n\n", 1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
for line in headers.splitlines():
|
||||||
|
name, value = line.split(':', 1)
|
||||||
|
self.headers[name.strip()] = value.strip()
|
||||||
|
except ValueError:
|
||||||
|
self.headers = {}
|
||||||
|
body = "\n\n".join([headers, body])
|
||||||
|
self.headers['pubDate'] = ctime = os.stat(self.source).st_ctime
|
||||||
|
self.headers['published'] = datetime.datetime.fromtimestamp(ctime)
|
||||||
|
|
||||||
|
basename, oldext = os.path.splitext(filename)
|
||||||
|
oldext = oldext.lower()[1:]
|
||||||
|
converter = getattr(self, "convert_%s" % oldext, lambda x: x)
|
||||||
|
self.body = converter(body)
|
||||||
|
|
||||||
|
newfn = "%s.%s" % (basename, self.headers.get('ext', 'html'))
|
||||||
|
self.target = os.path.join(tgt_path, newfn)
|
||||||
|
|
||||||
|
def url(self):
|
||||||
|
path = self.target.split(conf.OUTPUT_PATH)[1].lstrip('/')
|
||||||
|
return "/".join([self.site.url, path])
|
||||||
|
|
||||||
|
def needed(self):
|
||||||
|
for f in "force --force -f":
|
||||||
|
if f in sys.argv[1:]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if not os.path.exists(self.target):
|
||||||
|
return True
|
||||||
|
|
||||||
|
smtime = os.stat(self.source).st_mtime
|
||||||
|
tmtime = os.stat(self.target).st_mtime
|
||||||
|
return smtime > tmtime
|
||||||
|
|
||||||
|
def write(self):
|
||||||
|
contents = self.render()
|
||||||
|
with codecs.open(self.target, 'w', 'utf-8') as tgt:
|
||||||
|
tgt.write(contents)
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
tmpl_name = self.headers.get('template', conf.DEFAULT_TEMPLATE)
|
||||||
|
|
||||||
|
kwargs = {"conf": conf, "stuff": self.body, "url": self.url()}
|
||||||
|
kwargs.update(self.headers)
|
||||||
|
print self.body
|
||||||
|
|
||||||
|
return self.site.get_template(tmpl_name).render(kwargs)
|
||||||
|
|
||||||
|
def convert_rst(self, body):
|
||||||
|
parts = publish_parts(source=body, writer_name="html")
|
||||||
|
return parts['html_body']
|
||||||
|
|
||||||
|
def main():
|
||||||
|
Site().render()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
21
doc/conf.py
Normal file
21
doc/conf.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -
|
||||||
|
#
|
||||||
|
# This file is part of gunicorn released under the MIT license.
|
||||||
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
# options
|
||||||
|
SITE_NAME = "Green Unicorn"
|
||||||
|
SITE_URL = "http://www.gunicorn.org"
|
||||||
|
SITE_DESCRIPTION = "A Python port of Ruby's Unicorn project."
|
||||||
|
|
||||||
|
EXTENSIONS = ['.rst']
|
||||||
|
DEFAULT_TEMPLATE = "default.html"
|
||||||
|
CONTENT_TYPE = "textile"
|
||||||
|
|
||||||
|
# paths
|
||||||
|
DOC_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
TEMPLATES_PATH = os.path.join(DOC_PATH, "templates")
|
||||||
|
INPUT_PATH = os.path.join(DOC_PATH, "site")
|
||||||
|
OUTPUT_PATH = os.path.join(DOC_PATH, "htdocs")
|
||||||
12
doc/site/index.rst
Normal file
12
doc/site/index.rst
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
template: index.html
|
||||||
|
|
||||||
|
|
||||||
|
This is some markup
|
||||||
|
===================
|
||||||
|
|
||||||
|
More stuff::
|
||||||
|
|
||||||
|
Hello there.
|
||||||
|
Yes... yes... yes!
|
||||||
|
|
||||||
|
And done.
|
||||||
24
doc/templates/base.html
vendored
Normal file
24
doc/templates/base.html
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Green Unicorn - Welcome</title>
|
||||||
|
<link rel="stylesheet" href="/css/style.css" type="text/css" />
|
||||||
|
<link rel="alternate" type="application/rss+xml" href="/feed.xml" />
|
||||||
|
|
||||||
|
<!--[if IE]>
|
||||||
|
<script>
|
||||||
|
document.createElement('section');
|
||||||
|
document.createElement('article');
|
||||||
|
document.createElement('aside');
|
||||||
|
document.createElement('footer');
|
||||||
|
document.createElement('header');
|
||||||
|
document.createElement('nav');
|
||||||
|
document.createElement('time');
|
||||||
|
</script>
|
||||||
|
<![endif]-->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block body %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
3
doc/templates/index.html
vendored
Normal file
3
doc/templates/index.html
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block body %}{{ stuff }}{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user