Skip to content

Commit

Permalink
Merge pull request #28480 from GiudGiud/PR_tagging_pics
Browse files Browse the repository at this point in the history
Add support for a description and an image in tags
  • Loading branch information
GiudGiud authored Aug 28, 2024
2 parents 0543657 + fc8a183 commit 277e199
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions python/MooseDocs/extensions/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
def make_extension(**kwargs):
return TaggingExtension(**kwargs)

Tag = tokens.newToken('Tag', attr_name='', path='', key_vals=[])
Tag = tokens.newToken('Tag', attr_name='', path='', description='', image='', key_vals=[])

class TaggingExtension(command.CommandExtension):

Expand Down Expand Up @@ -98,9 +98,10 @@ def postExecute(self):
# Data dictionary saved as a string
replace_str = ""
for iter in self.getAttributeItems():
print(iter)
if bool(re.search('tag_', iter[0])):
tag_dict_str=str(iter[1])
key_list_regex = ['name', 'path', 'key_vals'] + self._allowed_keys
key_list_regex = ['name', 'path', 'image', 'description', 'key_vals'] + self._allowed_keys
for entry in key_list_regex:

# Remove single quotes around entry
Expand Down Expand Up @@ -209,13 +210,16 @@ def defaultSettings():
settings = command.CommandComponent.defaultSettings()
settings['name'] = (None, 'ID name for page and associated key:value category:label pairs.')
settings['pairs'] = (None, 'Key:value pairs representing categories and page-specific labels for each category.')
settings['image'] = (None, 'Link to an image to display for this entry')
settings['description'] = (None, 'Description of the entry')
return settings

def createToken(self, parent, info, page, settings):
"""
Process name and key:value pairs provided in the documentation file, check against
previously-processed names and keys, and add new data to global attributes.
"""
# Process input data
if settings['name'] is None:
msg = "%s: No 'name' provided for page and associated tags; check markdown file. " \
"This page will not be added to the tag database!"
Expand All @@ -229,12 +233,22 @@ def createToken(self, parent, info, page, settings):
keylist=''
else:
keylist=settings['pairs'].split()
# Downstream javascript does not support empty fields
if settings['description'] is None:
description = settings['name']
else:
description = settings['description']
if settings['image'] is None:
image = 'No Image'
else:
image=settings['image']
mpath=re.sub(r'^.*?moose/', 'moose/', page.source)
entry_key_values=[]
for keys in keylist:
key_vals=keys.split(':')
entry_key_values.append([key_vals[0],key_vals[1]])

# Check keys
good_keys=[]
for pair in entry_key_values:
if pair[0] not in self.extension.allowed_keys and len(self.extension.allowed_keys) > 0:
Expand All @@ -247,8 +261,9 @@ def createToken(self, parent, info, page, settings):
else:
good_keys.append([pair[0], pair[1]])

# Form tag token
if len(name) != 0: # Only add to tag database if 'name' is provided
page_data = {'name':name, "path":mpath, "key_vals":dict(good_keys)}
page_data = {'name':name, "path":mpath, "description":description, "image":image, "key_vals":dict(good_keys)}

tag_id_name = ''
if self.extension.get_tag_data("tag_" + name):
Expand All @@ -259,6 +274,6 @@ def createToken(self, parent, info, page, settings):
tag_id_name = "tag_" + name
self.extension.set_tag_data(tag_id_name, page_data)

Tag(parent, attr_name=tag_id_name, path=mpath, key_vals=dict(good_keys))
Tag(parent, attr_name=tag_id_name, path=mpath, description=description, image=image, key_vals=dict(good_keys))

return parent

0 comments on commit 277e199

Please sign in to comment.