[enhance] app wise help documentation (#2002)
* [enhance] app wise help documentation * [fix] data-path for contextual help links
This commit is contained in:
parent
9590ec546f
commit
5683f1f5aa
4 changed files with 38 additions and 15 deletions
|
|
@ -14,6 +14,7 @@ from .exceptions import *
|
|||
from .utils.jinja import get_jenv, get_template, render_template
|
||||
|
||||
__version__ = "7.0.27"
|
||||
__title__ = "Frappe Framework"
|
||||
|
||||
local = Local()
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
<li class="divider"></li>
|
||||
<li>
|
||||
<a data-link-type="documentation"
|
||||
data-path="/user/en/" target="_blank">Documentation</a>
|
||||
data-path="/documentation/index" target="_blank">Documentation</a>
|
||||
</li>
|
||||
<li class="divider documentation-links"></li>
|
||||
<li><a href="#" onclick="return frappe.ui.toolbar.show_about();">
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ frappe.ui.toolbar.Toolbar = Class.extend({
|
|||
});
|
||||
|
||||
$("#input-help + span").on("click", function () {
|
||||
var keywords = $(this).val();
|
||||
var keywords = $("#input-help").val();
|
||||
show_help_results(keywords);
|
||||
$(this).val("");
|
||||
});
|
||||
|
|
@ -115,10 +115,13 @@ frappe.ui.toolbar.Toolbar = Class.extend({
|
|||
for (var i = 0; i < links.length; i++) {
|
||||
var link = links[i];
|
||||
var url = link.url;
|
||||
var app_name = url.split('//', 2)[1].split('/', 2)[1];
|
||||
console.log(app_name)
|
||||
var data_path = url.slice(url.indexOf('/user'));
|
||||
if(data_path.lastIndexOf('.')){
|
||||
data_path = data_path.slice(0, data_path.lastIndexOf('.'));
|
||||
}
|
||||
data_path = data_path.replace('user', app_name);
|
||||
|
||||
$("<a>", {
|
||||
href: link.url,
|
||||
|
|
|
|||
|
|
@ -54,13 +54,14 @@ class HelpDatabase(object):
|
|||
def make_table(self):
|
||||
if not 'help' in self.db.get_tables():
|
||||
self.db.sql('''create table help(
|
||||
path text,
|
||||
path varchar(255),
|
||||
content text,
|
||||
title text,
|
||||
intro text,
|
||||
full_path text,
|
||||
fulltext(title),
|
||||
fulltext(content))
|
||||
fulltext(content),
|
||||
fulltext(path))
|
||||
COLLATE=utf8mb4_unicode_ci
|
||||
ENGINE=MyISAM
|
||||
CHARACTER SET=utf8mb4''')
|
||||
|
|
@ -75,9 +76,6 @@ class HelpDatabase(object):
|
|||
where path like "{path}%" order by path desc limit 1'''
|
||||
result = None
|
||||
|
||||
if not path.startswith('/user'):
|
||||
path = '%' + path
|
||||
|
||||
if not path.endswith('index'):
|
||||
result = self.db.sql(query.format(path=os.path.join(path, 'index')))
|
||||
|
||||
|
|
@ -88,10 +86,17 @@ class HelpDatabase(object):
|
|||
|
||||
def sync_pages(self):
|
||||
self.db.sql('truncate help')
|
||||
doc_contents = '<ol>'
|
||||
for app in os.listdir('../apps'):
|
||||
docs_folder = '../apps/{app}/{app}/docs/user'.format(app=app)
|
||||
self.out_base_path = '../apps/{app}/{app}/docs'.format(app=app)
|
||||
if os.path.exists(docs_folder):
|
||||
try:
|
||||
app_name = frappe.get_attr('{app}.__title__'.format(app=app)) or app
|
||||
doc_contents += '<li><a data-path="/{app}/index">{app_name}</a></li>'.format(
|
||||
app=app, app_name=app_name)
|
||||
except Exception, e:
|
||||
pass
|
||||
for basepath, folders, files in os.walk(docs_folder):
|
||||
files = self.reorder_files(files)
|
||||
for fname in files:
|
||||
|
|
@ -102,11 +107,16 @@ class HelpDatabase(object):
|
|||
{'docs_base_url': '/assets/{app}_docs'.format(app=app)})
|
||||
|
||||
relpath = self.get_out_path(fpath)
|
||||
content = self.make_content(content, fpath)
|
||||
relpath = relpath.replace("user", app)
|
||||
content = markdown(content)
|
||||
title = self.make_title(basepath, fname, content)
|
||||
intro = self.make_intro(content)
|
||||
content = self.make_content(content, fpath, relpath)
|
||||
self.db.sql('''insert into help(path, content, title, intro, full_path)
|
||||
values (%s, %s, %s, %s, %s)''', (relpath, content, title, intro, fpath))
|
||||
doc_contents += "</ol>"
|
||||
self.db.sql('''insert into help(path, content, title, intro, full_path) values (%s, %s, %s, %s, %s)''',
|
||||
('/documentation/index', doc_contents, 'Documentation', '', ''))
|
||||
|
||||
|
||||
def make_title(self, basepath, filename, html):
|
||||
|
|
@ -126,8 +136,10 @@ class HelpDatabase(object):
|
|||
intro = "Help Video: " + intro
|
||||
return intro
|
||||
|
||||
def make_content(self, content, path):
|
||||
html = markdown(content)
|
||||
def make_content(self, html, path, relpath):
|
||||
|
||||
if '<h1>' in html:
|
||||
html = html.split('</h1>', 1)[1]
|
||||
|
||||
if '{next}' in html:
|
||||
html = html.replace('{next}', '')
|
||||
|
|
@ -156,9 +168,9 @@ class HelpDatabase(object):
|
|||
if '.' in data_path:
|
||||
data_path = data_path[: data_path.rindex('.')]
|
||||
if data_path:
|
||||
link['data-path'] = data_path
|
||||
link['data-path'] = data_path.replace("user", app_name)
|
||||
|
||||
parent = self.get_parent(path)
|
||||
parent = self.get_parent(relpath)
|
||||
if parent:
|
||||
parent_tag = soup.new_tag('a')
|
||||
parent_tag.string = parent['title']
|
||||
|
|
@ -223,10 +235,17 @@ class HelpDatabase(object):
|
|||
child_path = child_path[: child_path.rindex('index')]
|
||||
if child_path[-1] == '/':
|
||||
child_path = child_path[:-1]
|
||||
child_path = child_path[: child_path.rindex('/')]
|
||||
|
||||
parent_path = self.get_out_path(child_path[: child_path.rindex('/')] + "/index")
|
||||
|
||||
out = self.get_content(parent_path)
|
||||
out = None
|
||||
if child_path:
|
||||
parent_path = child_path + "/index"
|
||||
out = self.get_content(parent_path)
|
||||
#if parent is documentation root
|
||||
else:
|
||||
parent_path = "/documentation/index"
|
||||
out = {}
|
||||
out['title'] = "Documentation"
|
||||
|
||||
if not out:
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue