package Mojolicious::Plugin::Notifications::JSON;
use Mojo::Base 'Mojolicious::Plugin::Notifications::Engine';
# TODO:
# Probably introduce a notify_json function
has key => 'notifications';
# No
my ($self, $c, $notify_array, $rule, $json, %param) = @_;
my $key = $param{key} // $self->key;
return $json unless @$notify_array;
if (!$json || ref $json) {
my @msgs;
foreach (@$noti
-1]]);
};
};
if (!$json) {
return { $key => \@msgs }
}
# Obect is an array
elsif (index(ref $json, 'ARRAY') >= 0) {
push(@$json, { $key => \@msgs });
}
r 'import';
use Mojo::ByteStream 'b';
use Mojo::Util qw/xml_escape quote/;
use Mojo::JSON qw/decode_json encode_json/;
use Scalar::Util qw/blessed/;
use File::Spec;
use File::Basename;
our @EXPORT_OK
tify_html/;
use Mojo::ByteStream 'b';
use Mojo::Util qw/xml_escape quote/;
use Mojo::JSON qw/encode_json decode_json/;
use File::Spec;
use File::Basename;
has [qw/base_class base_timeout/];
state $p
s
foreach (@$notify_array) {
$notify{$_->[0]} = 1;
$log .= '.' . $_->[0] . '(' . encode_json($_->[-1]);
if (scalar @{$_} == 3) {
my %param = %{$_->[1]};
# Remove potential l
d
$param{timeout} = 0;
# Encode parameters if left
$log .= ', ' . encode_json(\%param) if keys %param;
# Define callback
$log .= ', function(){var r=new XMLHt
al engines
plugin Notifications => {
Humane => {
base_class => 'libnotify'
},
JSON => 1
};
# Add notification messages in controllers
$c->notify(warn => 'Something went wron
s 'humane';
# ... or in any other responses
my $json = { text => 'That\'s my response' };
$c->render(json => $c->notifications(json => $json));
=head1 DESCRIPTION
L<Mojolicious::Plugin::Noti
tions 'humane' => [qw/warn error success/];
%= notifications 'html';
$c->render(json => $c->notifications(json => {
text => 'My message'
}));
Serve notifications to your user based on an e