From cd0965413f230006264793ce9fca8611b1a7f67a Mon Sep 17 00:00:00 2001 From: SebastianGode <70581801+SebastianGode@users.noreply.github.com> Date: Wed, 12 Jun 2024 17:24:58 +0200 Subject: [PATCH] change existing wrappers (#36) change existing wrappers Reviewed-by: Tino Schr --- doc/source/_static/{ => images}/ansible.svg | 0 doc/source/examples/card_item.rst | 49 ++++++++ doc/source/examples/index.rst | 1 + otc_sphinx_directives/card_item.py | 108 ++++++++++++++++++ otc_sphinx_directives/directive_wrapper.py | 35 +++--- .../otc_sphinx_directives_setup.py | 4 + 6 files changed, 178 insertions(+), 19 deletions(-) rename doc/source/_static/{ => images}/ansible.svg (100%) create mode 100644 doc/source/examples/card_item.rst create mode 100644 otc_sphinx_directives/card_item.py diff --git a/doc/source/_static/ansible.svg b/doc/source/_static/images/ansible.svg similarity index 100% rename from doc/source/_static/ansible.svg rename to doc/source/_static/images/ansible.svg diff --git a/doc/source/examples/card_item.rst b/doc/source/examples/card_item.rst new file mode 100644 index 0000000..7fcd7e3 --- /dev/null +++ b/doc/source/examples/card_item.rst @@ -0,0 +1,49 @@ +Card Item Test +=================== + +.. directive_wrapper:: + :class: card-item-wrapper + + .. card_item:: + :title: Ansible + :image: ../_static/images/ansible.svg + :description: Ansible is a suite of software tools that enables infrastructure as code. It is open-source and the suite includes software provisioning, configuration management, and application deployment functionality. + + - OTC Ansible Collection|https://docs.otc-service.com/ansible-collection-cloud + - Release Notes|https://docs.otc-service.com/ansible-collection-cloud + - Release Notes|https://docs.otc-service.com/ansible-collection-cloud + + .. card_item:: + :title: Ansible + :image: ../_static/images/ansible.svg + :description: Ansible is a suite of software tools that enables infrastructure as code. It is open-source and the suite includes software provisioning, configuration management, and application deployment functionality. + + - Ansible Collection|https://docs.otc-service.com/ansible-collection-cloud + + .. card_item:: + :title: Ansible + :image: ../_static/images/ansible.svg + :description: Ansible is a suite of software tools that enables infrastructure as code. It is open-source and the suite includes software provisioning, configuration management, and application deployment functionality. + + - Ansible Collection|https://docs.otc-service.com/ansible-collection-cloud + + .. card_item:: + :title: Ansible + :image: ../_static/images/ansible.svg + :description: Ansible is a suite of software tools that enables infrastructure as code. It is open-source and the suite includes software provisioning, configuration management, and application deployment functionality. + + - Ansible Collection|https://docs.otc-service.com/ansible-collection-cloud + + .. card_item:: + :title: Ansible + :image: ../_static/images/ansible.svg + :description: Ansible is a suite of software tools that enables infrastructure as code. It is open-source and the suite includes software provisioning, configuration management, and application deployment functionality. + + - Ansible Collection|https://docs.otc-service.com/ansible-collection-cloud + + .. card_item:: + :title: Ansible + :image: ../_static/images/ansible.svg + :description: Ansible is a suite of software tools that enables infrastructure as code. It is open-source and the suite includes software provisioning, configuration management, and application deployment functionality. + + - Ansible Collection|https://docs.otc-service.com/ansible-collection-cloud diff --git a/doc/source/examples/index.rst b/doc/source/examples/index.rst index 8d30460..4827710 100644 --- a/doc/source/examples/index.rst +++ b/doc/source/examples/index.rst @@ -9,5 +9,6 @@ Documentation Examples directives_ecs_internal directives_docsportal container_item + card_item service_navigator docs_link diff --git a/otc_sphinx_directives/card_item.py b/otc_sphinx_directives/card_item.py new file mode 100644 index 0000000..11142ff --- /dev/null +++ b/otc_sphinx_directives/card_item.py @@ -0,0 +1,108 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# Description: +# The directive card_item can get 3 options. +# +# Options: +# - title: takes the Name of the linked item +# - image: takes the link to the picture in the static folder +# - external: if set, the link opens in a new tab +# +# Usage: +# .. directive_wrapper:: +# :class: card-item-wrapper +# +# .. card_item:: +# :title: Ansible +# :image: ../_static/images/ansible.svg +# :description: Ansible is a suite of software tools that enables infrastructure as code. It is open-source and the suite includes software provisioning, configuration management, and application deployment functionality. +# +# - OTC Ansible Collection|https://docs.otc-service.com/ansible-collection-cloud +# - Release Notes|https://docs.otc-service.com/ansible-collection-cloud + + +from docutils import nodes + +from docutils.parsers.rst import Directive +from docutils.parsers.rst import directives +from sphinx.util import logging + +LOG = logging.getLogger(__name__) + + +class card_item(nodes.General, nodes.Element): + pass + + +class CardItem(Directive): + node_class = card_item + option_spec = { + 'title': directives.unchanged_required, + 'image': directives.unchanged_required, + 'external': directives.unchanged, + 'description': directives.unchanged_required, + } + + has_content = True + + def run(self): + node = card_item() + node['title'] = self.options['title'] + node['image'] = self.options['image'] + node['description'] = self.options['description'] + # Check, if 'external' is available in self.options and set the value for the node + node['external'] = 'external' in self.options + links = [] + for ent in self.content: + _srv = ent.strip('- ') + data_parts = _srv.split("|") + title = data_parts[0] + href = data_parts[1] if len(data_parts) > 1 else '#' + links.append( + dict( + title=title, + href=href + ) + ) + node['links'] = links + return [node] + + +def card_item_html(self, node): + + data = f''' +