Browse Source

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

version-14
Rushabh Mehta 8 years ago
committed by GitHub
parent
commit
3c7c17215d
9 changed files with 25 additions and 15 deletions
  1. +0
    -0
      frappe/docs/assets/img/app-development/__init__.py
  2. +0
    -0
      frappe/docs/assets/img/portals/__init__.py
  3. +1
    -1
      frappe/docs/contents.py
  4. +1
    -1
      frappe/templates/autodoc/contents.py
  5. +1
    -1
      frappe/templates/autodoc/pymodule.html
  6. +1
    -1
      frappe/templates/includes/full_index.html
  7. +12
    -6
      frappe/utils/setup_docs.py
  8. +3
    -3
      frappe/website/router.py
  9. +6
    -2
      frappe/website/utils.py

+ 0
- 0
frappe/docs/assets/img/app-development/__init__.py View File


+ 0
- 0
frappe/docs/assets/img/portals/__init__.py View File


+ 1
- 1
frappe/docs/contents.py View File

@@ -6,4 +6,4 @@ import frappe
from frappe.website.utils import get_full_index from frappe.website.utils import get_full_index


def get_context(context): def get_context(context):
context.full_index = get_full_index(extn = True)
context.full_index = get_full_index()

+ 1
- 1
frappe/templates/autodoc/contents.py View File

@@ -6,4 +6,4 @@ import frappe
from frappe.website.utils import get_full_index from frappe.website.utils import get_full_index


def get_context(context): def get_context(context):
context.full_index = get_full_index(extn = True)
context.full_index = get_full_index()

+ 1
- 1
frappe/templates/autodoc/pymodule.html View File

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


{{ automodule(name) }} {{ automodule(name) }}


+ 1
- 1
frappe/templates/includes/full_index.html View File

@@ -2,7 +2,7 @@
<ol> <ol>
{% for item in children_map[route] %} {% for item in children_map[route] %}
<li> <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] %} {% if children_map[item.route] %}
{{ make_item_list(item.route, children_map) }} {{ make_item_list(item.route, children_map) }}
{% endif %} {% endif %}


+ 12
- 6
frappe/utils/setup_docs.py View File

@@ -17,8 +17,9 @@ class setup_docs(object):
""" """
self.app = app 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.hooks = frappe.get_hooks(app_name = self.app)
self.app_title = self.hooks.get("app_title")[0] self.app_title = self.hooks.get("app_title")[0]
@@ -160,6 +161,8 @@ class setup_docs(object):
self.target = target self.target = target
self.local = local self.local = local


frappe.flags.local_docs = local

if self.local: if self.local:
self.docs_base_url = "" self.docs_base_url = ""
else: else:
@@ -191,8 +194,10 @@ class setup_docs(object):


for f in files: for f in files:
if f.endswith(".py"): 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, module_doc_path = os.path.join(module_folder,
self.app + "." + module_name + ".html") self.app + "." + module_name + ".html")
@@ -204,6 +209,7 @@ class setup_docs(object):
with open(module_doc_path, "w") as f: with open(module_doc_path, "w") as f:
context = {"name": self.app + "." + module_name} context = {"name": self.app + "." + module_name}
context.update(self.app_context) context.update(self.app_context)
context['full_module_name'] = self.app + '.' + full_module_name
f.write(frappe.render_template("templates/autodoc/pymodule.html", f.write(frappe.render_template("templates/autodoc/pymodule.html",
context).encode('utf-8')) context).encode('utf-8'))


@@ -269,7 +275,7 @@ class setup_docs(object):


def write_files(self): def write_files(self):
"""render templates and write files to target folder""" """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 from frappe.website.router import get_pages, make_toc
pages = get_pages(self.app) pages = get_pages(self.app)
@@ -346,7 +352,7 @@ class setup_docs(object):


html = frappe.render_template(context.source, context) html = frappe.render_template(context.source, context)


html = make_toc(context, html)
html = make_toc(context, html, self.app)


if not "<!-- autodoc -->" in html: if not "<!-- autodoc -->" in html:
html = html.replace('<!-- edit-link -->', html = html.replace('<!-- edit-link -->',


+ 3
- 3
frappe/website/router.py View File

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




+ 6
- 2
frappe/website/utils.py View File

@@ -182,23 +182,27 @@ def abs_url(path):
path = "/" + path path = "/" + path
return 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""" """Returns full index of the website for www upto the n-th level"""
if not frappe.local.flags.children_map: if not frappe.local.flags.children_map:
from frappe.website.router import get_pages from frappe.website.router import get_pages
children_map = {} children_map = {}
pages = get_pages()
pages = get_pages(app=app)


# make children map # make children map
for route, page_info in pages.iteritems(): for route, page_info in pages.iteritems():
parent_route = os.path.dirname(route) parent_route = os.path.dirname(route)
children_map.setdefault(parent_route, []).append(page_info) children_map.setdefault(parent_route, []).append(page_info)


if frappe.flags.local_docs:
page_info.extn = '.html'

# order as per index if present # order as per index if present
for route, children in children_map.items(): for route, children in children_map.items():
page_info = pages[route] page_info = pages[route]
if page_info.index: if page_info.index:
new_children = [] new_children = []
page_info.extn = ''
for name in page_info.index: for name in page_info.index:
child_route = page_info.route + '/' + name child_route = page_info.route + '/' + name
if child_route in pages: if child_route in pages:


Loading…
Cancel
Save