Skip to content

Commit

Permalink
Modify XML macro parameters to allow arbitrary wrap string.
Browse files Browse the repository at this point in the history
Previously there were two hard-coded toke types at_tokens an dollar_tokens. Now all tokens for the same macro must have the same wrap string and this string can be set arbitrarily with token_wrap attribute. The defualt token_wrap value is @.
  • Loading branch information
jmchilton committed Jun 18, 2015
1 parent 0bc8b97 commit 1adabb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 12 additions & 8 deletions lib/galaxy/util/xml_macros.py
Expand Up @@ -245,15 +245,19 @@ class XmlMacroDef(object):
def __init__(self, el):
self.elements = list(el)
parameters = {}
tokens = []
token_wrap = "@"
for key, value in el.attrib.items():
for char, char_descript in [("@", "at"), ("$", "dollar")]:
if key == "%s_tokens" % char_descript:
for at_token in value.split(","):
parameter_name = at_token
parameters[parameter_name] = (char, REQUIRED_PARAMETER)
elif key.startswith("%s_token_" % char_descript):
parameter_name = key[len("%s_token_" % char_descript):]
parameters[parameter_name] = (char, value)
if key == "token_wrap":
token_wrap = value
if key == "tokens":
for token in value.split(","):
tokens.append((token, REQUIRED_PARAMETER))
elif key.startswith("token_"):
token = key[len("token_"):]
tokens.append((token, value))
for name, default in tokens:
parameters[name] = (token_wrap, default)
self.parameters = parameters

def macro_tokens(self, expand_el):
Expand Down
6 changes: 3 additions & 3 deletions test/unit/tools/test_tool_loader.py
Expand Up @@ -196,8 +196,8 @@ def load(self, name="tool.xml", preprocess=True):
<tool>
<expand macro="inputs" bar="hello" />
<macros>
<xml name="inputs" dollar_tokens="bar">
<inputs type="the type is $BAR$" />
<xml name="inputs" tokens="bar" token_wrap="$$">
<inputs type="the type is $$BAR$$" />
</xml>
</macros>
</tool>
Expand All @@ -215,7 +215,7 @@ def load(self, name="tool.xml", preprocess=True):
<expand macro="inputs" foo="world" />
<expand macro="inputs" />
<macros>
<xml name="inputs" at_token_foo="the_default">
<xml name="inputs" token_foo="the_default">
<inputs>@FOO@</inputs>
</xml>
</macros>
Expand Down

0 comments on commit 1adabb8

Please sign in to comment.