@@ -357,7 +357,6 @@ def build_website(context): | |||||
def make_dev_docs(context, app, docs_version): | def make_dev_docs(context, app, docs_version): | ||||
"Setup docs in target folder of target app" | "Setup docs in target folder of target app" | ||||
from frappe.utils.setup_docs import setup_docs | from frappe.utils.setup_docs import setup_docs | ||||
from frappe.website import statics | |||||
for site in context.sites: | for site in context.sites: | ||||
try: | try: | ||||
frappe.init(site=site) | frappe.init(site=site) | ||||
@@ -946,6 +945,7 @@ commands = [ | |||||
destroy_all_sessions, | destroy_all_sessions, | ||||
sync_www, | sync_www, | ||||
build_website, | build_website, | ||||
make_dev_docs, | |||||
setup_docs, | setup_docs, | ||||
reset_perms, | reset_perms, | ||||
execute, | 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/bootstrap.css"> | ||||
<link type="text/css" rel="stylesheet" href="/assets/css/hljs.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 %} | {% block favicon %} | ||||
<link rel="shortcut icon" | <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"> | type="image/x-icon"> | ||||
<link rel="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"> | type="image/x-icon"> | ||||
{% endblock %} | {% endblock %} | ||||
@@ -76,13 +76,16 @@ | |||||
</div> | </div> | ||||
<footer class="page-footer"> | <footer class="page-footer"> | ||||
<div class="container" data-html-block="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> | </footer> | ||||
</div> | </div> | ||||
<div> | |||||
{%- block footer -%}{% include "templates/includes/footer/footer.html" %}{%- endblock -%} | |||||
</div> | |||||
</div> | </div> | ||||
<div class="modal-backdrop offcanvas-main-section-overlay"></div> | <div class="modal-backdrop offcanvas-main-section-overlay"></div> | ||||
<div class="sidebar sidebar-right visible-xs"> | <div class="sidebar sidebar-right visible-xs"> | ||||
@@ -1,7 +1,7 @@ | |||||
<!-- title: {{ app.title }} Documentation --> | <!-- title: {{ app.title }} Documentation --> | ||||
<!-- no-breadcrumbs --> | <!-- no-breadcrumbs --> | ||||
{% from "templates/autodoc/macros.html" import github_link, version, discuss_link %} | |||||
{% from "templates/autodoc/macros.html" import github_link, version %} | |||||
<p> | <p> | ||||
{{ version(app.name) }} | {{ version(app.name) }} | ||||
{{ github_link(app, app.name, True) }} | {{ github_link(app, app.name, True) }} | ||||
@@ -43,13 +43,11 @@ | |||||
<h3>Contents</h3> | <h3>Contents</h3> | ||||
<ul> | <ul> | ||||
<li> | <li> | ||||
<a href="{{ '{{ pathname }}' }}/models">Models (DocTypes)</a> | |||||
<a href="models">Models (DocTypes)</a> | |||||
</li> | </li> | ||||
<li> | <li> | ||||
<a href="{{ '{{ pathname }}' }}/api">Server-side API</a> | |||||
<a href="api">Server-side API</a> | |||||
</li> | </li> | ||||
</ul> | </ul> | ||||
{{ discuss_link() }} | |||||
<!-- jinja --><!-- static --> | <!-- jinja --><!-- static --> |
@@ -1,7 +1,7 @@ | |||||
<!-- title: {{ doctype }} --> | <!-- title: {{ doctype }} --> | ||||
{% from "templates/autodoc/macros.html" import automodule, version, | {% 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 doc = frappe.get_doc("DocType", doctype) %} | ||||
{% set controller = autodoc.get_controller(doctype) %} | {% set controller = autodoc.get_controller(doctype) %} | ||||
@@ -46,7 +46,7 @@ | |||||
</td> | </td> | ||||
<td>{% if df.options and df.fieldtype not in ("HTML") %} | <td>{% if df.options and df.fieldtype not in ("HTML") %} | ||||
{% if df.fieldtype in ("Table", "Link") %} | {% if df.fieldtype in ("Table", "Link") %} | ||||
{{ doctype_link(df.options) }} | |||||
{{ doctype_link(app, df.options) }} | |||||
{% else %}<pre>{{ df.options }}</pre>{% endif %} | {% else %}<pre>{{ df.options }}</pre>{% endif %} | ||||
{% endif %}</td> | {% endif %}</td> | ||||
</tr> | </tr> | ||||
@@ -66,7 +66,7 @@ | |||||
<h4>Linked In:</h4> | <h4>Linked In:</h4> | ||||
<ul> | <ul> | ||||
{% for parent in parents %} | {% for parent in parents %} | ||||
<li>{{ doctype_link(parent.parent) }}</li> | |||||
<li>{{ doctype_link(app, parent.parent) }}</li> | |||||
{% endfor %} | {% endfor %} | ||||
</ul> | </ul> | ||||
{% endif %} | {% endif %} | ||||
@@ -77,12 +77,10 @@ | |||||
<h4>Child Table Of</h4> | <h4>Child Table Of</h4> | ||||
<ul> | <ul> | ||||
{% for parent in parents %} | {% for parent in parents %} | ||||
<li>{{ doctype_link(parent.parent) }}</li> | |||||
<li>{{ doctype_link(app, parent.parent) }}</li> | |||||
{% endfor %} | {% endfor %} | ||||
</ul> | </ul> | ||||
{% endif %} | {% endif %} | ||||
{% endif %} | {% endif %} | ||||
<!-- jinja --><!-- static --> | <!-- 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> | target="_blank" style="margin-left: 10px; margin-bottom: 10px;"><i class="octicon octicon-mark-github"></i> Source</a> | ||||
{% endmacro %} | {% 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") %} | {% set module = frappe.db.get_value("DocType", doctype, "module") %} | ||||
{% if doctype and 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> | scrub(module) }}/{{ scrub(doctype) }}">{{ doctype }}</a> | ||||
{% endif %} | {% endif %} | ||||
{% endmacro %} | {% endmacro %} |
@@ -1,12 +1,10 @@ | |||||
<!-- title: {{ name }} --> | <!-- title: {{ name }} --> | ||||
{%- from "templates/autodoc/macros.html" import automodule, github_link, | {%- from "templates/autodoc/macros.html" import automodule, github_link, | ||||
version, discuss_link -%} | |||||
version -%} | |||||
<p> | <p> | ||||
{{ version(app.name) }} | {{ version(app.name) }} | ||||
{{ github_link(app, name.replace(".", "/") + ".py") }} | {{ github_link(app, name.replace(".", "/") + ".py") }} | ||||
</p> | </p> | ||||
{{ automodule(name) }} | {{ automodule(name) }} | ||||
{{ discuss_link() }} |
@@ -12,16 +12,6 @@ | |||||
{% include 'templates/includes/comments/comments.html' %} | {% include 'templates/includes/comments/comments.html' %} | ||||
{%- endif %} | {%- endif %} | ||||
</div> | </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 %} | {% endblock %} | ||||
{% block style %}{{ style or "" }}{% endblock %} | {% block style %}{{ style or "" }}{% endblock %} | ||||
@@ -1,4 +1,5 @@ | |||||
<!-- post login tools --> | <!-- post login tools --> | ||||
{% if not only_static %} | |||||
<li class="dropdown logged-in" id="website-post-login" | <li class="dropdown logged-in" id="website-post-login" | ||||
data-label="website-post-login" style="display: none"> | data-label="website-post-login" style="display: none"> | ||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> | <a href="#" class="dropdown-toggle" data-toggle="dropdown"> | ||||
@@ -23,3 +24,4 @@ | |||||
{% if not hide_login %} | {% if not hide_login %} | ||||
<li class="btn-login-area"><a href="/login">{{ _("Login") }}</a></li> | <li class="btn-login-area"><a href="/login">{{ _("Login") }}</a></li> | ||||
{% endif %} | {% endif %} | ||||
{% endif %} |
@@ -4,7 +4,7 @@ | |||||
<ol> | <ol> | ||||
{% for item in items %} | {% for item in items %} | ||||
<li> | <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> | </li> | ||||
{% endfor %} | {% endfor %} | ||||
</ol> | </ol> | ||||
@@ -16,13 +16,14 @@ class setup_docs(object): | |||||
and templates at `templates/autodoc` | and templates at `templates/autodoc` | ||||
""" | """ | ||||
self.app = app | 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): | def build(self, docs_version): | ||||
"""Build templates for docs models and Python API""" | """Build templates for docs models and Python API""" | ||||
self.path = frappe.get_app_path(self.app, "docs", docs_version) | 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) | self.app_path = frappe.get_app_path(self.app) | ||||
print "Deleting current..." | print "Deleting current..." | ||||
@@ -33,10 +34,12 @@ class setup_docs(object): | |||||
"app": { | "app": { | ||||
"name": self.app, | "name": self.app, | ||||
"title": self.app_title, | "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): | def make_docs(self, target): | ||||
self.target = target | self.target = target | ||||
print "Loadings docs..." | |||||
sync = frappe.website.statics.sync() | sync = frappe.website.statics.sync() | ||||
sync.start(path="docs", rebuild=True) | sync.start(path="docs", rebuild=True) | ||||
@@ -183,6 +187,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.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, | for page in frappe.db.sql("""select parent_website_route, | ||||
page_name from `tabWeb Page`""", as_dict=True): | page_name from `tabWeb Page`""", as_dict=True): | ||||
@@ -194,7 +199,23 @@ class setup_docs(object): | |||||
frappe.local.path = path | 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) | 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]) | 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.router import get_route_info | ||||
from frappe.website.utils import can_cache | from frappe.website.utils import can_cache | ||||
def get_context(path): | |||||
def get_context(path, args=None): | |||||
context = None | context = None | ||||
context_cache = {} | context_cache = {} | ||||
@@ -26,6 +26,7 @@ def get_context(path): | |||||
if not context: | if not context: | ||||
context = get_route_info(path) | context = get_route_info(path) | ||||
context.update(args) | |||||
context = build_context(context) | context = build_context(context) | ||||
add_data_path(context) | add_data_path(context) | ||||
@@ -109,18 +109,31 @@ def set_sidebar(out, context): | |||||
def add_index(out, context): | def add_index(out, context): | ||||
"""Add index, next button if `{index}`, `{next}` is present.""" | """Add index, next button if `{index}`, `{next}` is present.""" | ||||
# table of contents | # table of contents | ||||
extn = "" | |||||
if context.page_links_with_extn: | |||||
extn = ".html" | |||||
if "{index}" in out.get("content", "") and context.get("children"): | 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({ | 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) | out["content"] = out["content"].replace("{index}", html) | ||||
# next and previous | # next and previous | ||||
if "{next}" in out.get("content", ""): | if "{next}" in out.get("content", ""): | ||||
next_item = context.doc.get_next() | 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: | ||||
if next_item.name[0]!="/": next_item.name = "/" + next_item.name | 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: | else: | ||||
html = "" | html = "" | ||||
@@ -210,9 +210,10 @@ class WebsiteGenerator(Document): | |||||
return children | return children | ||||
def get_children_of(self, route): | 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, | children = frappe.db.sql("""select name, page_name, | ||||
parent_website_route, {title_field} as title from `tab{doctype}` | 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( | order by {order_by}""".format( | ||||
doctype = self.doctype, | doctype = self.doctype, | ||||
title_field = self.website.page_title_field or "name", | title_field = self.website.page_title_field or "name", | ||||
@@ -224,6 +225,10 @@ class WebsiteGenerator(Document): | |||||
return children | 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): | def get_next(self): | ||||
if self.meta.get_field("parent_website_route") and self.parent_website_route: | if self.meta.get_field("parent_website_route") and self.parent_website_route: | ||||
route = self.get_route() | route = self.get_route() | ||||