You've already forked tribes-plugin-aether
forked from tribes/tribes-plugin-template
Rename to aether plugin and add /aether timeline integration
This commit is contained in:
101
lib/aether/plugin.ex
Normal file
101
lib/aether/plugin.ex
Normal file
@@ -0,0 +1,101 @@
|
||||
defmodule Aether.Plugin do
|
||||
@moduledoc """
|
||||
Tribes plugin entry point.
|
||||
|
||||
Implements the `Tribes.Plugin` behaviour. This module is referenced by
|
||||
`entry_module` in manifest.json and is called by the host's PluginManager
|
||||
during startup.
|
||||
"""
|
||||
|
||||
# Once Tribes.Plugin.Base is available, replace the manual implementation
|
||||
# with:
|
||||
#
|
||||
# use Tribes.Plugin.Base, otp_app: :aether
|
||||
#
|
||||
# and override only register/1.
|
||||
|
||||
# @behaviour Tribes.Plugin
|
||||
|
||||
def register(_context) do
|
||||
manifest = read_manifest()
|
||||
|
||||
%{
|
||||
name: manifest["name"],
|
||||
version: manifest["version"],
|
||||
provides: manifest["provides"] || [],
|
||||
requires: manifest["requires"] || [],
|
||||
enhances_with: manifest["enhances_with"] || [],
|
||||
nav_items: [
|
||||
%{
|
||||
label: "Aether",
|
||||
path: "/aether",
|
||||
icon: nil,
|
||||
requires: [],
|
||||
order: 50
|
||||
}
|
||||
],
|
||||
pages: [
|
||||
%{
|
||||
path: "/aether",
|
||||
live_view: AetherWeb.TimelineLive,
|
||||
layout: nil
|
||||
}
|
||||
],
|
||||
api_routes: [],
|
||||
plugs: [],
|
||||
children: [],
|
||||
global_js: get_in(manifest, ["assets", "global_js"]) || [],
|
||||
global_css: get_in(manifest, ["assets", "global_css"]) || [],
|
||||
migrations_path: migrations_path(manifest),
|
||||
hooks: %{}
|
||||
}
|
||||
end
|
||||
|
||||
defp read_manifest do
|
||||
manifest_path()
|
||||
|> File.read!()
|
||||
|> Jason.decode!()
|
||||
end
|
||||
|
||||
defp manifest_path do
|
||||
project_manifest = Path.join(__DIR__, "../../manifest.json") |> Path.expand()
|
||||
|
||||
candidates =
|
||||
case :code.priv_dir(:aether) do
|
||||
{:error, :bad_name} ->
|
||||
[project_manifest]
|
||||
|
||||
priv_dir ->
|
||||
priv_dir = to_string(priv_dir)
|
||||
|
||||
[
|
||||
Path.join(priv_dir, "../manifest.json") |> Path.expand(),
|
||||
project_manifest
|
||||
]
|
||||
end
|
||||
|
||||
first_existing_path(candidates) || project_manifest
|
||||
end
|
||||
|
||||
defp migrations_path(manifest) do
|
||||
if manifest["migrations"] do
|
||||
candidates =
|
||||
case :code.priv_dir(:aether) do
|
||||
{:error, :bad_name} ->
|
||||
[Path.join(__DIR__, "../../priv/repo/migrations") |> Path.expand()]
|
||||
|
||||
priv_dir ->
|
||||
[
|
||||
Path.join(to_string(priv_dir), "repo/migrations") |> Path.expand(),
|
||||
Path.join(__DIR__, "../../priv/repo/migrations") |> Path.expand()
|
||||
]
|
||||
end
|
||||
|
||||
first_existing_path(candidates)
|
||||
end
|
||||
end
|
||||
|
||||
defp first_existing_path(paths) do
|
||||
Enum.find(paths, &File.exists?/1)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user