The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojolicious::Plugin::Humane - Mojolicious integration for humane.js

SYNOPSIS

  # Mojolicious
  $app->plugin('Humane');
  # then elsewhere
  $c->humane_flash('Not authorized');

  # Mojolicious::Lite
  plugin 'Humane';
  get '/' => sub {
    my $c = shift;
    $c->humane_stash('Welcome back!');
  ...

  # Without 'auto' feature
  plugin 'Humane', auto => 0;
  ...
  __DATA__
  ...
  %= humane_include

DESCRIPTION

Mojolicious::Plugin::Humane is a Mojolicious plugin allowing easy use of humane.js, a browser notification handler (http://wavded.github.com/humane-js/).

By default the template needed to render the messages is injected only if needed. For infrequent use, this is less costly overall and less to think about. If messages are to be used frequently or perhaps humane.js is to also be used without reloading the page (via websockets perhaps) then turn the auto feature off and add the template to your layout manually.

Internally this plugin uses the (non-localized) stash keys humane.stash and humane.flash. Other stash keys starting with humane. are reserved for future use should be avoided.

ATTRIBUTES

humane_version

Version of humane.js (to be) loaded. Defaults to the highest bundled version. Currently version 3.2.0 is bundled.

In future, non-breaking releases will be silently upgraded, while breaking versions will be kept and left at the highest version that had been bundled.

static_path

The path to the folder containing the bundled version of humane to be used. This path is added to the static rendering path. The default is $plugin->path('humane-' . $self->humane_version);.

template

The name of the template to be used. This allows the user to supply their own template name if desired.

theme

Selects the humane.js theme. This should be chosen from the available themes (see "all_themes"). The default is libnotify.

METHODS

Mojolicious::Plugin::Humane inherits all methods from Mojolicious::Plugin and implements the following new ones.

all_themes

  $plugin->all_themes();

Get a list of all the available themes for humane.js.

path

  $plugin->path($directory);

Find the path to a directory relative to the shared data directory. This isn't likely to be needed.

register

  $plugin->register($app);

Register plugin in Mojolicious application. Optionally key-value pairs or a hashreference of the same may be passed. Those options are:

auto

Set to a true value, the template necessary for humane.js will be automatically added to the <head> tag of the rendered document if needed. Note that this will be skipped if no <head> tag is found or if no messages are waiting to be added. Default is true.

HELPERS

This plugin provides several helpers which are available as methods to the application and controllers and as functions to the templates (and lite apps).

humane

  $app->humane->theme($newtheme);

Holds the instance of the plugin.

humane_stash/humane_flash

  $app->humane_stash('Welcome back');
  $app->humane_flash('Not authorized');

Take a message or list of messages and adds them to the stack of messages to be rendered during the current or next rendering respectively. Returns an array reference of all the buffered messages in that stack. May be called without argument to get the stack while not adding messages.

Note that each stack is rendered first-in first-out, however all flashed messages are shown before stashed messages.

humane_include

Behaves like include inserting the template needed to render the messages. You need to use this when setting auto => 0.

humane_messages

Returns a list of all the messages to be rendered in this rendering, in order; flashed messages first, then stashed.

SEE ALSO

Mojolicious, http://wavded.github.com/humane-js/

SOURCE REPOSITORY

http://github.com/jberger/Mojolicious-Plugin-Humane

AUTHOR

Joel Berger, <joel.a.berger@gmail.com>

COPYRIGHT AND LICENSE

Mojolicious::Plugin::Humane is

Copyright (C) 2013 by Joel Berger

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

humane.js bears the license

(The MIT License)

Copyright (c) 2011 Marc Harter <wavded@gmail.com>

See http://wavded.github.com/humane-js/ for terms of use.