Browse Source

[docs] many fixes, options to add extensions, relative links in index in web pages

version-14
Rushabh Mehta 9 years ago
parent
commit
56a50de421
13 changed files with 78 additions and 54 deletions
  1. +1
    -1
      frappe/commands.py
  2. +13
    -10
      frappe/templates/autodoc/base_template.html
  3. +3
    -5
      frappe/templates/autodoc/docs_home.html
  4. +4
    -6
      frappe/templates/autodoc/doctype.html
  5. +2
    -7
      frappe/templates/autodoc/macros.html
  6. +1
    -3
      frappe/templates/autodoc/pymodule.html
  7. +0
    -10
      frappe/templates/generators/web_page.html
  8. +2
    -0
      frappe/templates/includes/navbar/navbar_login.html
  9. +1
    -1
      frappe/templates/includes/static_index.html
  10. +28
    -7
      frappe/utils/setup_docs.py
  11. +2
    -1
      frappe/website/context.py
  12. +15
    -2
      frappe/website/template.py
  13. +6
    -1
      frappe/website/website_generator.py

+ 1
- 1
frappe/commands.py View File

@@ -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,


+ 13
- 10
frappe/templates/autodoc/base_template.html View File

@@ -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">


+ 3
- 5
frappe/templates/autodoc/docs_home.html View File

@@ -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 -->

+ 4
- 6
frappe/templates/autodoc/doctype.html View File

@@ -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() }}

+ 2
- 7
frappe/templates/autodoc/macros.html View File

@@ -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
- 3
frappe/templates/autodoc/pymodule.html View File

@@ -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() }}

+ 0
- 10
frappe/templates/generators/web_page.html View File

@@ -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 %}


+ 2
- 0
frappe/templates/includes/navbar/navbar_login.html View File

@@ -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 %}

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

@@ -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>


+ 28
- 7
frappe/utils/setup_docs.py View File

@@ -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])


+ 2
- 1
frappe/website/context.py View File

@@ -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)


+ 15
- 2
frappe/website/template.py View File

@@ -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 = ""



+ 6
- 1
frappe/website/website_generator.py View File

@@ -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()


Loading…
Cancel
Save