Skip to content

Extensions #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
inputs: [
"*.{heex,ex,exs}",
"{core,extensions,config,lib,test}/**/*.{heex,ex,exs}",
"priv/*/seeds.exs"
]
]
8 changes: 7 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Config

config :phoenix_extensions,
ecto_repos: [PhoenixExtensions.Repo],
generators: [timestamp_type: :utc_datetime]
generators: [timestamp_type: :utc_datetime],
extensions: [PhoenixExtensions.Extensions.TelegramBot]

# Configures the endpoint
config :phoenix_extensions, PhoenixExtensionsWeb.Endpoint,
Expand Down Expand Up @@ -64,3 +65,8 @@ config :phoenix, :json_library, Jason
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"

# Import Telegram Bot Extension Config
import_config ["extensions", "telegram_bot", "config", "#{config_env()}.exs"]
|> Path.join()
|> Path.expand()
4 changes: 4 additions & 0 deletions core/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
23 changes: 23 additions & 0 deletions core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
core-*.tar

# Temporary files, for example, from tests.
/tmp/
18 changes: 18 additions & 0 deletions core/lib/core.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Core do
@moduledoc """
Documentation for `Core`.
"""

@doc """
Hello world.

## Examples

iex> Core.hello()
:world

"""
def hello do
:world
end
end
28 changes: 28 additions & 0 deletions core/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Core.MixProject do
use Mix.Project

def project do
[
app: :phoenix_extensions_core,
version: "0.1.0",
elixir: "~> 1.18",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
8 changes: 8 additions & 0 deletions core/test/core_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule CoreTest do
use ExUnit.Case
doctest Core

test "greets the world" do
assert Core.hello() == :world
end
end
1 change: 1 addition & 0 deletions core/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()
4 changes: 4 additions & 0 deletions extensions/telegram_bot/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
23 changes: 23 additions & 0 deletions extensions/telegram_bot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
extension_telegram_bot-*.tar

# Temporary files, for example, from tests.
/tmp/
21 changes: 21 additions & 0 deletions extensions/telegram_bot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ExtensionTelegramBot

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `extension_telegram_bot` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:extension_telegram_bot, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/extension_telegram_bot>.

Empty file.
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions extensions/telegram_bot/lib/extension.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule PhoenixExtensions.Extensions.TelegramBot do
@moduledoc false

require Logger

def init() do
Logger.info("Telegram Bot Extension Initialized")
:ok
end
end
Empty file.
Empty file.
30 changes: 30 additions & 0 deletions extensions/telegram_bot/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule PhoenixExtensions.Extensions.TelegramBot.MixProject do
use Mix.Project

def project do
[
app: :extension_telegram_bot,
version: "0.1.0",
elixir: "~> 1.18",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:phoenix_extensions_core, path: Path.expand(Path.join(["..", "..", "core"]))},
{:phoenix, "~> 1.7.18"}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
8 changes: 8 additions & 0 deletions extensions/telegram_bot/test/telegram_bot_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule PhoenixExtensions.Extensions.TelegramBotTest do
use ExUnit.Case
doctest ExtensionTelegramBot

test "greets the world" do
assert ExtensionTelegramBot.hello() == :world
end
end
1 change: 1 addition & 0 deletions extensions/telegram_bot/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()
11 changes: 8 additions & 3 deletions lib/phoenix_extensions/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ defmodule PhoenixExtensions.Application do
PhoenixExtensionsWeb.Telemetry,
PhoenixExtensions.Repo,
{Ecto.Migrator,
repos: Application.fetch_env!(:phoenix_extensions, :ecto_repos),
skip: skip_migrations?()},
{DNSCluster, query: Application.get_env(:phoenix_extensions, :dns_cluster_query) || :ignore},
repos: Application.fetch_env!(:phoenix_extensions, :ecto_repos), skip: skip_migrations?()},
{DNSCluster,
query: Application.get_env(:phoenix_extensions, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: PhoenixExtensions.PubSub},
# Start the Finch HTTP client for sending emails
{Finch, name: PhoenixExtensions.Finch},
Expand All @@ -23,6 +23,11 @@ defmodule PhoenixExtensions.Application do
PhoenixExtensionsWeb.Endpoint
]

# Initialize extensions
Enum.each(Application.get_env(:phoenix_extensions, :extensions, []), fn extension ->
extension.init()
end)

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: PhoenixExtensions.Supervisor]
Expand Down
9 changes: 8 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ defmodule PhoenixExtensions.MixProject do
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

# Specifies your project extensions.
defp extensions do
[
{:extension_telegram_bot, path: Path.join(["extensions", "telegram_bot"])}
]
end

# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
Expand Down Expand Up @@ -58,7 +65,7 @@ defmodule PhoenixExtensions.MixProject do
{:jason, "~> 1.2"},
{:dns_cluster, "~> 0.1.1"},
{:bandit, "~> 1.5"}
]
] ++ extensions()
end

# Aliases are shortcuts or tasks specific to the current project.
Expand Down
3 changes: 2 additions & 1 deletion test/phoenix_extensions_web/controllers/error_html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule PhoenixExtensionsWeb.ErrorHTMLTest do
end

test "renders 500.html" do
assert render_to_string(PhoenixExtensionsWeb.ErrorHTML, "500", "html", []) == "Internal Server Error"
assert render_to_string(PhoenixExtensionsWeb.ErrorHTML, "500", "html", []) ==
"Internal Server Error"
end
end
4 changes: 3 additions & 1 deletion test/phoenix_extensions_web/controllers/error_json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ defmodule PhoenixExtensionsWeb.ErrorJSONTest do
use PhoenixExtensionsWeb.ConnCase, async: true

test "renders 404" do
assert PhoenixExtensionsWeb.ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not Found"}}
assert PhoenixExtensionsWeb.ErrorJSON.render("404.json", %{}) == %{
errors: %{detail: "Not Found"}
}
end

test "renders 500" do
Expand Down