Skip to content

Commit

Permalink
Updating the yaml constructors to update more dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoramite committed Jul 28, 2017
1 parent eebd1ed commit 8217652
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions grow/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def validate_name(name):
# TODO: better validation.
if ('//' in name
or '..' in name
or ' ' in name):
or ' ' in name):
raise errors.BadNameError(
'Names must be lowercase and only contain letters, numbers, '
'backslashes, and dashes. Found: "{}"'.format(name))
Expand Down Expand Up @@ -224,11 +224,14 @@ def _construct_func(self, node, func):
return func(node.value)

def construct_csv(self, node):
if doc:
pod.podcache.dependency_graph.add(doc.pod_path, node.value)
return self._construct_func(node, pod.read_csv)

def construct_doc(self, node):
locale = doc._locale_kwarg if doc else None
pod_path = doc.pod_path if doc else None

def func(path):
doc = pod.get_doc(path, locale=locale)
pod.podcache.dependency_graph.add(pod_path, doc.pod_path)
Expand All @@ -239,29 +242,41 @@ def construct_gettext(self, node):
return self._construct_func(node, gettext.gettext)

def construct_json(self, node):
if doc:
pod.podcache.dependency_graph.add(doc.pod_path, node.value)
return self._construct_func(node, pod.read_json)

def construct_static(self, node):
locale = doc._locale_kwarg if doc else None
func = lambda path: pod.get_static(path, locale=locale)
def func(path):
if doc:
pod.podcache.dependency_graph.add(doc.pod_path, path)
return pod.get_static(path, locale=locale)
return self._construct_func(node, func)

def construct_url(self, node):
locale = doc._locale_kwarg if doc else None
func = lambda path: pod.get_url(path, locale=locale)
def func(path):
if doc:
pod.podcache.dependency_graph.add(doc.pod_path, path)
return pod.get_url(path, locale=locale)
return self._construct_func(node, func)

def construct_yaml(self, node):
def func(path):
if '?' in path:
path, reference = path.split('?')
if doc:
pod.podcache.dependency_graph.add(doc.pod_path, path)
data = pod.read_yaml(path)
for key in reference.split('.'):
if data and key in data:
data = data[key]
else:
data = None
return data
if doc:
pod.podcache.dependency_graph.add(doc.pod_path, path)
return pod.read_yaml(path)
return self._construct_func(node, func)

Expand Down

0 comments on commit 8217652

Please sign in to comment.