NAME
Ado::Plugin::AdoHelpers - Default Ado helpers plugin
SYNOPSIS
# Ado
$self->plugin('AdoHelpers');
# Mojolicious::Lite
plugin 'AdoHelpers';
DESCRIPTION
Ado::Plugin::AdoHelpers is a collection of renderer helpers for Ado.
This is a core plugin, that means it is always enabled and its code a good example for learning to build new plugins, you're welcome to fork it.
See "PLUGINS" in Ado::Manual::Plugins for a list of plugins that are available by default.
HELPERS
Ado::Plugin::AdoHelpers implements the following helpers.
do_sql_file
Your plugin may need to add some new tables, add columns to already existing tables or insert some data. This method allows you to do that. See the source code of Ado::Plugin::Vest for example. The SQL file will be slurped, multiline comments will be removed. The content will be split into ';'
and each statement will be executed using "do" in DBI.
# in a plugin somewhere in register
$app->do_sql_file(catfile($self->config_dir, $sql_file));
$app->do_sql_file($conf->{vest_data_sql_file});
# on the command line
$ ado eval 'app->do_sql_file(shift)' some_file.sql
# elsewhere in an application
$app->do_sql_file($sql_file)
head_css, head_javascript
Minimalist asset management for the <head>
section. Appends and later renders assets (links to files and code-snippets) to $c->stash('head_css')
and app->stash('head_javascript')
. The new assets are only appended if they are not already present in the corresponding list of assets. The defaults are populated in etc/ado.conf
. See also: "defaults" in Mojolicious; Mojolicious::Plugin::AssetPack.
#in a template:
#append
<%
head_css([
'vendor/SemanticUI/components/popup.min.css'
'#myid { font-size:xx-small }'
]);
head_javascript([
'vendor/SemanticUI/components/popup.min.js'
'jQuery( function($){ $('#ado-img').popup() })'
]);
%>
<!-- or -->
# or
% head_javascript begin
jQuery( function($){ $('#ado-img').popup() });
% end;
# render in templates/partials/head.html.ep
%== head_css;
<link href="css/ado.css" rel='stylesheet' type='text/css' />
<link href='//fonts.googleapis.com/css?family=Ubuntu&subset=latin,cyrillic'
rel='stylesheet' type='text/css' />
%== head_javascript;
to_json
Suitable for preparing JavaScript objects from Perl references that will be used from stash and in templates.
my $chars = $c->to_json({name =>'Петър',id=>2});
$c->stash(user_as_js => $chars);
# in a javascript chunk of a template
var user = <%== $user_as_js %>;
var user_group_names = <%== to_json([user->ingroup]) %>;
user
Returns the current user. This is the user guest
for not authenticated users. This helper is a wrapper for "user" in Ado::Control.
$c->user(Ado::Model::Users->query("SELECT * from users WHERE login_name='guest'"));
#in a controller action:
my $current_user = $c->user;
#in a template:
<h1>Hello, <%=user->name%>!</h1>
METHODS
Ado::Plugin::AdoHelpers inherits all methods from Ado::Plugin and implements the following new ones.
register
$plugin->register(Ado->new);
Register helpers in Ado application.
SEE ALSO
Ado::Plugin, Mojolicious::Plugins, Mojolicious::Plugin,
AUTHOR
Красимир Беров (Krasimir Berov)
COPYRIGHT AND LICENSE
Copyright 2013-2015 Красимир Беров (Krasimir Berov).
This program is free software, you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License v3 (LGPL-3.0). You may copy, distribute and modify the software provided that modifications are open source. However, software that includes the license may release under a different license.
See http://opensource.org/licenses/lgpl-3.0.html for more information.