Created
April 7, 2017 11:30
-
-
Save niczero/d1f8ba667458cfde7350165f40a42c57 to your computer and use it in GitHub Desktop.
Variant templates driven by env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
app->mode('development') and app->defaults(variant => 'offline') | |
if ($ENV{MOJO_MODE} // '') eq 'offline'; | |
get '/' => sub { shift->render(template => 'index') }; | |
app->start; | |
__DATA__ | |
@@ index.html.ep | |
% layout 'default'; | |
% title 'Value Added'; | |
The value of 'variant' is: <%= stash('variant') // '(nothing)' %>. | |
@@ layouts/default.html.ep | |
<!DOCTYPE html> | |
<html> | |
<head><title><%= title %></title></head> | |
<body><%= content %></body> | |
</html> | |
@@ layouts/default.html+offline.ep | |
<!DOCTYPE html> | |
<html> | |
<head><title><%= '[offline] '. title %></title></head> | |
<body><%= content %></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes you're developing your always-connected app while holed-up in your always-offline mountain retreat. At other times you're on an underground train. Wherever, it can be handy to fall-back to serving cdn files (eg js) from a local cache.