WhakerKit 2.0

https://sourceforge.net/projects/whakerkit/

Module whakerkit.nodes

Class WhakerKitHeadNode

Description

Node for the head of each page.

Constructor

Create the head node.

Parameters
  • parent
  • title
View Source
def __init__(self, parent, title: str='WhakerKit'):
    """Create the head node.

    """
    self._components_activated = list()
    super(WhakerKitHeadNode, self).__init__(parent)
    self.reset(title)

Public functions

reset

Reset the head to its default values.

Parameters
  • title: The title of the page to be added into the head.
View Source
def reset(self, title: str):
    """Reset the head to its default values.

        :param title: The title of the page to be added into the head.

        """
    self.clear_children()
    self.meta({'charset': 'utf-8'})
    self.meta({'http-equiv': 'X-UA-Compatible', 'content': 'IE=edge'})
    self.meta({'name': 'keywords', 'content': 'WhakerKit, WhakerPy, Whakerexa, Brigitte, Bigi, CNRS'})
    self.meta({'name': 'viewport', 'content': 'width=device-width, initial-scale=1.0, user-scalable=yes'})
    title_node = HTMLNode(self.identifier, 'title', 'title', value=title)
    self.append_child(title_node)
    self.link(rel='stylesheet', href=whakerkit.sg.whakerexa + 'css/wexa.css', link_type=CSS_MIME_TYPE)
    self.link(rel='stylesheet', href=whakerkit.sg.whakerexa + 'css/layout.css', link_type=CSS_MIME_TYPE)
    self.link(rel='stylesheet', href=whakerkit.sg.whakerexa + 'css/button.css', link_type=CSS_MIME_TYPE)
    self.link(rel='stylesheet', href=whakerkit.sg.whakerexa + 'css/menu.css', link_type=CSS_MIME_TYPE)
    self.link(rel='stylesheet', href=whakerkit.sg.path + 'statics/css/whakerkit.css', link_type=CSS_MIME_TYPE)
    self.script(src=whakerkit.sg.whakerexa + 'js/wexa.js', script_type='module')
    self.script(src=whakerkit.sg.whakerexa + 'js/whakerpy/request.js', script_type=JS_MIME_TYPE)
    self.append_child(HTMLNode(self.identifier, None, 'script', value=SUBMIT_BTN_SCRIPT, attributes={'type': 'module'}))

enable_component

Enable styles and scripts for the specified component.

Parameters
  • component_name: (str) Name of the component to enable.
View Source
def enable_component(self, component_name: str) -> bool:
    """Enable styles and scripts for the specified component.

        :param component_name: (str) Name of the component to enable.

        """
    try:
        files = Components.get(component_name)
    except KeyError:
        logging.warning(f"Component '{component_name}' is not registered.")
        return False
    if component_name not in self._components_activated:
        for file in files:
            if file.endswith('.css'):
                self.link(rel='stylesheet', href=whakerkit.sg.whakerexa + 'css/' + file, link_type=CSS_MIME_TYPE)
            elif file.endswith('.js'):
                self.script(whakerkit.sg.whakerexa + 'js/' + file, script_type=JS_MIME_TYPE)
            else:
                logging.warning(f"Unknown required file '{file}' for component '{component_name}'")
        self._components_activated.append(component_name)
    else:
        logging.debug(f"The component '{component_name}' is already enabled.")
    return True