Squid is a framework that helps you divide your application into multiple
small contexts and/or applications called tentacles
.
Each tentacle
defines its own logic (router, live view ...).
This framework is in development and isn't fully ready for production yet.
def deps do
[
{:squid,
git: "https://github.com/drakkardigital/squid", tag: "0.3.0"},
]
end
# config/config.exs
config :squid, tentacles: [:tentacle_a, :tentacle_b]
# apps/tentacle_a/config/config.exs
config :tentacle_a, :squid,
router: Tentacle1Web.Router
# apps/tentacle_b/config/config.exs
config :tentacle_b, :squid,
router: Tentacle2Web.Router
Learn more about
SquidWeb.Router
.
Then create the dynamic router with the following code.
defmodule YourHeadApp do
use Application
def start(_type, args) do
# The next line is REALLY important
SquidWeb.create_dynamic_router()
children = []
Supervisor.start_link(children, strategy: :one_for_one)
end
end
Learn more about squid routing system on the
SquidWeb.Router
module.
One of the major feature of Squid is to construct partials using your tentacles configurations. This is really usefull for building a menu or any composed view.
# in apps/tentacle_a/config/config.exs
config :tentacle_a, :squid,
partials: %{
greetings_builder: {TentacleA.Greetings, priority: 1}
}
# in apps/tentacle_a/lib/tentacle_a_web/greetings.ex
defmodule TentacleA.Greetings do
@behaviour SquidWeb.Partial
def render(assigns) do
~H"""
<div>Hello <%= @user_name %> from tentacle A</div>
"""
end
end
# in apps/tentacle_b/config/config.exs
config :tentacle_b, :squid,
partial: %{
greetings_builder: {TentacleB.Greetings, priority: 2}
}
# in apps/tentacle_b/lib/tentacle_b_web/greetings.ex
defmodule TentacleB.Greetings do
@behaviour SquidWeb.Partial
def render(assigns), do:
~H"""
<div>Hello <%= @user_name %> from tentacle B</div>
"""
end
end
You could then generate this partial view using the following code
<SquidWeb.Partial.render partial={:greetings_builder} user_name="Squid's King" />
<div>Hello Squid's King from tentacle B</div>
<div>Hello Squid's King from tentacle A</div>
Learn more about squid partials system on the
SquidWeb.Partial
module.