forked from erlef/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify community resources and refactor events
- Move static community resources into Community.Resources and delegate to Resources.all/0 as resources/0 from Community - Community.Resources loads up the data from priv/data/community which faciliates easier contributions to community resources. - Fellows likewise also now loads and compiles it's data in at compile time from priv/data/fellows.exs - Added Erlef.data_path/1 and Erlef.get_data/1 to support loading of data from priv/data - Added Erlef.in_env?/1 to avoid redundancies in checking if the app is running in a particular set of environments - The Events context module has been merged into the Community context - Event and EventType now live in Community - Erlef.Query.Event is now Erlef.Community.Query - Make readme the top page in ex_doc - Added fake s3 server to ease development of events - Remove priv/events (obsolete) - Removed Erlef.Community.Event.changeset/2 (not in use) - Ignore lib/erlef/release.ex in coverage - Removed dead category helper from ErlefWeb.BlogView - Move Erlef.Seeds into priv/repo.seeds.exs - Append 127.0.0.1:9998 to trusted sources in ErlefWeb.Router so images uploaded to the fake s3 server can be viewed in dev mode. - Added misc tests for existing code
- Loading branch information
Showing
65 changed files
with
563 additions
and
735 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
defmodule Erlef do | ||
@moduledoc false | ||
|
||
@spec in_env?([atom()]) :: boolean() | ||
def in_env?(envs), do: Application.get_env(:erlef, :env) in envs | ||
|
||
@spec is_env?(atom) :: boolean() | ||
def is_env?(env), do: Application.get_env(:erlef, :env) == env | ||
|
||
def data_path(path) do | ||
List.to_string(:code.priv_dir(:erlef)) <> "/data/#{path}" | ||
end | ||
|
||
def get_data(path) do | ||
{term, _binding} = Code.eval_file(data_path(path)) | ||
term | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/erlef/schema/event_type.ex → lib/erlef/community/event_type.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule Erlef.Community.Resources do | ||
@moduledoc """ | ||
Module for getting static community data | ||
All resources data for the community page of the site can be found in | ||
[priv/data/community](priv/data/community). | ||
Said data ends up compiled into this module along with a few dynamically generated helper functions. | ||
As an example,we have all active languages in | ||
`priv/data/community/languages.exs`, | ||
this file ends up being evalulated and the base name of the file without the | ||
extension (i.e., `"languages"`) ends up being used to create a helper function called `all_languages/0`. | ||
Like wise the atom `languages` is also used as a key pointing to the evalulated term as returned by the `all/0` function. | ||
""" | ||
|
||
data = | ||
for d <- "priv/data/community/*.exs" |> Path.wildcard() |> Enum.sort() do | ||
@external_resource d | ||
base_name = Path.basename(d) |> String.replace(".exs", "") | ||
name = String.to_atom(base_name) | ||
fn_name = String.to_atom("all_#{base_name}") | ||
{evaled, _} = Code.eval_file(d) | ||
val = Macro.escape(evaled) | ||
|
||
def unquote(fn_name)() do | ||
unquote(val) | ||
end | ||
|
||
{name, evaled} | ||
end | ||
|
||
@data Enum.reduce(data, %{}, fn {k, v}, acc -> Map.put(acc, k, v) end) | ||
|
||
def all() do | ||
@data | ||
end | ||
end |
Oops, something went wrong.