Created
December 1, 2019 07:38
-
-
Save s1037989/bd87efa59827f5565c0bf838dccc820d to your computer and use it in GitHub Desktop.
Atom Snippets for Mojolicious
This file contains hidden or 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
# Your snippets | |
# | |
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to | |
# expand the prefix into a larger code block with templated values. | |
# | |
# You can create a new snippet in this file by typing "snip" and then hitting | |
# tab. | |
# | |
# An example CoffeeScript snippet to expand log to console.log: | |
# | |
# '.source.coffee': | |
# 'Console log': | |
# 'prefix': 'log' | |
# 'body': 'console.log $1' | |
# | |
# Each scope (e.g. '.source.coffee' above) can only be declared once. | |
# | |
# This file uses CoffeeScript Object Notation (CSON). | |
# If you are unfamiliar with CSON, you can read more about it in the | |
# Atom Flight Manual: | |
# http://flight-manual.atom.io/using-atom/sections/basic-customization/#_cson | |
'.source.perl.mojolicious': | |
'MojoBase': | |
'prefix': 'base' | |
'body': """ | |
package ${1:ClassName}; | |
use Mojo::Base '${2:ParentClassName}'; | |
has '${3:attribute}' => sub { ${4:shift} }; | |
sub new { | |
my $self = shift->SUPER::new(@_); | |
return $self; | |
} | |
sub ${5:subname} { | |
my $self = shift; | |
} | |
1; | |
""" | |
'Role': | |
'prefix': 'role' | |
'body': """ | |
package ${1:ClassName}::Role::${2:RoleName}; | |
use Mojo::Base -role; | |
has '${3:attribute}' => sub { ${4:shift} }; | |
sub ${5:rolename} { | |
my $self = shift; | |
return $self; | |
} | |
1; | |
""" | |
'Plugin': | |
'prefix': 'plugin' | |
'body': """ | |
package Mojolicious::Plugin::${1:PluginName}; | |
use Mojo::Base 'Mojolicious::Plugin'; | |
has '${2:attribute}' => sub { ${3:shift} }; | |
sub register { | |
my ($self, $app, $config) = @_; | |
} | |
1; | |
""" | |
'Helper': | |
'prefix': 'helper' | |
'body': """ | |
$self->helper(${1:helper_name} => sub { | |
my ($c, @args) = @_; | |
}); | |
""" | |
'HelperLite': | |
'prefix': 'lhelper' | |
'body': """ | |
helper ${1:helper_name} => sub { | |
my $c = shift; | |
}; | |
""" | |
'Hook': | |
'prefix': 'hook' | |
'body': """ | |
$self->hook(${1:hook_name} => sub { | |
my $c = shift; | |
}); | |
""" | |
'Hook Before Command': | |
'prefix': 'hook_before_command' | |
'body': """ | |
$self->hook(before_command => sub { | |
my $c = shift; | |
... | |
}); | |
""" | |
'Hook Before Server Start': | |
'prefix': 'hook_before_server_start' | |
'body': """ | |
$self->hook(before_server_start => sub { | |
my ($server, $app) = @_; | |
... | |
}); | |
""" | |
'Hook After build_tx': | |
'prefix': 'hook_after_build_tx' | |
'body': """ | |
$self->hook(after_build_tx => sub { | |
my ($tx, $app) = @_; | |
... | |
}); | |
""" | |
'Hook Around Dispatch': | |
'prefix': 'hook_around_dispatch' | |
'body': """ | |
$self->hook(around_dispatch => sub { | |
my ($next, $c) = @_; | |
... | |
$next->(); | |
... | |
}); | |
""" | |
'Hook Before Dispatch': | |
'prefix': 'hook_before_dispatch' | |
'body': """ | |
$self->hook(before_dispatch => sub { | |
my $c = shift; | |
... | |
}); | |
""" | |
'Hook After Static': | |
'prefix': 'hook_after_static' | |
'body': """ | |
$self->hook(after_static => sub { | |
my $c = shift; | |
... | |
}); | |
""" | |
'Hook Before Routes': | |
'prefix': 'hook_before_routes' | |
'body': """ | |
$self->hook(before_routes => sub { | |
my $c = shift; | |
... | |
}); | |
""" | |
'Hook Around Action': | |
'prefix': 'hook_around_action' | |
'body': """ | |
$self->hook(around_action => sub { | |
my ($next, $c, $action, $last) = @_; | |
... | |
return $next->(); | |
}); | |
""" | |
'Hook Before Render': | |
'prefix': 'hook_before_render' | |
'body': """ | |
$self->hook(before_render => sub { | |
my ($c, $args) = @_; | |
... | |
}); | |
""" | |
'Hook After Render': | |
'prefix': 'hook_after_render' | |
'body': """ | |
$self->hook(after_render => sub { | |
my ($c, $outout, $format) = @_; | |
... | |
# $$output = lc($$outout); | |
}); | |
""" | |
'Hook After Dispatch': | |
'prefix': 'hook_after_dispatch' | |
'body': """ | |
$self->hook(after_dispatch => sub { | |
my $c = shift; | |
... | |
}); | |
""" | |
'HookLite': | |
'prefix': 'lhook' | |
'body': """ | |
hook ${1:hook_name} => sub { | |
my $c = shift; | |
}; | |
""" | |
'HookLite Before Command': | |
'prefix': 'lhook_before_command' | |
'body': """ | |
hook before_command => sub { | |
my $c = shift; | |
... | |
}; | |
""" | |
'HookLite Before Server Start': | |
'prefix': 'lhook_before_server_start' | |
'body': """ | |
hook before_server_start => sub { | |
my ($server, $app) = @_; | |
... | |
}; | |
""" | |
'HookLite After build_tx': | |
'prefix': 'lhook_after_build_tx' | |
'body': """ | |
hook after_build_tx => sub { | |
my ($tx, $app) = @_; | |
... | |
}; | |
""" | |
'HookLite Around Dispatch': | |
'prefix': 'lhook_around_dispatch' | |
'body': """ | |
hook around_dispatch => sub { | |
my ($next, $c) = @_; | |
... | |
$next->(); | |
... | |
}; | |
""" | |
'HookLite Before Dispatch': | |
'prefix': 'lhook_before_dispatch' | |
'body': """ | |
hook before_dispatch => sub { | |
my $c = shift; | |
... | |
}; | |
""" | |
'HookLite After Static': | |
'prefix': 'lhook_after_static' | |
'body': """ | |
hook after_static => sub { | |
my $c = shift; | |
... | |
}; | |
""" | |
'HookLite Before Routes': | |
'prefix': 'lhook_before_routes' | |
'body': """ | |
hook before_routes => sub { | |
my $c = shift; | |
... | |
}; | |
""" | |
'HookLite Around Action': | |
'prefix': 'lhook_around_action' | |
'body': """ | |
hook around_action => sub { | |
my ($next, $c, $action, $last) = @_; | |
... | |
return $next->(); | |
}; | |
""" | |
'HookLite Before Render': | |
'prefix': 'lhook_before_render' | |
'body': """ | |
hook before_render => sub { | |
my ($c, $args) = @_; | |
... | |
}; | |
""" | |
'HookLite After Render': | |
'prefix': 'lhook_after_render' | |
'body': """ | |
hook after_render => sub { | |
my ($c, $outout, $format) = @_; | |
... | |
# $$output = lc($$outout); | |
}; | |
""" | |
'HookLite After Dispatch': | |
'prefix': 'lhook_after_dispatch' | |
'body': """ | |
hook after_dispatch => sub { | |
my $c = shift; | |
... | |
}; | |
""" | |
'Route Condition': | |
'prefix': 'add_condition' | |
'body': """ | |
$r->add_condition(${1:condition_name} => sub { | |
my ($route, $c, $captures, $num) = @_; | |
return 1 || 0; | |
}); | |
""" | |
'Route Shortcut': | |
'prefix': 'add_shortcut' | |
'body': """ | |
# Simple "${1:shortcut}" shortcut | |
# $r->${1:shortcut}; | |
$r->add_shortcut(${1:shortcut} => sub { | |
my ($r, $name) = @_; | |
... | |
}); | |
""" | |
'Route Shortcut Resource': | |
'prefix': 'add_shortcut_resource' | |
'body': """ | |
# Simple "resource" shortcut | |
# GET /users -> {controller => 'users', action => 'index'} | |
# GET /users/create -> {controller => 'users', action => 'create'} | |
# POST /users -> {controller => 'users', action => 'store'} | |
# GET /users/23 -> {controller => 'users', action => 'show', id => 23} | |
# GET /users/23/edit -> {controller => 'users', action => 'edit', id => 23} | |
# PUT /users/23 -> {controller => 'users', action => 'update', id => 23} | |
# DELETE /users/23 -> {controller => 'users', action => 'remove', id => 23} | |
# $r->resource('users'); | |
$r->add_shortcut(resource => sub { | |
my ($r, $name) = @_; | |
# Prefix for resource | |
my $resource = $r->any("/$name")->to("$name#"); | |
# Render a list of resources | |
$resource->get('/')->to('#index')->name($name); | |
# Render a form to create a new resource (submitted to "store") | |
$resource->get('/create')->to('#create')->name("create_$name"); | |
# Store newly created resource (submitted by "create") | |
$resource->post->to('#store')->name("store_$name"); | |
# Render a specific resource | |
$resource->get('/:id')->to('#show')->name("show_$name"); | |
# Render a form to edit a resource (submitted to "update") | |
$resource->get('/:id/edit')->to('#edit')->name("edit_$name"); | |
# Store updated resource (submitted by "edit") | |
$resource->put('/:id')->to('#update')->name("update_$name"); | |
# Remove a resource | |
$resource->delete('/:id')->to('#remove')->name("remove_$name"); | |
return $resource; | |
}); | |
""" | |
'Validation Check': | |
'prefix': 'validation_check' | |
'body': """ | |
# Add validation check | |
$app->validator->add_check(${1:foo} => sub { | |
my ($v, $name, $value) = @_; | |
return $value ne '${1:foo}'; | |
}); | |
""" | |
'Validation Filter': | |
'prefix': 'validation_filter' | |
'body': """ | |
# Add validation filter | |
$app->validator->add_filter(${1:quotemeta} => sub { | |
my ($v, $name, $value) = @_; | |
return ${1:quotemeta} $value; | |
}); | |
""" | |
'Renderer Paths': | |
'prefix': 'renderer_paths' | |
'body': """ | |
# Add another "templates" directory | |
push @{$app->renderer->paths}, '${1:/path/to/templates}'; | |
""" | |
'Static Paths': | |
'prefix': 'static_paths' | |
'body': """ | |
# Add another "public" directory | |
push @{$app->static->paths}, '${1:/path/to/public}'; | |
""" | |
'Plugin Namespace': | |
'prefix': 'plugin_namespace' | |
'body': """ | |
# Add another namespace to load plugins from | |
push @{$app->plugins->namespace}, '${1:__PACKAGE__::Plugin}'; | |
""" | |
'Command Namespace': | |
'prefix': 'command_namespace' | |
'body': """ | |
# Add another namespace to load commands from | |
push @{$app->commands->namespace}, '${1:__PACKAGE__::Command}'; | |
""" | |
'Command': | |
'prefix': 'command' | |
'body': """ | |
package Mojolicious::Command::${1:command}; | |
use Mojo::Base 'Mojolicious::Command'; | |
use Mojo::Util 'getopt'; | |
has '${2:attribute}' => sub { ${3:shift} }; | |
has description => '${4:Description}'; | |
has usage => sub { shift->extract_usage }; | |
sub run { | |
my ($self, @args) = @_; | |
getopt \\@args | |
'h|help' => \\my $help; | |
} | |
1; | |
=encoding utf8 | |
=head1 NAME | |
Mojolicious::Command::${1:command} - ${1:command} command | |
=head1 SYNOPSIS | |
Usage: APPLICATION ${1:command} [OPTIONS] | |
./myapp.pl ${1:command} | |
Options: | |
-h, --help Show this summary of available options | |
=head1 DESCRIPTION | |
L<Mojolicious::Command::${1:command}> ${4:Description}. | |
See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are | |
available by default. | |
=head1 ATTRIBUTES | |
L<Mojolicious::Command::${1:command}> inherits all attributes from | |
L<Mojolicious::Command> and implements the following new ones. | |
=head2 description | |
my $description = $v->description; | |
$v = $v->description('Foo'); | |
Short description of this command, used for the command list. | |
=head2 usage | |
my $usage = $v->usage; | |
$v = $v->usage('Foo'); | |
Usage information for this command, used for the help screen. | |
=head1 METHODS | |
L<Mojolicious::Command::${1:command}> inherits all methods from | |
L<Mojolicious::Command> and implements the following new ones. | |
=head2 run | |
$v->run(@ARGV); | |
Run this command. | |
=head1 SEE ALSO | |
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | |
=cut | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment