Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added dependency for additional data. Bumped plugin version.
  • Loading branch information
felixfontein committed Jul 13, 2015
1 parent ae07ad8 commit d8bdd56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions v7/wordpress_compiler/wordpress/wordpress.py
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion v7/wordpress_compiler/wordpress_compiler.plugin
Expand Up @@ -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.