Skip to content
Permalink
Browse files

Added dependency for additional data. Bumped plugin version.

  • Loading branch information
felixfontein committed Jul 13, 2015
1 parent ae07ad8 commit d8bdd56267b3ab26b714ca090c1a8d8f5be05984
Showing with 10 additions and 6 deletions.
  1. +9 −5 v7/wordpress_compiler/wordpress/wordpress.py
  2. +1 −1 v7/wordpress_compiler/wordpress_compiler.plugin
@@ -227,23 +227,25 @@ def _read_similar_file(self, source, suffix):
try:
with open(candidate, "rb") as in_file:
# _LOGGER.info("Found file {0} for {1}.".format(candidate, source))
return in_file.read()
return in_file.read(), candidate
except:
pass
return None
return None, None

def load_additional_data(self, source):
result = {}
dependent_files = set()

attachments = self._read_similar_file(source, ".attachments.json")
attachments, filename = self._read_similar_file(source, ".attachments.json")
if attachments is not None:
try:
attachments = json.loads(attachments.decode('utf-8'))
result['attachments'] = attachments
dependent_files.add(filename)
except Exception as e:
_LOGGER.error("Could not load attachments for {0}! (Exception: {1})".format(source, e))

return result
return result, dependent_files

def compile_html(self, source, dest, is_two_file=False):
makedirs(os.path.dirname(dest))
@@ -254,9 +256,11 @@ def compile_html(self, source, dest, is_two_file=False):
if not is_two_file:
data = re.split('(\n\n|\r\n\r\n)', data, maxsplit=1)[-1]
# Read additional data
additional_data = self.load_additional_data(source)
additional_data, dependent_files = self.load_additional_data(source)
# Process post
context = Context(hash(data), name=source, additional_data=additional_data)
for filename in dependent_files:
context.add_file_dependency(filename, 'fragment')
output = self.__formatData(data, context)
# Write result
out_file.write(output)
@@ -7,6 +7,6 @@ MinVersion = 7.6.1

[Documentation]
Author = Felix Fontein
Version = 0.1
Version = 0.2
Website = https://felix.fontein.de
Description = Compile Wordpress-similar text into HTML

0 comments on commit d8bdd56

Please sign in to comment.
You can’t perform that action at this time.