commit/galaxy-central: carlfeberhard: PageServingPluginManager: allow additional common paths to be added to each plugin's TemplateLookup and allow configuration of these paths; Visualizations Framework: add common/templates, readme, and configuration of same
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/6af6d838db50/ Changeset: 6af6d838db50 User: carlfeberhard Date: 2014-02-05 17:55:13 Summary: PageServingPluginManager: allow additional common paths to be added to each plugin's TemplateLookup and allow configuration of these paths; Visualizations Framework: add common/templates, readme, and configuration of same Affected #: 3 files diff -r 9c4a45cd38e6fd6122698db67689c7aaacd0adac -r 6af6d838db509c1ce90a885d15a6e2cda2ef1e87 config/plugins/visualizations/additional_template_paths.xml --- /dev/null +++ b/config/plugins/visualizations/additional_template_paths.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- these relative paths can contain common templates importable by all visualization plugins --> +<paths> + <path>common/templates</path> +</paths> diff -r 9c4a45cd38e6fd6122698db67689c7aaacd0adac -r 6af6d838db509c1ce90a885d15a6e2cda2ef1e87 config/plugins/visualizations/common/templates/README.txt --- /dev/null +++ b/config/plugins/visualizations/common/templates/README.txt @@ -0,0 +1,8 @@ +Common templates for visualization plugins +========================================== + +Placing Mako templates in this directory will allow them to be properly +inherited and imported in plugin directories. E.g. if you have a template file +in this directory named 'config_utils.mako', you can import it in your plugin +templates using: + <%namespace name="config_utils" file="config_utils.mako" /> diff -r 9c4a45cd38e6fd6122698db67689c7aaacd0adac -r 6af6d838db509c1ce90a885d15a6e2cda2ef1e87 lib/galaxy/web/base/pluginframework.py --- a/lib/galaxy/web/base/pluginframework.py +++ b/lib/galaxy/web/base/pluginframework.py @@ -374,6 +374,8 @@ DEFAULT_TEMPLATE_COLLECTION_SIZE = 10 #: default encoding of plugin templates DEFAULT_TEMPLATE_ENCODING = 'utf-8' + #: name of files to search for additional template lookup directories + additional_template_paths_config_filename = 'additional_template_paths.xml' def __init__( self, app, base_url, template_cache_dir=None, **kwargs ): """ @@ -389,9 +391,42 @@ """ self.base_url = base_url self.template_cache_dir = template_cache_dir + self.additional_template_paths = [] super( PageServingPluginManager, self ).__init__( app, **kwargs ) + def load_configuration( self ): + """ + Load framework wide configuration, including: + additional template lookup directories + """ + for directory in self.directories: + possible_path = os.path.join( directory, self.additional_template_paths_config_filename ) + if os.path.exists( possible_path ): + added_paths = self.parse_additional_template_paths( possible_path, directory ) + self.additional_template_paths.extend( added_paths ) + + def parse_additional_template_paths( self, config_filepath, base_directory ): + """ + Parse an XML config file at `config_filepath` for template paths + (relative to `base_directory`) to add to each plugin's template lookup. + + Allows having a set of common templates for import/inheritance in + plugin templates. + + :type config_filepath: string + :param config_filepath: filesystem path to the config file + :type base_directory: string + :param base_directory: path prefixed to new, relative template paths + """ + additional_paths = [] + xml_tree = util.parse_xml( config_filepath ) + paths_list = xml_tree.getroot() + for rel_path_elem in paths_list.findall( 'path' ): + if rel_path_elem.text is not None: + additional_paths.append( os.path.join( base_directory, rel_path_elem.text ) ) + return additional_paths + def is_plugin( self, plugin_path ): """ Determines whether the given filesystem path contains a plugin. @@ -518,7 +553,11 @@ """ if not plugin.serves_templates: return None - template_lookup = self._create_mako_template_lookup( self.template_cache_dir, plugin.template_path ) + template_lookup_paths = plugin.template_path + if self.additional_template_paths: + template_lookup_paths = [ template_lookup_paths ] + self.additional_template_paths + #log.debug( 'template_lookup_paths: %s', template_lookup_paths ) + template_lookup = self._create_mako_template_lookup( self.template_cache_dir, template_lookup_paths ) return template_lookup def _create_mako_template_lookup( self, cache_dir, paths, Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org