diff --git a/frappe/commands.py b/frappe/commands.py index 71d0149a01..b4a8bf0814 100644 --- a/frappe/commands.py +++ b/frappe/commands.py @@ -357,7 +357,6 @@ def build_website(context): def make_dev_docs(context, app, docs_version): "Setup docs in target folder of target app" from frappe.utils.setup_docs import setup_docs - from frappe.website import statics for site in context.sites: try: frappe.init(site=site) @@ -946,6 +945,7 @@ commands = [ destroy_all_sessions, sync_www, build_website, + make_dev_docs, setup_docs, reset_perms, execute, diff --git a/frappe/templates/autodoc/base_template.html b/frappe/templates/autodoc/base_template.html index 1c1118431d..2414a00e2f 100644 --- a/frappe/templates/autodoc/base_template.html +++ b/frappe/templates/autodoc/base_template.html @@ -9,16 +9,16 @@ - - - + + + {% block favicon %} {% endblock %} @@ -76,13 +76,16 @@ -
- {%- block footer -%}{% include "templates/includes/footer/footer.html" %}{%- endblock -%} -
- {% endblock %} {% block style %}{{ style or "" }}{% endblock %} diff --git a/frappe/templates/includes/navbar/navbar_login.html b/frappe/templates/includes/navbar/navbar_login.html index 3e929bd886..62f986100f 100644 --- a/frappe/templates/includes/navbar/navbar_login.html +++ b/frappe/templates/includes/navbar/navbar_login.html @@ -1,4 +1,5 @@ +{% if not only_static %}
  • {{ _("Login") }}
  • {% endif %} +{% endif %} diff --git a/frappe/templates/includes/static_index.html b/frappe/templates/includes/static_index.html index c5f25009a7..c61bb001a6 100644 --- a/frappe/templates/includes/static_index.html +++ b/frappe/templates/includes/static_index.html @@ -4,7 +4,7 @@
      {% for item in items %}
    1. - {{ item.title }} + {{ item.title }}
    2. {% endfor %}
    diff --git a/frappe/utils/setup_docs.py b/frappe/utils/setup_docs.py index 29b9b60fe8..4b99b9c362 100644 --- a/frappe/utils/setup_docs.py +++ b/frappe/utils/setup_docs.py @@ -16,13 +16,14 @@ class setup_docs(object): and templates at `templates/autodoc` """ self.app = app + self.hooks = frappe.get_hooks(app_name = self.app) + self.app_title = self.hooks.get("app_title")[0] def build(self, docs_version): """Build templates for docs models and Python API""" self.path = frappe.get_app_path(self.app, "docs", docs_version) - hooks = frappe.get_hooks(app_name = self.app) - self.app_title = hooks.get("app_title")[0] + self.app_title = self.hooks.get("app_title")[0] self.app_path = frappe.get_app_path(self.app) print "Deleting current..." @@ -33,10 +34,12 @@ class setup_docs(object): "app": { "name": self.app, "title": self.app_title, - "description": markdown2.markdown(hooks.get("app_description")[0]), - "version": hooks.get("app_version")[0], - "publisher": hooks.get("app_publisher")[0], - "github_link": hooks.get("github_link")[0], + "description": markdown2.markdown(self.hooks.get("app_description")[0]), + "version": self.hooks.get("app_version")[0], + "publisher": self.hooks.get("app_publisher")[0], + "github_link": self.hooks.get("github_link")[0], + "github": self.hooks.get("github_pages_url")[0], + "docs_version": docs_version } } @@ -80,6 +83,7 @@ class setup_docs(object): def make_docs(self, target): self.target = target + print "Loadings docs..." sync = frappe.website.statics.sync() sync.start(path="docs", rebuild=True) @@ -183,6 +187,7 @@ class setup_docs(object): def write_files(self): """render templates and write files to target folder""" frappe.local.flags.home_page = "index" + github_pages_url = self.hooks.get("github_pages_url")[0] for page in frappe.db.sql("""select parent_website_route, page_name from `tabWeb Page`""", as_dict=True): @@ -194,7 +199,23 @@ class setup_docs(object): frappe.local.path = path - context = get_context(path) + context = get_context(path, { + "page_links_with_extn": True, + "relative_links": True + }) + + context.update({ + "brand_html": self.app_title, + "top_bar_items": [ + {"label": "User", "url":"/", "right": 1}, + {"label": "Developer", "url":"/current", "right": 1}, + {"label": "About", "url":"/user/about", "right": 1} + ], + "favicon": "/assets/img/favicon.ico", + "only_static": True, + "github_pages_url": github_pages_url, + }) + html = frappe.get_template("templates/autodoc/base_template.html").render(context) target_filename = os.path.join(self.target, context.template_path.split('/docs/', 1)[1]) diff --git a/frappe/website/context.py b/frappe/website/context.py index 0882fed340..0a1c960991 100644 --- a/frappe/website/context.py +++ b/frappe/website/context.py @@ -9,7 +9,7 @@ from frappe.website.template import build_template from frappe.website.router import get_route_info from frappe.website.utils import can_cache -def get_context(path): +def get_context(path, args=None): context = None context_cache = {} @@ -26,6 +26,7 @@ def get_context(path): if not context: context = get_route_info(path) + context.update(args) context = build_context(context) add_data_path(context) diff --git a/frappe/website/template.py b/frappe/website/template.py index ff5b9c4942..12d2d5de4d 100644 --- a/frappe/website/template.py +++ b/frappe/website/template.py @@ -109,18 +109,31 @@ def set_sidebar(out, context): def add_index(out, context): """Add index, next button if `{index}`, `{next}` is present.""" # table of contents + + extn = "" + if context.page_links_with_extn: + extn = ".html" + if "{index}" in out.get("content", "") and context.get("children"): + if extn: + for c in context.children: + c.extn = "" if context.doc.has_children(c.name) else extn + html = frappe.get_template("templates/includes/static_index.html").render({ - "items": context["children"]}) + "items": context.children, 'relative_links': context.relative_links}) out["content"] = out["content"].replace("{index}", html) # next and previous if "{next}" in out.get("content", ""): next_item = context.doc.get_next() + next_item.extn = "" if context.doc.has_children(c.name) else extn + if context.relative_links: + next_item.name = next_item.page_name + if next_item: if next_item.name[0]!="/": next_item.name = "/" + next_item.name - html = ('

    '+_("Next")+': {title}

    ').format(**next_item) + html = ('

    '+_("Next")+': {title}

    ').format(**next_item) else: html = "" diff --git a/frappe/website/website_generator.py b/frappe/website/website_generator.py index a708268ff3..9092c78363 100644 --- a/frappe/website/website_generator.py +++ b/frappe/website/website_generator.py @@ -210,9 +210,10 @@ class WebsiteGenerator(Document): return children def get_children_of(self, route): + """Return list of children of given route, for generating index in Web Page""" children = frappe.db.sql("""select name, page_name, parent_website_route, {title_field} as title from `tab{doctype}` - where ifnull(parent_website_route,'')=%s + where parent_website_route = %s order by {order_by}""".format( doctype = self.doctype, title_field = self.website.page_title_field or "name", @@ -224,6 +225,10 @@ class WebsiteGenerator(Document): return children + def has_children(self, route): + return frappe.db.sql('''select name from `tab{0}` + where parent_website_route = %s limit 1'''.format(self.doctype), route) + def get_next(self): if self.meta.get_field("parent_website_route") and self.parent_website_route: route = self.get_route()