Skip to content

Commit

Permalink
config
Browse files Browse the repository at this point in the history
  • Loading branch information
IciaCarroBarallobre committed Jan 7, 2025
1 parent a24ab8d commit 829c288
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 343 deletions.
7 changes: 1 addition & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,4 @@ COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/exploring_bea

USER nobody

# If using an environment that doesn't automatically reap zombie processes, it is
# advised to add an init process such as tini via `apt-get install`
# above and adding an entrypoint. See https://github.com/krallin/tini for details
# ENTRYPOINT ["/tini", "--"]

CMD ["/app/bin/server"]
CMD ["/app/bin/server"]
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ config :exploring_beam_community, ExploringBeamCommunityWeb.Endpoint,
cache_static_manifest: "priv/static/cache_manifest.json"

# Do not print debug messages in production
config :logger, level: :info
config :logger, level: :error

# Runtime production configuration, including reading
# of environment variables, is done on config/runtime.exs.
16 changes: 13 additions & 3 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# fly.toml app configuration file generated for exploring-beam-community on 2024-08-19T13:09:26+02:00
# fly.toml app configuration file generated for exploring-beam-community on 2025-01-07T05:54:08+01:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
Expand All @@ -18,15 +18,25 @@ kill_signal = 'SIGTERM'
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
min_machines_running = 1
processes = ['app']

[http_service.concurrency]
type = 'connections'
hard_limit = 1000
soft_limit = 1000

[[services]]
protocol = ''
internal_port = 0
ports = []

[services.concurrency]
type = 'connections'
hard_limit = 300
soft_limit = 150

[[vm]]
memory = '1gb'
memory = '512mb'
cpu_kind = 'shared'
cpus = 1
2 changes: 0 additions & 2 deletions lib/exploring_beam_community_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ defmodule ExploringBeamCommunityWeb do
layouts: [html: ExploringBeamCommunityWeb.Layouts]

import Plug.Conn
import ExploringBeamCommunityWeb.Gettext

unquote(verified_routes())
end
Expand Down Expand Up @@ -85,7 +84,6 @@ defmodule ExploringBeamCommunityWeb do
import Phoenix.HTML
# Core UI components and translation
import ExploringBeamCommunityWeb.CoreComponents
import ExploringBeamCommunityWeb.Gettext

# Shortcut for generating JS commands
alias Phoenix.LiveView.JS
Expand Down
47 changes: 18 additions & 29 deletions lib/exploring_beam_community_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ defmodule ExploringBeamCommunityWeb.CoreComponents do
use Phoenix.Component

alias Phoenix.LiveView.JS
import ExploringBeamCommunityWeb.Gettext

@doc """
Renders a modal.
Expand Down Expand Up @@ -73,7 +72,7 @@ defmodule ExploringBeamCommunityWeb.CoreComponents do
phx-click={JS.exec("data-cancel", to: "##{@id}")}
type="button"
class="-m-3 flex-none p-3 opacity-20 hover:opacity-40"
aria-label={gettext("close")}
aria-label={"close"}
>
<.icon name="hero-x-mark-solid" class="h-5 w-5" />
</button>
Expand Down Expand Up @@ -125,7 +124,7 @@ defmodule ExploringBeamCommunityWeb.CoreComponents do
<%= @title %>
</p>
<p class="mt-2 text-sm leading-5"><%= msg %></p>
<button type="button" class="group absolute top-1 right-1 p-2" aria-label={gettext("close")}>
<button type="button" class="group absolute top-1 right-1 p-2" aria-label={"close"}>
<.icon name="hero-x-mark-solid" class="h-5 w-5 opacity-40 group-hover:opacity-70" />
</button>
</div>
Expand Down Expand Up @@ -476,7 +475,7 @@ defmodule ExploringBeamCommunityWeb.CoreComponents do
<thead class="text-sm text-left leading-6 text-zinc-500">
<tr>
<th :for={col <- @col} class="p-0 pr-6 pb-4 font-normal"><%= col[:label] %></th>
<th class="relative p-0 pb-4"><span class="sr-only"><%= gettext("Actions") %></span></th>
<th class="relative p-0 pb-4"><span class="sr-only"><%= "Actions" %></span></th>
</tr>
</thead>
<tbody
Expand Down Expand Up @@ -672,31 +671,21 @@ defmodule ExploringBeamCommunityWeb.CoreComponents do
|> JS.pop_focus()
end

@doc """
Translates an error message using gettext.
"""
def translate_error({msg, opts}) do
# When using gettext, we typically pass the strings we want
# to translate as a static argument:
#
# # Translate the number of files with plural rules
# dngettext("errors", "1 file", "%{count} files", count)
#
# However the error messages in our forms and APIs are generated
# dynamically, so we need to translate them by calling Gettext
# with our gettext backend as first argument. Translations are
# available in the errors.po file (as we use the "errors" domain).
if count = opts[:count] do
Gettext.dngettext(ExploringBeamCommunityWeb.Gettext, "errors", msg, msg, count, opts)
else
Gettext.dgettext(ExploringBeamCommunityWeb.Gettext, "errors", msg, opts)
@doc """
Translates an error message. This can be modified to return a custom error message.
"""
def translate_error({msg, opts}) do
# You can replace this with a custom translation logic,
# or directly return the message if no translation is needed
"#{msg} #{opts}"
end
end

@doc """
Translates the errors for a field from a keyword list of errors.
"""
def translate_errors(errors, field) when is_list(errors) do
for {^field, {msg, opts}} <- errors, do: translate_error({msg, opts})
end
@doc """
Translates errors for a specific field from a list of errors.
"""
def translate_errors(errors, field) when is_list(errors) do
errors
|> Enum.filter(fn {key, _} -> key == field end) # Filter out errors for the specific field
|> Enum.map(fn {_, {msg, opts}} -> translate_error({msg, opts}) end) # Translate each error
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
text="© 2024 BEAM Developer Community. All rights reserved."
navigation_pages={[
%{route: ~p"/", name: "Home"},
%{route: ~p"/results", name: "Results"},
%{route: ~p"/about-us", name: "About Us"},
%{route: "https://github.com/IciaCarroBarallobre/exploring_beam_community/issues", name: "Github Issues"}
]}
Expand Down
10 changes: 5 additions & 5 deletions lib/exploring_beam_community_web/components/navbar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ defmodule ExploringBeamCommunityWeb.Components.Navbar do
</div>
<div class="hidden md:flex md:items-center md:gap-4 font-semibold leading-6 text-main-900 dark:text-white">
<%= for %{route: route, name: name} <- @navigation_pages do %>
<a href={route} class="hover:text-main-400">
<%= name %>
</a>
<% end %>
<%= for %{route: route, name: name} <- @navigation_pages do %>
<a href={route} class="hover:text-main-400" phx-link="patch">
<%= name %>
</a>
<% end %>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion lib/exploring_beam_community_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ defmodule ExploringBeamCommunityWeb.Endpoint do
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
plug(Phoenix.LiveReloader)
plug(Phoenix.CodeReloader)
plug(Phoenix.Ecto.CheckRepoStatus, otp_app: :exploring_beam_community)
end

plug(Phoenix.LiveDashboard.RequestLogger,
Expand Down
24 changes: 0 additions & 24 deletions lib/exploring_beam_community_web/gettext.ex

This file was deleted.

8 changes: 5 additions & 3 deletions lib/exploring_beam_community_web/live/results.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
defmodule ExploringBeamCommunityWeb.ResultsView do
defmodule ExploringBeamCommunityWeb.ResultsLive do
use ExploringBeamCommunityWeb, :live_view
alias ExploringBeamCommunityWeb.Components.{Question}

def mount(_params, _session, socket) do
results =
case File.read("priv/static/results/dev_gi.json") do
priv_dir = Application.app_dir(:exploring_beam_community, "priv/static")
file_path = Path.join(priv_dir, "results/dev_gi.json")

results = case File.read(file_path) do
{:ok, file_content} ->
case Jason.decode(file_content) do
{:ok, data} -> data
Expand Down
15 changes: 0 additions & 15 deletions lib/exploring_beam_community_web/plugs/locale.ex

This file was deleted.

4 changes: 1 addition & 3 deletions lib/exploring_beam_community_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ defmodule ExploringBeamCommunityWeb.Router do
plug(:put_root_layout, html: {ExploringBeamCommunityWeb.Layouts, :root})
plug(:protect_from_forgery)
plug(:put_secure_browser_headers)
plug(ExploringBeamCommunityWeb.Plugs.Locale, "en")
end

scope "/", ExploringBeamCommunityWeb do
pipe_through(:browser)

get("/", HomeController, :index)
live("/results", ResultsView)
live("/results", ResultsLive)
get("/about-us", AboutUsController, :index)
end

Expand Down
3 changes: 0 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ defmodule ExploringBeamCommunity.MixProject do
defp deps do
[
{:phoenix, "~> 1.7.7"},
{:phoenix_ecto, "~> 4.4"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 3.3"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.19.0"},
{:floki, ">= 0.30.0", only: :test},
{:phoenix_live_dashboard, "~> 0.8.0"},
{:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
{:gettext, "~> 0.20"},
{:jason, "~> 1.4"},
{:plug_cowboy, "~> 2.5"},
{:hackney, "~> 1.20"},
Expand Down
Loading

0 comments on commit 829c288

Please sign in to comment.