logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker git clone https://hacktivis.me/git/auto_linker.git
commit: 76cfb574a3ecfd80f43ef9abe2017a081a6314a4
parent 529014c8f4efc2f953b3e93411234f24f80838d6
Author: Egor Kislitsyn <egor@kislitsyn.com>
Date:   Fri, 21 Jun 2019 19:39:58 +0700

Remove application configuration

Diffstat:

Dconfig/config.exs30------------------------------
Mlib/auto_linker/parser.ex24++++++------------------
2 files changed, 6 insertions(+), 48 deletions(-)

diff --git a/config/config.exs b/config/config.exs @@ -1,30 +0,0 @@ -# This file is responsible for configuring your application -# and its dependencies with the aid of the Mix.Config module. -use Mix.Config - -# This configuration is loaded before any dependency and is restricted -# to this project. If another project depends on this project, this -# file won't be loaded nor affect the parent project. For this reason, -# if you want to provide default values for your application for -# 3rd-party users, it should be done in your "mix.exs" file. - -# You can configure for your application as: -# -# config :auto_linker, key: :value -# -# And access this configuration in your application as: -# -# Application.get_env(:auto_linker, :key) -# -# Or configure a 3rd-party app: -# -# config :logger, level: :info -# - -# It is also possible to import configuration files, relative to this -# directory. For example, you can emulate configuration per environment -# by uncommenting the line below and defining dev.exs, test.exs and such. -# Configuration from the imported file will override the ones defined -# here (which is why it is important to import them last). -# -# import_config "#{Mix.env}.exs" diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex @@ -38,7 +38,10 @@ defmodule AutoLinker.Parser do @tlds "./priv/tlds.txt" |> File.read!() |> String.split("\n", trim: true) |> MapSet.new() - @default_opts ~w(url validate_tld)a + @default_opts %{ + url: true, + validate_tld: true + } @doc """ Parse the given string, identifying items to link. @@ -52,27 +55,12 @@ defmodule AutoLinker.Parser do """ def parse(input, opts \\ %{}) - def parse(input, opts) when is_binary(input), do: {input, nil} |> parse(opts) |> elem(0) + def parse(input, opts) when is_binary(input), do: {input, %{}} |> parse(opts) |> elem(0) def parse(input, list) when is_list(list), do: parse(input, Enum.into(list, %{})) def parse(input, opts) do - config = - :auto_linker - |> Application.get_env(:opts, []) - |> Enum.into(%{}) - |> Map.put( - :attributes, - Application.get_env(:auto_linker, :attributes, []) - ) + opts = Map.merge(@default_opts, opts) - opts = - Enum.reduce(@default_opts, opts, fn opt, acc -> - if is_nil(opts[opt]) and is_nil(config[opt]) do - Map.put(acc, opt, true) - else - acc - end - end) do_parse(input, Map.merge(config, opts)) end