Skip to content

Commit

Permalink
add docs to LinkPreview widget
Browse files Browse the repository at this point in the history
  • Loading branch information
chirizxc committed Dec 15, 2024
1 parent bd56910 commit 22dd47b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
5 changes: 1 addition & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
# import os
# import sys
# sys.path.insert(0, os.path.abspath("."))

import datetime

# -- Project information -----------------------------------------------------

project = "aiogram-dialog"
copyright = f"{datetime.date.today().year}, Tishka17"
copyright = "%Y, Tishka17"
author = "Tishka17"
master_doc = "index"

Expand Down
8 changes: 5 additions & 3 deletions docs/widgets/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Widgets and Rendering
Base information
********************

Currently there are 4 kinds of widgets: :ref:`texts <text_widgets>`, :ref:`keyboards <keyboard_widgets>`,
:ref:`input <input_widgets>`, :ref:`media<media_widgets>` and you can create your own :ref:`widgets<custom_widgets>`.
Currently there are 5 kinds of widgets: :ref:`texts <text_widgets>`, :ref:`keyboards <keyboard_widgets>`,
:ref:`input <input_widgets>`, :ref:`media<media_widgets>`, :ref:`link preview<link_preview>` and you can create your own :ref:`widgets<custom_widgets>`.

* **Texts** used to render text anywhere in dialog. It can be message text, button title and so on.
* **Keyboards** represent parts of ``InlineKeyboard``
* **Media** represent media attachment to message
* **Input** allows to process incoming messages from user. Is has no representation.
* **Link Preview** used to manage link previews in messages.

Widgets can display static (e.g. ``Const``) and dynamic (e.g. ``Format``) content. To use dynamic data you have to set it. See :ref:`passing data <passing_data>`.

Expand All @@ -37,5 +38,6 @@ Also there are 2 general types:
keyboard/index
input/index
media/index
link_preview/index
hiding/index
custom_widgets/index
custom_widgets/index
27 changes: 27 additions & 0 deletions docs/widgets/link_preview/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from aiogram.filters.state import State, StatesGroup

from aiogram_dialog import Window
from aiogram_dialog.widgets.link_preview import LinkPreview
from aiogram_dialog.widgets.text import Const


class SG(StatesGroup):
MAIN = State()
SECOND = State()


window = Window(
Const("https://nplus1.ru/news/2024/05/23/voyager-1-science-data"),
LinkPreview(is_disabled=True),
state=SG.MAIN,
)

second_window = Window(
Const("some text"),
LinkPreview(
url=Const("https://nplus1.ru/news/2024/05/23/voyager-1-science-data"),
prefer_small_media=True,
show_above_text=True,
),
state=SG.MAIN,
)
23 changes: 23 additions & 0 deletions docs/widgets/link_preview/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. _link_preview:

LinkPreview
*************

The **LinkPreview** widget is used to manage link previews in messages.

Parameters:

* ``url``: A ``TextWidget`` with URL to be used in the link preview. If not provided, the first URL found in the message will be used.
* ``is_disabled``: that controls whether the link preview is displayed. If ``True``, the preview will be disabled.
* ``prefer_small_media``: that controls if the media in the link preview should be displayed in a smaller size. Ignored if media size change is not supported.
* ``prefer_large_media``: that controls if the media in the link preview should be enlarged. Ignored if media size change is not supported.
* ``show_above_text``: that specifies whether the link preview should be displayed above the message text. If ``True``, link preview be displayed above the message text.


Code example:

.. literalinclude:: ./example.py

.. autoclass:: aiogram_dialog.widgets.link_preview.LinkPreview
:special-members: __init__
:members: render_link_preview, _render_link_preview

0 comments on commit 22dd47b

Please sign in to comment.