Skip to content

Commit

Permalink
Improvements for theme techdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
t00m committed Dec 5, 2020
1 parent 2cfb389 commit 0284e03
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 177 deletions.
31 changes: 9 additions & 22 deletions kb4it/resources/themes/default/templates/CARD_DOC.tpl
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@

<!-- CARD_DOC_DEFAULT.tpl :: START -->
<div class="uk-card uk-card-default uk-width-1-1@m uk-card-hover" uk-scrollspy="target: > div; cls: uk-animation-fade; delay: 100" style="border:1px solid lightgray;">
<div class="uk-card-header">
<div class="uk-grid-small uk-flex-middle" uk-grid>
<div class="uk-width-expand">
<div class="uk-text-break uk-text-truncate uk-text-bold uk-margin-remove-bottom" uk-tooltip="${var['tooltip']}">
${var['title']}
<!-- DOC_CARD.tpl :: START -->
<div data-title="${var['data-title']}" class="uk-card uk-card-hover" uk-scrollspy="target: > div; cls: uk-animation-fade; delay: 100" style="">
<div class="uk-card-header">
<div class="uk-grid-small uk-flex-middle" uk-grid>
<div class="uk-width-expand">
<div class="uk-text-break uk-text-truncate uk-text-bold uk-margin-remove-bottom" uk-tooltip="${var['tooltip']}">${var['title']}</div>
<div class="uk-text-meta uk-margin-remove-top"><time datetime="${var['timestamp']}">${var['fuzzy_date']}</time> on ${var['category']}</div>
</div>
</div>
<p class="uk-text-meta uk-margin-remove-top">
<time datetime="${var['timestamp']}">${var['fuzzy_date']}</time>
</p>
</div>
</div>
</div>
<div class="uk-card uk-padding-small uk-padding-remove-bottom">
<div class="uk-flex uk-flex-right">
<ul class="uk-breadcrumb">
<li uk-tooltip="Category">${var['link_category']}</li>
<li uk-tooltip="Scope">${var['link_scope']}</li>
</ul>
</div>
</div>
</div>
<!-- CARD_DOC_DEFAULT.tpl :: END -->
<!-- DOC_CARD.tpl :: END -->
156 changes: 6 additions & 150 deletions kb4it/resources/themes/techdoc/logic/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ def build(self):
self.create_page_properties()
self.create_page_stats()
self.create_page_index_all()
self.create_page_index()
self.create_page_bookmarks()
# ~ self.create_page_authors()
self.create_page_index()
self.create_page_etype('Author', 'Category')
self.create_page_categories()
# ~ self.create_page_events()
# ~ self.create_page_blog()
self.create_page_etype('Category', 'Scope')
self.create_page_etype('Team', 'Scope')
self.create_page_recents()
self.create_page_bookmarks()

def create_page_index(self):
var = {}
Expand Down Expand Up @@ -315,8 +313,8 @@ def tab_header(docs):
items = ''
sect_items = 0
for doc in docs:
category = self.srvdtb.get_values(doc, 'Category')
if etype_item in category:
subkey_item = self.srvdtb.get_values(doc, subkey.title())
if etype_item in subkey_item:
items += self.get_doc_card(doc)
sect_items += 1
section['count_items'] = sect_items
Expand All @@ -335,145 +333,3 @@ def tab_header(docs):
html = TPL_PAGE_ETYPE.render(var=page)
basename = valid_filename("%s_%s" % (key.title(), key_item))
self.distribute(basename, html)


def create_page_authors(self):
TPL_PAGE_AUTHOR = self.template('PAGE_AUTHOR')
TPL_SECTION_ETYPE = self.template('PAGE_AUTHOR_SECTION_EVENT_TYPE')
TPL_SWITCHER_ETYPE = self.template('PAGE_AUTHOR_SWITCHER_EVENT_TYPE')
TPL_TAB_CENTER = self.template('TAB_CENTER')
TPL_TAB_ITEM = self.template('TAB_ITEM')
authors = self.srvdtb.get_all_values_for_key('Author')

def tab_header(docs):
author_etypes = set()
event_types = self.srvapp.get_theme_property('events')
for doc in docs:
categories = self.srvdtb.get_values(doc, 'Category')
for category in categories:
author_etypes.add(category)
items = ''
for etype in sorted(list(author_etypes)):
item = {}
item['name'] = etype.title()
items += TPL_TAB_ITEM.render(var=item)
tab = {}
tab['content'] = items
header = TPL_TAB_CENTER.render(var=tab)
authors = sorted(list(author_etypes))
return authors, header

for author in authors:
docs = self.srvdtb.get_docs_by_key_value('Author', author)
author_etypes, header = tab_header(docs)

# Registered event types
content_author = ''
for etype in author_etypes:
section = {}
items = ''
sect_items = 0
for doc in docs:
category = self.srvdtb.get_values(doc, 'Category')
if etype in category:
items += self.get_doc_card_author(doc)
sect_items += 1
section['count_items'] = sect_items
section['count_docs'] = len(docs)
section['items'] = items
content_author += TPL_SECTION_ETYPE.render(var=section)

page_author = {}
page_author['content'] = content_author
content = TPL_SWITCHER_ETYPE.render(var=page_author)
page = {}
page['title'] = author
page['header'] = header
page['content'] = content

html = TPL_PAGE_AUTHOR.render(var=page)
basename = valid_filename("Author_%s" % author)
self.distribute(basename, html)


def create_page_categories(self):
PAGE_CATEGORY = self.template('PAGE_CATEGORY')
SECTION_ETYPE = self.template('PAGE_CATEGORY_SECTION_SCOPE_TYPE')
SWITCHER_ETYPE = self.template('PAGE_CATEGORY_SWITCHER_SCOPE_TYPE')
categories = self.srvdtb.get_all_values_for_key('Category')
#FIXME: convert inline html to templates

def tab_header(docs):
scopes_category = set()
for doc in docs:
scopes = self.srvdtb.get_values(doc, 'Scope')
for scope in scopes:
scopes_category.add(scope)
header = """<ul class="uk-flex-center" uk-tab>\n"""
for scope in sorted(list(scopes_category)):
header += """<li><a href="#">%s</a></li>\n""" % scope.title()
header += """</ul>\n"""
return sorted(list(scopes_category)), header

for category in categories:
docs = self.srvdtb.get_docs_by_key_value('Category', category)
scopes_category, header = tab_header(docs)

content_category = ''
for this_scope in scopes_category:
items = ''
sect_items = 0
for doc in docs:
scopes = self.srvdtb.get_values(doc, 'Scope')
for scope in scopes:
if scope in this_scope:
items += self.get_doc_card_author(doc)
sect_items += 1
switcher = {}
switcher['sect_items'] = sect_items
switcher['len_docs'] = len(docs)
switcher['items'] = items
content_category += SECTION_ETYPE.render(var=switcher)

# Distribute
page_category = {}
page_category['content'] = content_category
content = SWITCHER_ETYPE.render(var=page_category)

page = {}
page['title'] = category
page['header'] = header
page['content'] = content

html = PAGE_CATEGORY.render(var=page)
basename = valid_filename("Category_%s" % category)
self.distribute(basename, html)

def get_doc_card_author(self, doc):
source_dir = self.srvapp.get_source_path()
DOC_CARD = self.template('CARD_DOC_AUTHOR')
LINK = self.template('LINK')
title = self.srvdtb.get_values(doc, 'Title')[0]
category = self.srvdtb.get_values(doc, 'Category')[0]
scope = self.srvdtb.get_values(doc, 'Scope')[0]

card = {}
card['data-title'] = "%s%s%s" % (title, category, scope)
link = {}
link['class'] = "uk-link-heading uk-text-meta"
link['url'] = "%s.html" % valid_filename(doc).replace('.adoc', '')
link['title'] = title
card['title'] = LINK.render(var=link)

link['url'] = "Category_%s.html" % valid_filename(category)
link['title'] = category
card['category'] = LINK.render(var=link)

link['url'] = "Scope_%s.html" % valid_filename(scope)
link['title'] = scope
card['scope'] = LINK.render(var=link)

card['timestamp'] = self.srvdtb.get_doc_timestamp(doc)
card['fuzzy_date'] = fuzzy_date_from_timestamp(card['timestamp'])
card['tooltip'] = title
return DOC_CARD.render(var=card) # % (title, tooltip, link_title, timestamp, fuzzy_date, link_scope)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<li>
<div class="uk-flex uk-flex-center"><span class="uk-text-meta">${var['count_items']}/${var['count_docs']} documents</span></div>
<div class="uk-child-width-1-3@m uk-grid-collapse" uk-grid>
<div class="uk-child-width-1-3@m uk-grid-small" uk-grid>
${var['items']}
</div>
</li>
Expand Down
2 changes: 1 addition & 1 deletion kb4it/resources/themes/techdoc/templates/TAB_ITEM.tpl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<li><a href="#">${var['name']}</a></li>
<li><a href="#" class="uk-text-capitalize">${var['name']}</a></li>
9 changes: 6 additions & 3 deletions kb4it/services/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,12 @@ def get_doc_card(self, doc):
TPL_DOC_CARD_CLASS = self.template('CARD_DOC_CLASS')
LINK = self.template('LINK')

title = self.srvdtb.get_values(doc, 'Title')[0]
var['category'] = self.srvdtb.get_values(doc, 'Category')[0]
var['scope'] = self.srvdtb.get_values(doc, 'Scope')[0]
title = self.srvdtb.get_values(doc, 'Title')[0]
category = self.srvdtb.get_values(doc, 'Category')[0]
scope = self.srvdtb.get_values(doc, 'Scope')[0]
var['category'] = category
var['scope'] = scope
var['data-title'] = "%s%s%s" % (title, category, scope)
var['content'] = ''
link = {}
link['class'] = TPL_DOC_CARD_CLASS.render()
Expand Down

0 comments on commit 0284e03

Please sign in to comment.