|
32 | 32 | from copy import copy
|
33 | 33 | from pkg_resources import resource_filename
|
34 | 34 | import datetime
|
| 35 | +import glob |
35 | 36 | import locale
|
36 | 37 | import os
|
37 | 38 | import json
|
@@ -896,7 +897,8 @@ def __init__(self, **config):
|
896 | 897 | else:
|
897 | 898 | self.bad_compilers.add(k)
|
898 | 899 |
|
899 |
| - self._set_global_context() |
| 900 | + self._set_global_context_from_config() |
| 901 | + self._set_global_context_from_data() |
900 | 902 |
|
901 | 903 | # Set persistent state facility
|
902 | 904 | self.state = Persistor('state_data.json')
|
@@ -1036,8 +1038,12 @@ def plugin_position_in_places(plugin):
|
1036 | 1038 | self._register_templated_shortcodes()
|
1037 | 1039 | signal('configured').send(self)
|
1038 | 1040 |
|
1039 |
| - def _set_global_context(self): |
1040 |
| - """Create global context from configuration.""" |
| 1041 | + def _set_global_context_from_config(self): |
| 1042 | + """Create global context from configuration. |
| 1043 | +
|
| 1044 | + These are options that are used by templates, so they always need to be |
| 1045 | + available. |
| 1046 | + """ |
1041 | 1047 | self._GLOBAL_CONTEXT['url_type'] = self.config['URL_TYPE']
|
1042 | 1048 | self._GLOBAL_CONTEXT['timezone'] = self.tzinfo
|
1043 | 1049 | self._GLOBAL_CONTEXT['_link'] = self.link
|
@@ -1128,6 +1134,16 @@ def _set_global_context(self):
|
1128 | 1134 |
|
1129 | 1135 | self._GLOBAL_CONTEXT.update(self.config.get('GLOBAL_CONTEXT', {}))
|
1130 | 1136 |
|
| 1137 | + def _set_global_context_from_data(self): |
| 1138 | + """Load files from data/ and put them in the global context.""" |
| 1139 | + self._GLOBAL_CONTEXT['data'] = {} |
| 1140 | + for fname in glob.glob('data/*'): |
| 1141 | + data = utils.load_data(fname) |
| 1142 | + key = os.path.basename(fname) |
| 1143 | + key = os.path.splitext(key)[0] |
| 1144 | + self._GLOBAL_CONTEXT['data'][key] = data |
| 1145 | + |
| 1146 | + |
1131 | 1147 | def _activate_plugins_of_category(self, category):
|
1132 | 1148 | """Activate all the plugins of a given category and return them."""
|
1133 | 1149 | # this code duplicated in tests/base.py
|
|
0 commit comments