@@ -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, | |||
@@ -9,16 +9,16 @@ | |||
<link type="text/css" rel="stylesheet" href="/assets/css/bootstrap.css"> | |||
<link type="text/css" rel="stylesheet" href="/assets/css/hljs.css"> | |||
<script type="text/javascript" src="/assets/js/jquery.min.js"></script> | |||
<script type="text/javascript" src="/assets/js/bootstrap.min.js"></script> | |||
<script type="text/javascript" src="/assets/js/highlight.pack.js"></script> | |||
<script type="text/javascript" src="{{ github }}/assets/js/jquery.min.js"></script> | |||
<script type="text/javascript" src="{{ github }}/assets/js/bootstrap.min.js"></script> | |||
<script type="text/javascript" src="{{ github }}/assets/js/highlight.pack.js"></script> | |||
{% block favicon %} | |||
<link rel="shortcut icon" | |||
href="{{ (favicon or "/assets/img/favicon.png") | abs_url }}" | |||
href="{{ favicon or (github + "/assets/img/favicon.png") }}" | |||
type="image/x-icon"> | |||
<link rel="icon" | |||
href="{{ (favicon or "/assets/img/favicon.png") | abs_url }}" | |||
href="{{ favicon or (github + "/assets/img/favicon.png") }}" | |||
type="image/x-icon"> | |||
{% endblock %} | |||
@@ -76,13 +76,16 @@ | |||
</div> | |||
<footer class="page-footer"> | |||
<div class="container" data-html-block="footer"> | |||
{%- if footer is defined -%}{{ footer }}{%- endif -%} | |||
</div> | |||
{%- if footer is defined -%}{{ footer }}{%- endif -%} | |||
<br> | |||
<div class="text-center"> | |||
<b>A Frappe App</b><br> | |||
<a href="https://discuss.erpnext.com" | |||
target="_blank">Discuss this on the forum</a> | |||
</div> | |||
</div> | |||
</footer> | |||
</div> | |||
<div> | |||
{%- block footer -%}{% include "templates/includes/footer/footer.html" %}{%- endblock -%} | |||
</div> | |||
</div> | |||
<div class="modal-backdrop offcanvas-main-section-overlay"></div> | |||
<div class="sidebar sidebar-right visible-xs"> | |||
@@ -1,7 +1,7 @@ | |||
<!-- title: {{ app.title }} Documentation --> | |||
<!-- no-breadcrumbs --> | |||
{% from "templates/autodoc/macros.html" import github_link, version, discuss_link %} | |||
{% from "templates/autodoc/macros.html" import github_link, version %} | |||
<p> | |||
{{ version(app.name) }} | |||
{{ github_link(app, app.name, True) }} | |||
@@ -43,13 +43,11 @@ | |||
<h3>Contents</h3> | |||
<ul> | |||
<li> | |||
<a href="{{ '{{ pathname }}' }}/models">Models (DocTypes)</a> | |||
<a href="models">Models (DocTypes)</a> | |||
</li> | |||
<li> | |||
<a href="{{ '{{ pathname }}' }}/api">Server-side API</a> | |||
<a href="api">Server-side API</a> | |||
</li> | |||
</ul> | |||
{{ discuss_link() }} | |||
<!-- jinja --><!-- static --> |
@@ -1,7 +1,7 @@ | |||
<!-- title: {{ doctype }} --> | |||
{% from "templates/autodoc/macros.html" import automodule, version, | |||
github_link, doctype_link, discuss_link %} | |||
github_link, doctype_link %} | |||
{% set doc = frappe.get_doc("DocType", doctype) %} | |||
{% set controller = autodoc.get_controller(doctype) %} | |||
@@ -46,7 +46,7 @@ | |||
</td> | |||
<td>{% if df.options and df.fieldtype not in ("HTML") %} | |||
{% if df.fieldtype in ("Table", "Link") %} | |||
{{ doctype_link(df.options) }} | |||
{{ doctype_link(app, df.options) }} | |||
{% else %}<pre>{{ df.options }}</pre>{% endif %} | |||
{% endif %}</td> | |||
</tr> | |||
@@ -66,7 +66,7 @@ | |||
<h4>Linked In:</h4> | |||
<ul> | |||
{% for parent in parents %} | |||
<li>{{ doctype_link(parent.parent) }}</li> | |||
<li>{{ doctype_link(app, parent.parent) }}</li> | |||
{% endfor %} | |||
</ul> | |||
{% endif %} | |||
@@ -77,12 +77,10 @@ | |||
<h4>Child Table Of</h4> | |||
<ul> | |||
{% for parent in parents %} | |||
<li>{{ doctype_link(parent.parent) }}</li> | |||
<li>{{ doctype_link(app, parent.parent) }}</li> | |||
{% endfor %} | |||
</ul> | |||
{% endif %} | |||
{% endif %} | |||
<!-- jinja --><!-- static --> | |||
{{ discuss_link() }} |
@@ -55,15 +55,10 @@ | |||
target="_blank" style="margin-left: 10px; margin-bottom: 10px;"><i class="octicon octicon-mark-github"></i> Source</a> | |||
{% endmacro %} | |||
{% macro discuss_link() %} | |||
<br> | |||
<a href="https://discuss.erpnext.com" target="_blank">Discuss this on the forum</a> | |||
{% endmacro %} | |||
{% macro doctype_link(doctype) %} | |||
{% macro doctype_link(app, doctype) %} | |||
{% set module = frappe.db.get_value("DocType", doctype, "module") %} | |||
{% if doctype and module %} | |||
<a href="/{{'{{ pathname.split("/")[0] }}'}}/models/{{ | |||
<a href="{{ app.github }}/{{ app.docs_version }}/models/{{ | |||
scrub(module) }}/{{ scrub(doctype) }}">{{ doctype }}</a> | |||
{% endif %} | |||
{% endmacro %} |
@@ -1,12 +1,10 @@ | |||
<!-- title: {{ name }} --> | |||
{%- from "templates/autodoc/macros.html" import automodule, github_link, | |||
version, discuss_link -%} | |||
version -%} | |||
<p> | |||
{{ version(app.name) }} | |||
{{ github_link(app, name.replace(".", "/") + ".py") }} | |||
</p> | |||
{{ automodule(name) }} | |||
{{ discuss_link() }} |
@@ -12,16 +12,6 @@ | |||
{% include 'templates/includes/comments/comments.html' %} | |||
{%- endif %} | |||
</div> | |||
<script> | |||
$(function() { | |||
if(window.logged_in && getCookie("system_user")==="yes") { | |||
frappe.has_permission("Web Page", "{{ docname }}", "write", function(r) { | |||
frappe.require("/assets/frappe/js/frappe/website/editable.js"); | |||
frappe.make_editable($(".web-page-content"), "Web Page", "{{ docname }}", "main_section"); | |||
}); | |||
} | |||
}); | |||
</script> | |||
{% endblock %} | |||
{% block style %}{{ style or "" }}{% endblock %} | |||
@@ -1,4 +1,5 @@ | |||
<!-- post login tools --> | |||
{% if not only_static %} | |||
<li class="dropdown logged-in" id="website-post-login" | |||
data-label="website-post-login" style="display: none"> | |||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> | |||
@@ -23,3 +24,4 @@ | |||
{% if not hide_login %} | |||
<li class="btn-login-area"><a href="/login">{{ _("Login") }}</a></li> | |||
{% endif %} | |||
{% endif %} |
@@ -4,7 +4,7 @@ | |||
<ol> | |||
{% for item in items %} | |||
<li> | |||
<a href="/{{ item.name }}">{{ item.title }}</a> | |||
<a href="{% if relative_links %}{{ item.page_name }}{% else %}/{{ item.name }}{% endif %}{{ item.extn or '' }}">{{ item.title }}</a> | |||
</li> | |||
{% endfor %} | |||
</ol> | |||
@@ -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]) | |||
@@ -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) | |||
@@ -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 = ('<p class="btn-next-wrapper"><a class="btn-next" href="{name}">'+_("Next")+': {title}</a></p>').format(**next_item) | |||
html = ('<p class="btn-next-wrapper"><a class="btn-next" href="{name}{extn}">'+_("Next")+': {title}</a></p>').format(**next_item) | |||
else: | |||
html = "" | |||
@@ -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() | |||