Commit b96a0735 authored by Denis Salem's avatar Denis Salem
Browse files

Add missings templates and chapters.py, add ForEntryMetadata

parent b3ed53fb
......@@ -160,7 +160,10 @@ cd # version 1.0.0 Last minute edition :p
DONE | Semantic-web features.
DONE | Theme must have it's own yaml configuration.
DONE | Fix pattern processing within included file.
DONE | Add ForEntryMetadata
WIP | Reorganize themes dependencies in setup.
TODO | Include threads preview in entry
TODO | Add command for reorder entries by criteria
TODO | Fix Tessellation CSS
TODO | Add IfChapters and use it in academik to hide/show chapters navigation.
WIP | Add relevant templates for themes.
......@@ -206,7 +209,7 @@ cd # version 1.0.0 Last minute edition :p
TODO | Add draft support.
TODO | Add CPU threads support.
TODO | Regenerate any missing folders.
TODO | Override server port with extra arg.
TODO | Override server port with extra arg.
# version 3.x.x
TODO | Replace categories with taxonomy support.
......
authors: ''
categories: ''
tags: ''
title: Escape unit test
---VENC-BEGIN-PREVIEW---
---VENC-END-PREVIEW---
_As shown below Escape will disable parsing of both VenC patterns and markup language between the Escape/EndEscape pair._
__With Escape/EndEscape__
.:Escape::
- Hello VenC!
- Hello lovely user!
::EndEscape:.
.:Escape:: .:SetColor::This is red text!t::red:. ::EndEscape:.
__Without Escape/EndEscape__
- Hello VenC!
- Hello lovely user!
.:SetColor::This is red text!t::red:.
Please note that VenC syntax require you to close Escape pattern with ::EndEscape.
......@@ -30,6 +30,7 @@ from venc2.datastore.entry import Entry
from venc2.datastore.metadata import build_categories_tree
from venc2.datastore.metadata import MetadataNode
from venc2.datastore.metadata import Chapter
from venc2.helpers import GenericMessage
from venc2.prompt import notify
from venc2.l10n import messages
from venc2.patterns.exceptions import MalformedPatterns
......@@ -680,12 +681,32 @@ class DataStore:
return self.entries[self.requested_entry_index].html_tags[key]
def for_entry_metadata(self, argv):
if len(argv) != 2:
raise PatternMissingArguments(expected=2,got=len(argv))
entry = self.entries[self.requested_entry_index]
key = ''.join(argv)
try:
l = getattr(entry, argv[0]).split(',')
except:
raise GenericMessage(messages.entry_has_no_metadata_like.format(argv[0]))
if not key in entry.html_for_metadata:
entry.html_for_metadata[key] = ''.join([
argv[1].format(**{"item": item.strip()}) for item in l
])
return entry.html_for_metadata[key]
def for_entry_authors(self, argv):
entry = self.entries[self.requested_entry_index]
key = ''.join(argv)
if not key in self.entries[self.requested_entry_index].html_authors.keys():
self.entries[self.requested_entry_index].html_authors[key] = merge(self.entries[self.requested_entry_index].authors, argv)
if not key in entry.html_authors.keys():
entry.html_authors[key] = merge(entry.authors, argv)
return self.entries[self.requested_entry_index].html_authors[key]
return entry.html_authors[key]
""" TODO in 2.x.x: Access {count} and {weight} from LeavesForEntrycategories by taking benefit of preprocessing. """
def leaves_for_entry_categories(self, argv):
......
......@@ -172,6 +172,7 @@ class Entry:
self.html_tags = {}
self.html_authors = {}
self.html_categories_leaves = {}
self.html_for_metadata = {}
if jsonld_callback != None:
jsonld_callback(self)
......
......@@ -29,7 +29,6 @@ from venc2.l10n import messages
from venc2.prompt import die
from venc2.prompt import notify
class GenericMessage(Exception):
def __init__(self, message):
self.message = message
......
......@@ -111,5 +111,6 @@ class Messages:
nothing_to_serv = "Nothing to do. Try venc -xb before."
theme_has_no_description = "This theme has no description."
undefined_variable = "{0} is undefined in {1}."
too_much_call_of_content = "There is too much call of .:GetEntryContent:. and/or .:GetEntryPreview in {0}"
entry_has_no_metadata_like = "Entry has no metadata identified by {0}."
......@@ -109,3 +109,5 @@ class Messages:
nothing_to_serv = "Rien à faire. Essayez venc -xb d'abord."
theme_has_no_description = "Ce thème n'a pas de description."
undefined_variable = "{0} n'est pas défini dans \"{1}\"."
too_much_call_of_content = "Il y a trop d'appels de .:GetEntryContent:. et/ou de .:GetEntryPreview:. dans {0}"
entry_has_no_metadata_like = "La publication ne possède pas la métadonnée identifié par {0}."
......@@ -42,6 +42,7 @@ class PatternsMap():
# Extra metadata getter
"LeavesForEntryCategories" : datastore.leaves_for_entry_categories,
"TreeForEntryCategories" : datastore.tree_for_entry_categories,
"ForEntryMetadata" : datastore.for_entry_metadata,
"GetEntryMetadata" : datastore.get_entry_metadata,
"GetEntryMetadataIfExists" : datastore.get_entry_metadata_if_exists
},
......
#! /usr/bin/env python3
# Copyright 2016, 2019 Denis Salem
#
# This file is part of VenC.
#
# VenC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# VenC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with VenC. If not, see <http://www.gnu.org/licenses/>.
import os
from venc2.prompt import notify
from venc2.threads import Thread
class ChaptersThread(Thread):
def __init__(self, prompt, datastore, theme, patterns_map):
super().__init__(prompt, datastore, theme, patterns_map)
self.filename = self.datastore.blog_configuration["path"]["index_file_name"]
self.entries_per_page = self.datastore.blog_configuration["entries_per_pages"]
self.organize_entries([
entry for entry in datastore.get_entries(
False
)
])
self.folder_name = self.datastore.blog_configuration["path"]["chapter_directory_name"]
self.sub_folders = self.datastore.blog_configuration["path"]["chapters_sub_folders"]
self.relative_origin = str(''.join([ "../" for p in self.sub_folders.split('/') if p != ''])).replace("//",'/')
self.in_thread = True
def if_in_first_page(self, argv):
return argv[1].strip()
def if_in_last_page(self, argv):
return argv[1].strip()
def setup_chapters_context(self, i, top, len_top):
node = top[i]
if i == len_top-1:
tree_special_char = '└'
else:
tree_special_char = '├'
notify(self.indentation_level+tree_special_char+"─ "+node.index+' '+node.entry.title+"...")
self.export_path = "blog/"+self.sub_folders+'/'+self.folder_name
self.export_path = self.export_path.replace(' ','-').format(**{
"chapter_name" : node.entry.title,
"chapter_index": node.index
})
self.relative_origin = ''.join([ '../' for f in self.export_path.split("/")[1:] if f != '' ]).replace("//",'/')
try:
os.makedirs(self.export_path)
except FileExistsError:
pass
return (node)
def do(self, top=None):
if top == None:
top = self.datastore.chapters_index
for chapter_index in range(0, len(top)):
chapter = top[chapter_index]
self.organize_entries([ chapter.entry ] + [c.entry for c in chapter.sub_chapters])
self.setup_chapters_context(chapter_index, top, len(top))
super().do()
if len(chapter.sub_chapters) > 0:
self.do(chapter.sub_chapters)
def GetJSONLD(self, argv):
if self.current_page == 0:
return '<script type="application/ld+json" src="chapters.jsonld"></script>'
return ''
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment