Prompt Editor

Template editing with {{variable}} highlighting.

python 7 params

Preview

{{topic}} = djust LiveView{{audience}} = a Django developer
Summarise djust LiveView for a Django developer in three bullet points.
Arguments
prompt_editor(template='Summarise {{topic}} for {{audience}} in three bullet points.', variables={'topic': 'djust LiveView', 'audience': 'a Django developer'})

This composed editor receives its state from the host view, so it has no standalone preview.

Usage

views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import PromptEditor


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = PromptEditor(template='Summarise {{topic}} for {{audience}} in three bullet points.', variables={'topic': 'djust LiveView', 'audience': 'a Django developer'})

    @event_handler()
    def save_prompt(self, value=None, **kwargs):
        pass  # your app acts on 'save_prompt'; no component state moves
my_template.html
django
{{ component }}

Events this component sends to the view: save_prompt.

Parameters

NameTypeDefaultDescription
templatestr''The template string with {{variable}} placeholders.
variablesDict[str, str] | NoneNoneDict of variable name -> value for preview.
eventstr — renames the event; identity is `name`'save_prompt'Event name for save action.
placeholderstr'Enter your prompt template...'Placeholder text for the editor.
rowsint6Number of rows for the textarea.
custom_classstr''Additional CSS classes.
**kwargs— passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state——
Source & styles
FilePathNotes
moduledjust.components.components.prompt_editorSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 7 of this component's classes at line 2356, 2357, 2358, 2359, 2360, 2361, 2362. Override those rules, or the custom properties they read, in a stylesheet loaded after it.