ignite-core 0.7.3

Core types for Ignite, the admin panel for Rocket.rs: resources, fields, forms and runtime resources.
Documentation
//! The rich text editor of [`FieldKind::Wysiwyg`](crate::FieldKind::Wysiwyg) fields.
//!
//! Ignite is MIT licensed and bundles no editor. The panel renders a wysiwyg field as a
//! `<textarea data-ignite-editor="wysiwyg">` holding the HTML, and, when the app has
//! registered an editor script, loads it on each form that has such a field. The script
//! turns each marked textarea into an editor and keeps the textarea's value up to date, so
//! the form submits the HTML as usual.
//!
//! ```ignore
//! registries.register_editor("/vendor/editor/init.js");
//! ```

use std::sync::PoisonError;

use crate::registries::Registries;

impl Registries {
    /// Sets the URL of the script that turns wysiwyg textareas into an editor. The panel loads
    /// it with `<script src="..." defer>` on each form with a wysiwyg field, from the next
    /// request on. Registering again replaces the URL. With no script registered, a wysiwyg
    /// field is a plain textarea.
    pub fn register_editor(&self, script_url: impl Into<String>) {
        *self
            .inner
            .editor
            .write()
            .unwrap_or_else(PoisonError::into_inner) = Some(script_url.into());
    }

    /// The URL of the registered editor script, if the app registered one.
    pub fn editor_script(&self) -> Option<String> {
        self.inner
            .editor
            .read()
            .unwrap_or_else(PoisonError::into_inner)
            .clone()
    }
}

/// Sets the editor script of the default app, as 0.7.1 did. See
/// [`Registries::register_editor`](crate::Registries::register_editor).
pub fn register_editor(script_url: impl Into<String>) {
    Registries::default_app().register_editor(script_url);
}

/// The editor script of the default app. See
/// [`Registries::editor_script`](crate::Registries::editor_script).
pub fn editor_script() -> Option<String> {
    Registries::default_app().editor_script()
}