Yancy :: Plugin :: Editor (source, CPAN)

CONTENTS

NAME

Yancy::Plugin::Editor - Yancy content editor, admin, and management application

VERSION

version 1.081

SYNOPSIS

use Mojolicious::Lite;
# The default editor at /yancy
plugin Yancy => {
    backend => 'sqlite://myapp.db',
    read_schema => 1,
    editor => {
        require_user => { can_edit => 1 },
    },
};

# Enable another editor for blog users
app->plugin->yancy( Editor => {
    moniker => 'blog_editor',
    backend => app->yancy->backend,
    schema => { blog_posts => app->yancy->schema( 'blog_posts' ) },
    route => app->routes->any( '/blog/editor' ),
    require_user => { can_blog => 1 },
} );

DESCRIPTION

This plugin contains the Yancy editor application which allows editing the data in a Yancy::Backend.

CONFIGURATION

This plugin has the following configuration options.

backend

The backend to use for this editor. Defaults to the default backend configured in the main Yancy plugin.

schema

The schema to use to build the editor application. This may not necessarily be the full and exact schema supported by the backend: You can remove certain fields from this editor instance to protect them, for example.

If not given, will use "read_schema" in Yancy::Backend to read the schema from the backend.

openapi

Instead of "schema", you can pass a full OpenAPI spec to this editor. This is deprecated; see Yancy::Guides::Upgrading.

default_controller

The default controller for API routes. Defaults to Yancy::Controller::Yancy. Building a custom controller can allow for customizing how the editor works and what content it displays to which users.

moniker

The name of this editor instance. Used to build helper names and route names. Defaults to editor. Other plugins may rely on there being a default editor named editor. Additional instances should have different monikers.

route

A base route to add the editor to. This allows you to customize the URL and add authentication or authorization. Defaults to allowing access to the Yancy web application under /yancy, and the REST API under /yancy/api.

This can be a string or a Mojolicious::Routes::Route object.

return_to

The URL to use for the "Back to Application" link. Defaults to /.

title

The title of the page, shown in the title bar and the page header. Defaults to Yancy.

host

The host to use for the generated OpenAPI spec. Defaults to the current system's hostname (via Sys::Hostname).

info

An OpenAPI info object, as a Perl hashref. See the OpenAPI 2.0 spec for what keys are allowed in this hashref.

HELPERS

yancy.editor.include

$app->yancy->editor->include( $template_name );

Include a template in the editor, before the rest of the editor. Use this to add your own Vue.JS components to the editor.

yancy.editor.menu

$app->yancy->editor->menu( $category, $title, $config );

Add a menu item to the editor. The $category is the title of the category in the sidebar. $title is the title of the menu item. $config is a hash reference with the following keys:

component

The name of a Vue.JS component to display for this menu item. The component will take up the entire main area of the application, and will be kept active even after another menu item is selected.

Yancy plugins should use the category Plugins. Other categories are available for custom applications.

app->yancy->editor->include( 'plugin/editor/custom_element' );
app->yancy->editor->menu(
    'Plugins', 'Custom Item',
    {
        component => 'custom-element',
    },
);
__END__
@@ plugin/editor/custom_element.html.ep
<template id="custom-element-template">
    <div :id="'custom-element'">
        Hello, world!
    </div>
</template>
%= javascript begin
    Vue.component( 'custom-element', {
        template: '#custom-element-template',
    } );
% end
screenshot of yancy editor showing custom element

yancy.editor.route

Get the route where the editor will appear.

yancy.editor.openapi

my $openapi = $c->yancy->openapi;

Get the Mojolicious::Plugin::OpenAPI object containing the OpenAPI interface for this Yancy API.

TEMPLATES

To override these templates, add your own at the designated path inside your app's templates/ directory.

yancy/editor.html.ep

This is the main Yancy web application. You should not override this. Instead, use the "yancy.editor.include" helper to add new components. If there is something you can't do using the include helper, consider asking how on the Github issues board or filing a bug report or feature request.

SEE ALSO

Yancy::Guides::Schema, Mojolicious::Plugin::Yancy, Yancy

AUTHOR

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Doug Bell.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.