Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added load path.

  • Loading branch information...
commit 52062dd4dedb7c2e41626aa847f2a620b92961bb 1 parent 02aeca1
@Licenser authored
Showing with 21 additions and 6 deletions.
  1. +2 −2 README.md
  2. +18 −3 src/eplugin.erl
  3. +1 −1  src/eplugin_srv.erl
View
4 README.md
@@ -48,7 +48,7 @@ eplugin:callbacks(my_fancy_callback).
config/1
--------
-Fetches the custom plugin Config. This is holding plugin internal information as well as some used by eplugin.
+Fetches the custom plugin Config. This is holding plugin internal information as well as some used by eplugin.project-fifo.net
```erlang
eplugin:config(my_fancy_callback).
@@ -108,7 +108,7 @@ OptionsPlist has the following reserved options:
* disabled - this plugin will not load.
* dependencies - a list of dependencies.¯
* provides - a list of dependencies the plugin provides.
-
+* add path - relative pathes to be added to the loadpath.
Callbacks
=========
View
21 src/eplugin.erl
@@ -27,6 +27,7 @@
register/4, register/5,
fold/2,
config/1,
+ provide/1,
plugins/0,
enable/1,
provide/1,
@@ -127,6 +128,7 @@
-type plugin_config() :: {dependencies, [atom()]} |
{provides, [atom()]} |
+ {add_paths, [file:name_all()]}|
disabled |
atom() |
{Key::atom(), Value::any()}.
@@ -350,7 +352,7 @@ config(Plugin) ->
%% @end
%%--------------------------------------------------------------------
--spec disable(Plugin::atom()) -> {error, not_found}|ok.
+-spec disable(Plugin::atom()) -> {error, not_found} | ok.
disable(Plugin) ->
case is_enabled(Plugin) of
@@ -363,6 +365,13 @@ disable(Plugin) ->
Callback = ets:match(?TABLE, {'eplugin:disable', Plugin, '$1', '$2'}),
ets:match_delete(?TABLE, {'_', Plugin, '_', '_'}),
{ok, Config} = config(Plugin),
+ Base = proplists:get_value(path, Config),
+ case proplists:get_value(add_paths, Config, []) of
+ [] ->
+ ok;
+ Paths ->
+ [code:del_path([Base, "/", P]) || P <- Paths]
+ end,
[M:F(Config) || [M, F] <- Callback],
eplugin:call('eplugin:disable_plugin', Plugin),
ok;
@@ -394,8 +403,14 @@ enable(Plugin) ->
case ets:lookup(?CONFTABLE, Plugin) of
[] ->
undefined;
- [{_, _, Modules}] ->
- {ok, Config} = config(Plugin),
+ [{_, Config, Modules}] ->
+ Base = proplists:get_value(path, Config),
+ case proplists:get_value(add_paths, Config, []) of
+ [] ->
+ ok;
+ Paths ->
+ code:add_paths([[Base, "/", P] || P <- Paths])
+ end,
%% We look for all functions that are registered to 'eplugin:enable'
%% so we can call them before the plugin is enabled.
lists:foreach(fun({M, Callbacks}) ->
View
2  src/eplugin_srv.erl
@@ -167,7 +167,7 @@ compile_plugin(Path, Name, Modules, Config) ->
error ->
{error, Name};
ok ->
- ets:insert(?CONFTABLE, {Name, Config, Modules}),
+ ets:insert(?CONFTABLE, {Name, [{path, Path} | Config], Modules}),
case proplists:get_value(disabled, Config) of
true ->
lager:warning("[eplugin::~p] Disabled.", [Name]);
Please sign in to comment.
Something went wrong with that request. Please try again.