joop.web.component — joop 0.0.1 documentation

# joop.web.component

Components are programmatic representations of data or UI elements, designed to be rendered dynamically,

  in the context of a web server.

A highly abstract class, the purpose of it is to provide a standard way to define inputs, outputs,

  and the transformations needed to render them. Components are the backbone of joop.web.

Classes:
  Component:

    The base class for all components, providing a structure for inputs, data, and subcomponents.

  JSONComponent:

    A specialized component for handling JSON data. Implementation pending.

Classes

`Component`([parent]) | Base class for programmatically rendering data or UI elements.
`JSONComponent`([parent]) | A specialized component for handling JSON data.

class joop.web.component.Component(parent: Component | None = None, *args, **kwargs)

  Bases: `object`

  Base class for programmatically rendering data or UI elements.

  This class provides a structure for defining inputs, data, and subcomponents, and includes methods for processing inputs and rendering components.

  inputs

    The input data for the component.

    Type:

      Inputs

  data

    The processed data for the component.

    Type:

      Data

  subs

    The subcomponents of the component.

    Type:

      SubComponents

  _process_inputs()

    Processes the inputs to generate the component’s data.

  render() → str

    Abstract method to render the component as a string.

  class Data

    Bases: `_Data`

    Class for defining the processed data of a component.

    _from_inputs(inputs

      Component.Inputs) -> Component.Data: Creates a Data instance from the given Inputs.

    from_inputs(inputs

      Component.Inputs) -> Component.Data: Abstract method to create a Data instance from the given Inputs.

    __init__() → None
    from_inputs

      A descriptor for defining abstract methods in classes.

      This class is particularly useful when working with ABCMeta classes and/or dataclasses. It allows marking methods as abstract, ensuring that they must be overridden in subclasses.

      Example usage:

        @classmethod def _my_abstract_class_method(cls, something: Any):

        > raise NotImplementedError(“Abstract; not implemented”)

        _my_abstract_class_method = AbstractMethod(_my_abstract_class_method)

      func

        The function to be marked as abstract.

        Type:

          callable

      _isabstract

        A flag indicating whether the method is abstract.

        Type:

          bool

  class Inputs

    Bases: `object`

    Abstract base class for defining the input data structure of a component.

    __init__() → None
  class SubComponents

    Bases: `object`

    Abstract base class for defining the subcomponents of a component.

    __init__() → None
  __init__(parent: Component | None = None, *args, **kwargs)

    Initialize a Component instance.

    Parameters:

      - parent (Optional[Component]) – The parent component, if any.

      - *args – Additional positional arguments.

      - **kwargs – Additional keyword arguments.

  data: Data
  inputs: Inputs
  abstract render() → str

    Abstract method to render the component as a string.

    This method processes the inputs and generates the component’s data before rendering it as a string. Subclasses must implement this method.

    Returns:

      The rendered component as a string.

    Return type:

      str

  subs: SubComponents

class joop.web.component.JSONComponent(parent: Component | None = None, *args, **kwargs)

  Bases: `Component`

  A specialized component for handling JSON data.

  Inherits:

    Component: The base Component class.

  class Data

    Bases: `_Data`

    Class for defining the processed data of a component.

    _from_inputs(inputs

      Component.Inputs) -> Component.Data: Creates a Data instance from the given Inputs.

    from_inputs(inputs

      Component.Inputs) -> Component.Data: Abstract method to create a Data instance from the given Inputs.

    __init__() → None
    from_inputs

      A descriptor for defining abstract methods in classes.

      This class is particularly useful when working with ABCMeta classes and/or dataclasses. It allows marking methods as abstract, ensuring that they must be overridden in subclasses.

      Example usage:

        @classmethod def _my_abstract_class_method(cls, something: Any):

        > raise NotImplementedError(“Abstract; not implemented”)

        _my_abstract_class_method = AbstractMethod(_my_abstract_class_method)

      func

        The function to be marked as abstract.

        Type:

          callable

      _isabstract

        A flag indicating whether the method is abstract.

        Type:

          bool

  class Inputs

    Bases: `object`

    Abstract base class for defining the input data structure of a component.

    __init__() → None
  class SubComponents

    Bases: `object`

    Abstract base class for defining the subcomponents of a component.

    __init__() → None
  __init__(parent: Component | None = None, *args, **kwargs)

    Initialize a Component instance.

    Parameters:

      - parent (Optional[Component]) – The parent component, if any.

      - *args – Additional positional arguments.

      - **kwargs – Additional keyword arguments.

  data: Data
  inputs: Inputs
  abstract render() → str

    Abstract method to render the component as a string.

    This method processes the inputs and generates the component’s data before rendering it as a string. Subclasses must implement this method.

    Returns:

      The rendered component as a string.

    Return type:

      str

  subs: SubComponents