NAME

Mojolicious::Plugin::CSSLoader - move css loading to the end of the document

VERSION

version 0.07

SYNOPSIS

In your startup:

  sub startup {
      my $self = shift;

      # do some Mojolicious stuff
      $self->plugin( 'CSSLoader' );

      # more Mojolicious stuff
  }

In your template:

<% css_load('css_file.css') %>

HELPERS

This plugin adds a helper method to your web application:

css_load

This method requires at least one parameter: The path to the JavaScript file to load. An optional second parameter is the configuration. You can switch off the base for this CSS file this way:

# <link rel="stylesheet" href="$base/css_file.css"/>
<% css_load('css_file.css') %>

# <link rel="stylesheet" href="http://domain/css_file.css"/>
<% css_load('http://domain/css_file.css', {no_base => 1});

# load css file only in Internet Explorer
# <!-- [if IE]> <link rel="stylesheet" href="http://domain/css_file.css"/> <![endif] -->
<% css_load('css_file.css', {ie => 1});

# load css file except in Internet Explorer
# <!-- [if !IE]><!--> <link rel="stylesheet" href="http://domain/css_file.css"/> <!--<![endif] -->
<% css_load('css_file.css', {ie => 0});

# load css file in Internet Explorer greater version 7
# <!-- [if gt IE 7]> <link rel="stylesheet" href="http://domain/css_file.css"/> <![endif] -->
<% css_load('css_file.css', {ie => { '>' => 7 } });

# allowed ie settings: >, >=, <, <=, ==

HOOKS

When you use this module, a hook for after_render is installed. That hook inserts the <link> tag at the end of the <head> part or at the start of the document.

METHODS

register

Called when registering the plugin. On creation, the plugin accepts a hashref to configure the plugin.

# load plugin, alerts are dismissable by default
$self->plugin( 'CSSLoader' );

Configuration

$self->plugin( 'CSSLoader' => {
    base  => 'http://domain/css',  # base for all CSS files
    media => 'screen',             # media setting (default: none)
});

NOTES

This plugin uses the stash key __CSSLOADERFILES__, so you should avoid using this stash key for your own purposes.

AUTHOR

Renee Baecker <reneeb@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 by Renee Baecker.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)