Commit 984b26b7 authored by Denis Salem's avatar Denis Salem
Browse files

add restore() method to ProcessedString, upgrading Infinite Scroll plugin

parent 7c932b7b
......@@ -148,6 +148,9 @@
DONE | Escape patterns.
DONE | Chapters engine.
DONE | Fix pattern (i.e .:GetEntryTitle:.) access in template's metadata.
WIP | Infinite scroll use html anchor instead of harcoded indexing.
WIP | Prevent Infinite scroll to block when ressource isn't available.
WIP | Code improvement on Infinite Scroll
TODO | Fix unit test.
TODO | Open with navigator manual.
TODO | Client-side search engine.
......
......@@ -169,6 +169,12 @@ class ProcessedString():
self.keep_appart_from_markup_indexes = list()
self.keep_appart_from_markup_inc = 0
self.bop, self.bcp = [], []
self.backup = None
def restore(self):
self.open_pattern_pos, self.close_pattern_pos, self.len_open_pattern_pos, self.len_close_pattern_pos, self.string = self.backup
self.backup = None
def keep_appart_from_markup_indexes_append(self, paragraphe, new_chunk, escape):
if escape:
......@@ -329,8 +335,15 @@ class Processor():
return True
def process(self, pre_processed, escape=False):
op, cp, string, lo, lc = pre_processed.open_pattern_pos, pre_processed.close_pattern_pos, pre_processed.string, pre_processed.len_open_pattern_pos, pre_processed.len_close_pattern_pos
def process(self, pre_processed, escape=False, safe_process=False):
op, cp, lo, lc, string = pre_processed.open_pattern_pos, pre_processed.close_pattern_pos, pre_processed.len_open_pattern_pos, pre_processed.len_close_pattern_pos, pre_processed.string
if safe_process and pre_processed.backup == None:
try:
pre_processed.backup = (list(op), list(cp), lo, lc, str(pre_processed.string))
except Exception as e:
print(op, cp, lo, lc, string)
if lo == 0 and lc == 0:
op, cp = sorted(op+pre_processed.bop), sorted(cp+pre_processed.bcp)
pre_processed.bop, pre_processed.bcp = [], []
......@@ -354,11 +367,12 @@ class Processor():
vop, vcp = op[i], cp[j]
fields = [field.strip() for field in string[vop+2:vcp].split("::") if field != '']
current_pattern = fields[0]
if current_pattern in self.forbidden:
self.handle_error(
messages.pattern_is_forbidden_here.format(current_pattern),
",;"+current_pattern+";;"+";;".join(pre_processed.sub_strings[index][2:-2])+";,",
",;"+current_pattern+";;"+";;".join(string[vop+2:vcp].split("::"))+";,",
error_origin = [current_pattern]
)
......@@ -403,5 +417,7 @@ class Processor():
lo -= 1
lc -= 1
pre_processed.len_open_pattern_pos, pre_processed.len_close_pattern_pos, pre_processed.open_pattern_pos, pre_processed.close_pattern_pos, pre_processed.string = lo, lc, op, cp, string
self.process(pre_processed, escape)
pre_processed.len_open_pattern_pos, pre_processed.len_close_pattern_pos, pre_processed.open_pattern_pos, pre_processed.close_pattern_pos = lo, lc, op, cp
pre_processed.string = string
self.process(pre_processed, escape, safe_process)
......@@ -33,6 +33,7 @@ class Thread:
# Notify wich thread is processed
if prompt != "":
notify(prompt)
self.forbidden = forbidden
self.entries_per_page = int(datastore.blog_configuration["entries_per_pages"])
self.disable_threads = datastore.disable_threads
......@@ -78,7 +79,7 @@ class Thread:
self.pages_count = len(self.pages)
# Must be called in child class
def get_next_page(self,argv=list()):
def get_next_page(self, argv):
if self.current_page < self.pages_count - 1:
params = {
"page_number" : str(self.current_page + 1),
......@@ -105,7 +106,7 @@ class Thread:
return str()
# Must be called in child class
def get_previous_page(self, argv=list()):
def get_previous_page(self, argv):
if self.current_page > 0:
params = {
"page_number" : str(self.current_page - 1) if self.current_page - 1 != 0 else '',
......@@ -222,8 +223,9 @@ class Thread:
def pre_iteration(self):
self.processor.forbidden = self.forbidden
self.processor.process(self.header)
self.processor.process(self.header, safe_process = True)
self.output = self.header.string
self.header.restore()
self.processor.forbidden = []
self.columns_counter = 0
self.columns = [ '' for i in range(0, self.columns_number) ]
......@@ -234,8 +236,9 @@ class Thread:
self.output += self.column_opening.format(self.columns_counter)+column+self.column_closing
self.processor.forbidden = self.forbidden
self.processor.process(self.footer)
self.processor.process(self.footer, safe_process = True)
self.output += self.footer.string
self.footer.restore()
self.write_file(self.output.replace(".:GetRelativeOrigin:.", self.relative_origin), self.page_number)
......@@ -244,20 +247,24 @@ class Thread:
def do_iteration(self, entry):
content_header = getattr(entry,self.content_type+"_wrapper").above
self.processor.process(content_header)
self.processor.process(content_header, safe_process = True)
self.columns[self.columns_counter] += content_header.string
content_header.restore()
if (entry.html_wrapper.required_content_pattern == ".:GetEntryPreview:.") or (entry.html_wrapper.required_content_pattern == ".:PreviewIfInThreadElseContent:." and self.in_thread):
self.processor.process(entry.preview)
self.processor.process(entry.preview, safe_process = True)
self.columns[self.columns_counter] += entry.preview.string
entry.preview.restore()
else:
self.processor.process(entry.content)
self.processor.process(entry.content, safe_process = True)
self.columns[self.columns_counter] += entry.content.string
entry.content.restore()
content_footer = getattr(entry,self.content_type+"_wrapper").below
self.processor.process(content_footer)
self.processor.process(content_footer, safe_process = True)
self.columns[self.columns_counter] += content_footer.string
content_footer.restore()
self.columns_counter +=1
if self.columns_counter >= self.columns_number:
......
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