[fix] fix toc for docs, url for local and other fixes #2293 (#2346)

This commit is contained in:
Rushabh Mehta 2016-11-21 16:43:16 +05:30 committed by GitHub
parent e26e80cf5c
commit 3c7c17215d
9 changed files with 25 additions and 15 deletions

View file

@ -6,4 +6,4 @@ import frappe
from frappe.website.utils import get_full_index
def get_context(context):
context.full_index = get_full_index(extn = True)
context.full_index = get_full_index()

View file

@ -6,4 +6,4 @@ import frappe
from frappe.website.utils import get_full_index
def get_context(context):
context.full_index = get_full_index(extn = True)
context.full_index = get_full_index()

View file

@ -4,7 +4,7 @@
version -%}
<div class="dev-header">
{{ version(app.name) }}
{{ source_link(app, name.replace(".", "/") + ".py") }}
{{ source_link(app, full_module_name.replace(".", "/") + ".py") }}
</div>
{{ automodule(name) }}

View file

@ -2,7 +2,7 @@
<ol>
{% for item in children_map[route] %}
<li>
<a href="{{ url_prefix }}{{ item.route }}">{{ item.title }}</a>
<a href="{{ url_prefix }}{{ item.route }}{{ item.extn or "" }}">{{ item.title }}</a>
{% if children_map[item.route] %}
{{ make_item_list(item.route, children_map) }}
{% endif %}

View file

@ -17,8 +17,9 @@ class setup_docs(object):
"""
self.app = app
frappe.local.flags.web_pages_folders = ['docs',]
frappe.local.flags.web_pages_apps = [self.app,]
frappe.flags.web_pages_folders = ['docs',]
frappe.flags.web_pages_apps = [self.app,]
self.hooks = frappe.get_hooks(app_name = self.app)
self.app_title = self.hooks.get("app_title")[0]
@ -160,6 +161,8 @@ class setup_docs(object):
self.target = target
self.local = local
frappe.flags.local_docs = local
if self.local:
self.docs_base_url = ""
else:
@ -191,8 +194,10 @@ class setup_docs(object):
for f in files:
if f.endswith(".py"):
module_name = os.path.relpath(os.path.join(basepath, f),
self.app_path)[:-3].replace("/", ".").replace(".__init__", "")
full_module_name = os.path.relpath(os.path.join(basepath, f),
self.app_path)[:-3].replace("/", ".")
module_name = full_module_name.replace(".__init__", "")
module_doc_path = os.path.join(module_folder,
self.app + "." + module_name + ".html")
@ -204,6 +209,7 @@ class setup_docs(object):
with open(module_doc_path, "w") as f:
context = {"name": self.app + "." + module_name}
context.update(self.app_context)
context['full_module_name'] = self.app + '.' + full_module_name
f.write(frappe.render_template("templates/autodoc/pymodule.html",
context).encode('utf-8'))
@ -269,7 +275,7 @@ class setup_docs(object):
def write_files(self):
"""render templates and write files to target folder"""
frappe.local.flags.home_page = "index"
frappe.flags.home_page = "index"
from frappe.website.router import get_pages, make_toc
pages = get_pages(self.app)
@ -346,7 +352,7 @@ class setup_docs(object):
html = frappe.render_template(context.source, context)
html = make_toc(context, html)
html = make_toc(context, html, self.app)
if not "<!-- autodoc -->" in html:
html = html.replace('<!-- edit-link -->',

View file

@ -249,12 +249,12 @@ def setup_index(page_info):
if os.path.exists(index_txt_path):
page_info.index = open(index_txt_path, 'r').read().splitlines()
def make_toc(context, out):
def make_toc(context, out, app=None):
'''Insert full index (table of contents) for {index} tag'''
from frappe.website.utils import get_full_index
if '{index}' in out:
html = frappe.get_template("templates/includes/full_index.html").render({
"full_index": get_full_index(),
"full_index": get_full_index(app=app),
"url_prefix": context.url_prefix or "/",
"route": context.route
})
@ -264,7 +264,7 @@ def make_toc(context, out):
if '{next}' in out:
# insert next link
next_item = None
children_map = get_full_index()
children_map = get_full_index(app=app)
parent_route = os.path.dirname(context.route)
children = children_map[parent_route]

View file

@ -182,23 +182,27 @@ def abs_url(path):
path = "/" + path
return path
def get_full_index(route=None, extn = False):
def get_full_index(route=None, app=None):
"""Returns full index of the website for www upto the n-th level"""
if not frappe.local.flags.children_map:
from frappe.website.router import get_pages
children_map = {}
pages = get_pages()
pages = get_pages(app=app)
# make children map
for route, page_info in pages.iteritems():
parent_route = os.path.dirname(route)
children_map.setdefault(parent_route, []).append(page_info)
if frappe.flags.local_docs:
page_info.extn = '.html'
# order as per index if present
for route, children in children_map.items():
page_info = pages[route]
if page_info.index:
new_children = []
page_info.extn = ''
for name in page_info.index:
child_route = page_info.route + '/' + name
if child_route in pages: