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

NAME

Slovo::Plugin::DefaultHelpers - additional default helpers for Slovo

SYNOPSIS

    # local.xn--b1arjbl.xn--90ae
    # from http://local.слово.бг:3000
    # or http://local.xn--b1arjbl.xn--90ae:3000
    # in a template:
    <%= host_only %>
    #in a controller
    $c->host_only

    # local.слово.бг
    # from http://local.слово.бг:3000
    # or http://local.xn--b1arjbl.xn--90ae:3000
    # in a template:
    <%= ihost_only %>
    #in a controller
    $c->ihost_only

    <%= language%>

DESCRIPTION

Slovo::Plugin::DefaultHelpers extends Mojolicious::Plugin::DefaultHelpers. It provides additional default helpers for Slovo. They are always loaded and ready for use. DefaultHelpers and TagHelpers are loaded unconditionally after all other mandatory for Slovo plugins.

HELPERS

The following additional helpers are provided.

host_only

Returns the host_only from $c->req->headers->host.

    # local.xn--b1arjbl.xn--90ae
    # from http://local.слово.бг:3000 or http://local.xn--b1arjbl.xn--90ae:3000
    # in a template:
    <%= host_only %>
    #in a controller
    $c->host_only

ihost_only

Returns the IDN (Internationalized Domain Name) from the current request.

    # local.слово.бг
    # from http://local.слово.бг:3000 or http://local.xn--b1arjbl.xn--90ae:3000
    # in a template:
    <%= ihost_only %>
    #in a controller
    $c->ihost_only

is_user_authenticated

We replaced the implementation of this helper, provided otherwise by "is_user_authenticated" in Mojolicious::Plugin::Authentication. Now we check if the user is not guest instead of checking if we have a loaded user all over the place. This was needed because we wanted to always have a default user. See "before_dispatch" in Slovo for details. Now we have default user properties even if there is not a logged in user. This will be the guest user.

Once again: Now this helper returns true if the current user is not Guest, false otherwise.

    %# in a template
    Hello <%= $c->user->{first_name} %>,
    % if($c->is_user_authenticated) {
    You can go and <%= link_to manage => url_for('under_management')%> some pages.
    % else {
    You may want to <%=link_to 'sign in' => url_for('sign_in') %>.
    % }

language

Wrapper for $c->stash('lang'), which is set in $app->defaults in slovo.conf. The requested language is also checked if it exists in $c->openapi_spec('/parameters/language/enum'). The first element from this list is returned if the requested language is not found in it. Using $lang, found in the stash in templates is strongly discouraged.

    <%= language eq $lang %> <!-- renders 1 -->
    $c->language

languages

Returns $c->openapi_spec('/parameters/language/enum').

METHODS

The usual method is implemented.

register

Calls the parent's register if needed and registers additional helpers in Slovo application.

SEE ALSO

Mojolicious::Plugin::DefaultHelpers Slovo::Plugin::TagHelpers