betty.url module - Betty 0.4.0a3 documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.url module

Provide a URL generation API.

final class betty.url.LocalizedPathUrlGenerator

  Bases: `LocalizedUrlGenerator`

  Generate URLs for localizable file paths.

  Parameters:

    project (`betty.project.Project`)

  __init__(project: betty.project.Project)
    Parameters:

      project (`betty.project.Project`)

  generate(resource: Any, media_type: str, absolute: bool = False, locale: str | babel.core.Locale | None = None) → str

    Generate a URL for a resource.

    Parameters:

      - resource (`typing.Any`)

      - media_type (`str`)

      - absolute (`bool`)

      - locale (`str` | `babel.core.Locale` | `None`)

    Return type:

      `str`

  supports(resource: Any) → bool

    Whether the given resource is supported by this URL generator.

    Parameters:

      resource (`typing.Any`)

    Return type:

      `bool`

class betty.url.LocalizedUrlGenerator

  Bases: `_UrlGenerator`

  Generate URLs for localizable resources.

  abstract generate(resource: Any, media_type: str, absolute: bool = False, locale: str | babel.core.Locale | None = None) → str

    Generate a URL for a resource.

    Parameters:

      - resource (`typing.Any`)

      - media_type (`str`)

      - absolute (`bool`)

      - locale (`str` | `babel.core.Locale` | `None`)

    Return type:

      `str`

final class betty.url.ProjectUrlGenerator

  Bases: `LocalizedUrlGenerator`

  Generate URLs for all resources provided by a Betty project.

  Parameters:

    project (`betty.project.Project`)

  __init__(project: betty.project.Project)
    Parameters:

      project (`betty.project.Project`)

  generate(resource: Any, media_type: str, absolute: bool = False, locale: str | babel.core.Locale | None = None) → str

    Generate a URL for a resource.

    Parameters:

      - resource (`typing.Any`)

      - media_type (`str`)

      - absolute (`bool`)

      - locale (`str` | `babel.core.Locale` | `None`)

    Return type:

      `str`

  supports(resource: Any) → bool

    Whether the given resource is supported by this URL generator.

    Parameters:

      resource (`typing.Any`)

    Return type:

      `bool`

final class betty.url.StaticPathUrlGenerator

  Bases: `StaticUrlGenerator`

  Generate URLs for static (non-localized) file paths.

  Parameters:

    configuration (`betty.project.ProjectConfiguration`)

  __init__(configuration: betty.project.ProjectConfiguration)
    Parameters:

      configuration (`betty.project.ProjectConfiguration`)

  generate(resource: Any, absolute: bool = False) → str

    Generate a URL for a resource.

    Parameters:

      - resource (`typing.Any`)

      - absolute (`bool`)

    Return type:

      `str`

  supports(resource: Any) → bool

    Whether the given resource is supported by this URL generator.

    Parameters:

      resource (`typing.Any`)

    Return type:

      `bool`

class betty.url.StaticUrlGenerator

  Bases: `_UrlGenerator`

  Generate URLs for static (non-localizable) resources.

  abstract generate(resource: Any, absolute: bool = False) → str

    Generate a URL for a resource.

    Parameters:

      - resource (`typing.Any`)

      - absolute (`bool`)

    Return type:

      `str`