Browse Source

Add some configuration options

main
Jeremy Boles 2 weeks ago
parent
commit
2bb9e501c3
Signed by: jb
GPG Key ID: 7DE0508F61CB57DF
  1. 2
      .formatter.exs
  2. 3
      .gitignore
  3. 2
      config/dev.exs
  4. 2
      config/prod.exs
  5. 5
      config/runtime.exs
  6. 6
      lib/ann/application.ex
  7. 8
      lib/storala/journal.ex
  8. 8
      lib/storala/wiki.ex

2
.formatter.exs

@ -1,5 +1,5 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
locals_without_parens: [plug: 1, plug: 2]
locals_without_parens: [config: 2, plug: 1, plug: 2]
]

3
.gitignore vendored

@ -24,3 +24,6 @@ ann-*.tar
# Temporary files, for example, from tests.
/tmp/
# Ignore locally checked out data
/priv/data/

2
config/dev.exs

@ -1 +1,3 @@
import Config
config :ann, Ann.Application, ip: {0, 0, 0, 0}, port: 4000

2
config/prod.exs

@ -1 +1,3 @@
import Config
config :ann, Ann.Application, ip: {127, 0, 0, 1}, port: 4000

5
config/runtime.exs

@ -1 +1,6 @@
import Config
if config_env() == :prod do
config :ann, Storala.Journal, data_path: System.get_env("ANN_JOURNAL_PATH")
config :ann, Storala.Wiki, data_path: System.get_env("ANN_WIKI_PATH")
end

6
lib/ann/application.ex

@ -4,10 +4,14 @@ defmodule Ann.Application do
@impl true
def start(_type, _args) do
children = [
{Bandit, plug: Ann.Plug, scheme: :http, options: [port: 4000]}
{Bandit,
plug: Ann.Plug, scheme: :http, options: [port: port(), transport_options: [ip: ip()]]}
]
opts = [strategy: :one_for_one, name: Ann.Supervisor]
Supervisor.start_link(children, opts)
end
defp ip, do: Application.get_env(:ann, __MODULE__) |> Keyword.get(:ip)
defp port, do: Application.get_env(:ann, __MODULE__) |> Keyword.get(:port)
end

8
lib/storala/journal.ex

@ -3,12 +3,16 @@ defmodule Storala.Journal do
alias __MODULE__.Entry
def all do
Path.wildcard(journal_path() <> "/**/*.md")
Path.wildcard(path() <> "/**/*.md")
|> Enum.map(&Markdown.parse_file!/1)
|> Enum.map(&Entry.new/1)
end
def get_entry(collection, id), do: collection |> Enum.find(&(&1.id == id))
defp journal_path, do: Path.expand("~/Ann/journal")
defp path do
:ann
|> Application.get_env(__MODULE__, [])
|> Keyword.get(:data_path, Application.app_dir(:ann, "priv/data/journal"))
end
end

8
lib/storala/wiki.ex

@ -3,12 +3,16 @@ defmodule Storala.Wiki do
alias __MODULE__.Topic
def all do
Path.wildcard(wiki_path() <> "/**/*.md")
Path.wildcard(path() <> "/**/*.md")
|> Enum.map(&Markdown.parse_file!/1)
|> Enum.map(&Topic.new/1)
end
def get_topic(collection, id), do: collection |> Enum.find(&(&1.id == id))
defp wiki_path, do: Path.expand("~/Ann/wiki")
defp path do
:ann
|> Application.get_env(__MODULE__, [])
|> Keyword.get(:data_path, Application.app_dir(:ann, "priv/data/wiki"))
end
end

Loading…
Cancel
Save