Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/configurable plugin system (#286)
* add configurable plugin system * add missing new line * run tests * cleanup code * more readable plugin example * update doc/README for plugin
- Loading branch information
Showing
10 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/data/ | ||
.precomp | ||
.idea/ | ||
lib/Bailador/tmp* |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env perl6 | ||
|
||
use v6.c; | ||
use lib 'lib'; | ||
use lib 'examples/plugins/lib'; | ||
use Bailador; | ||
use Bailador::Plugin::Example; | ||
use Data::Dump; | ||
|
||
get '/' => sub { | ||
template 'index.tt', { | ||
title => 'Plugin Example', | ||
plugin_text => app.plugins.get('Example').sample | ||
}; | ||
} | ||
|
||
baile(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use v6.c; | ||
|
||
use Bailador::Plugins; | ||
|
||
class Bailador::Plugin::Example:ver<0.001000> is Bailador::Plugin { | ||
|
||
method sample{ | ||
|
||
# Because of the inheritage from Bailador::Plugin | ||
# %.config the config for this plugin Example is available. | ||
my $param = %.config{'param'}; | ||
return 'Hello I am a sample!'; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
plugins: | ||
Example: | ||
param: 1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
% my ($h) = @_; | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Bailador App</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.min.js"></script> | ||
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> | ||
</head> | ||
<body> | ||
<h1>Bailador App</h1> | ||
<div> | ||
Version <%= $h<version> %> | ||
</div> | ||
</body> | ||
</html> |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use v6.c; | ||
|
||
use Bailador::Configuration; | ||
|
||
role Bailador::Plugin { | ||
has %.config; | ||
} | ||
|
||
class Bailador::Plugins { | ||
has %!plugins = {}; | ||
|
||
method add(Str:D $name, Bailador::Plugin:D $plugin) { | ||
%!plugins.{$name} = $plugin; | ||
} | ||
|
||
method get(Str:D $name) { | ||
return %!plugins.{$name}; | ||
} | ||
|
||
method detect(Bailador::Configuration $config) { | ||
for $config.plugins.keys -> $name { | ||
my $plugin_conf= $config.plugins{$name}; | ||
my $package = 'Bailador::Plugin::' ~ $name; | ||
try { | ||
require ::($package); | ||
$.add($name, ::($package).new(config => $plugin_conf)); | ||
} | ||
} | ||
} | ||
} |