Skip to content

Commit 46364ab

Browse files
author
Robert Beene
committed
Format code with Elixir 1.6-rc.0
1 parent 6783c29 commit 46364ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+4937
-2745
lines changed

.formatter.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
3+
]

config/config.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ config :ex_admin,
3939
module: ExAdmin
4040

4141
config :phoenix, :template_engines,
42-
haml: PhoenixHaml.Engine,
43-
eex: Phoenix.Template.EExEngine
42+
haml: PhoenixHaml.Engine,
43+
eex: Phoenix.Template.EExEngine
4444

4545
# Sample configuration:
4646
#
@@ -55,4 +55,4 @@ config :phoenix, :template_engines,
5555
# Configuration from the imported file will override the ones defined
5656
# here (which is why it is important to import them last).
5757
#
58-
import_config "#{Mix.env}.exs"
58+
import_config "#{Mix.env()}.exs"

config/test.exs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ config :ex_admin, TestExAdmin.Endpoint,
44
http: [port: 4001],
55
secret_key_base: "HL0pikQMxNSA58DV3mf26O/eh1e4vaJDmx1qLgqBcnS14gbKu9Xn3x114D+mHYcX",
66
server: true
7-
#debug_errors: true
7+
8+
# debug_errors: true
89

910
config :ex_admin, TestExAdmin.Repo,
1011
adapter: Ecto.Adapters.Postgres,
@@ -25,7 +26,7 @@ config :ex_admin,
2526
TestExAdmin.ExAdmin.Simple,
2627
TestExAdmin.ExAdmin.ModelDisplayName,
2728
TestExAdmin.ExAdmin.DefnDisplayName,
28-
TestExAdmin.ExAdmin.RestrictedEdit,
29+
TestExAdmin.ExAdmin.RestrictedEdit
2930
]
3031

3132
config :xain,

lib/ex_admin.ex

+75-41
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ defmodule ExAdmin do
161161
import ExAdmin.Utils, only: [titleize: 1, humanize: 1, admin_resource_path: 2]
162162
require ExAdmin.Register
163163

164-
Code.ensure_compiled ExAdmin.Register
164+
Code.ensure_compiled(ExAdmin.Register)
165165

166-
Module.register_attribute __MODULE__, :registered, accumulate: true, persist: true
166+
Module.register_attribute(__MODULE__, :registered, accumulate: true, persist: true)
167167

168168
@default_theme ExAdmin.Theme.AdminLte2
169169

@@ -177,24 +177,29 @@ defmodule ExAdmin do
177177
# check for old xain.after_callback format and issue a compile time
178178
# exception if not configured correctly.
179179

180-
case Application.get_env :xain, :after_callback do
181-
nil -> nil
182-
{_, _} -> nil
180+
case Application.get_env(:xain, :after_callback) do
181+
nil ->
182+
nil
183+
184+
{_, _} ->
185+
nil
186+
183187
_ ->
184-
raise ExAdmin.CompileError, message: "Invalid xain_callback in config. Use {Phoenix.HTML, :raw}"
188+
raise ExAdmin.CompileError,
189+
message: "Invalid xain_callback in config. Use {Phoenix.HTML, :raw}"
185190
end
186191

187192
@doc false
188-
def registered, do: Application.get_env(:ex_admin, :modules, []) |> Enum.reverse
193+
def registered, do: Application.get_env(:ex_admin, :modules, []) |> Enum.reverse()
189194

190195
@doc false
191196
def put_data(key, value) do
192-
Agent.update __MODULE__, &(Map.put(&1, key, value))
197+
Agent.update(__MODULE__, &Map.put(&1, key, value))
193198
end
194199

195200
@doc false
196201
def get_data(key) do
197-
Agent.get __MODULE__, &(Map.get(&1, key))
202+
Agent.get(__MODULE__, &Map.get(&1, key))
198203
end
199204

200205
@doc false
@@ -203,6 +208,7 @@ defmodule ExAdmin do
203208
case get_registered_resource(reg) do
204209
%{resource_model: rm} = item ->
205210
{rm, item}
211+
206212
%{type: :page} = item ->
207213
{nil, item}
208214
end
@@ -220,33 +226,45 @@ defmodule ExAdmin do
220226
get_registered_resource(reg)
221227
end
222228
end
229+
223230
@doc false
224231
def get_registered(resource_model) do
225232
get_all_registered()
226233
|> Keyword.get(resource_model)
227234
end
228235

229-
230236
def get_registered_by_association(resource, assoc_name) do
231237
resource_model = resource.__struct__
232-
assoc_model = case resource_model.__schema__(:association, assoc_name) do
233-
%{through: [link1, link2]} ->
234-
resource |> Ecto.build_assoc(link1) |> Ecto.build_assoc(link2) |> Map.get(:__struct__)
235-
%{queryable: assoc_model} ->
236-
assoc_model
237-
nil ->
238-
raise ArgumentError.exception("Association #{assoc_name} is not found.\n#{inspect(resource_model)}.__schema__(:association, #{inspect(assoc_name)}) returns nil")
239-
_ ->
240-
raise ArgumentError.exception("Association type of #{assoc_name} is not supported. Please, fill an issue.")
241-
end
242-
Enum.find get_registered(), %{}, &(Map.get(&1, :resource_model) == assoc_model)
243-
end
244238

239+
assoc_model =
240+
case resource_model.__schema__(:association, assoc_name) do
241+
%{through: [link1, link2]} ->
242+
resource |> Ecto.build_assoc(link1) |> Ecto.build_assoc(link2) |> Map.get(:__struct__)
243+
244+
%{queryable: assoc_model} ->
245+
assoc_model
246+
247+
nil ->
248+
raise ArgumentError.exception(
249+
"Association #{assoc_name} is not found.\n#{inspect(resource_model)}.__schema__(:association, #{
250+
inspect(assoc_name)
251+
}) returns nil"
252+
)
253+
254+
_ ->
255+
raise ArgumentError.exception(
256+
"Association type of #{assoc_name} is not supported. Please, fill an issue."
257+
)
258+
end
259+
260+
Enum.find(get_registered(), %{}, &(Map.get(&1, :resource_model) == assoc_model))
261+
end
245262

246263
@doc false
247264
def get_controller_path(%{} = resource) do
248-
get_controller_path Map.get(resource, :__struct__)
265+
get_controller_path(Map.get(resource, :__struct__))
249266
end
267+
250268
@doc false
251269
def get_controller_path(resource_model) when is_atom(resource_model) do
252270
get_all_registered()
@@ -266,6 +284,7 @@ defmodule ExAdmin do
266284
case get_registered(name) do
267285
nil ->
268286
&__MODULE__.default_page_title_actions/2
287+
269288
%{title_actions: actions} ->
270289
actions
271290
end
@@ -274,35 +293,42 @@ defmodule ExAdmin do
274293
@doc false
275294
def get_name_from_controller(controller) when is_atom(controller) do
276295
get_all_registered()
277-
|> Enum.find_value(fn({name, %{controller: c_name}}) ->
296+
|> Enum.find_value(fn {name, %{controller: c_name}} ->
278297
if c_name == controller, do: name
279298
end)
280299
end
281300

282301
@doc false
283-
def default_resource_title_actions(%Plug.Conn{params: params} = conn, %{resource_model: resource_model} = defn) do
302+
def default_resource_title_actions(
303+
%Plug.Conn{params: params} = conn,
304+
%{resource_model: resource_model} = defn
305+
) do
284306
singular = ExAdmin.Utils.displayable_name_singular(conn) |> titleize
285307
actions = defn.actions
308+
286309
case Utils.action_name(conn) do
287310
:show ->
288311
id = Map.get(params, "id")
289-
Enum.reduce([:edit, :new, :delete], [], fn(action, acc) ->
312+
313+
Enum.reduce([:edit, :new, :delete], [], fn action, acc ->
290314
if Utils.authorized_action?(conn, action, resource_model) do
291-
[{action, action_button(conn, defn, singular, :show, action, actions, id)}|acc]
315+
[{action, action_button(conn, defn, singular, :show, action, actions, id)} | acc]
292316
else
293317
acc
294318
end
295319
end)
296320
|> add_custom_actions(:show, actions, id)
297-
|> Enum.reverse
321+
|> Enum.reverse()
322+
298323
action when action in [:index, :edit] ->
299324
if Utils.authorized_action?(conn, action, resource_model) do
300325
[{:new, action_button(conn, defn, singular, action, :new, actions)}]
301326
else
302327
[]
303328
end
304329
|> add_custom_actions(action, actions)
305-
|> Enum.reverse
330+
|> Enum.reverse()
331+
306332
_ ->
307333
[]
308334
end
@@ -340,46 +366,54 @@ defmodule ExAdmin do
340366

341367
defp add_custom_actions(acc, action, actions, id \\ nil)
342368
defp add_custom_actions(acc, _action, [], _id), do: acc
369+
343370
defp add_custom_actions(acc, action, [{action, button} | actions], id) do
344371
import ExAdmin.ViewHelpers
345-
endpoint() # remove the compiler warning
346-
{fun, _} = Code.eval_quoted button, [id: id], __ENV__
372+
# remove the compiler warning
373+
endpoint()
374+
{fun, _} = Code.eval_quoted(button, [id: id], __ENV__)
375+
347376
cond do
348377
is_function(fun, 1) -> [fun.(id) | acc]
349378
is_function(fun, 0) -> [fun.() | acc]
350-
true -> acc
379+
true -> acc
351380
end
352381
|> add_custom_actions(action, actions, id)
353382
end
354-
defp add_custom_actions(acc, action, [_|actions], id) do
383+
384+
defp add_custom_actions(acc, action, [_ | actions], id) do
355385
add_custom_actions(acc, action, actions, id)
356386
end
357387

358388
defp action_link(conn, name, :delete, _id) do
359-
{name,
360-
[href: admin_resource_path(conn, :destroy),
361-
"data-confirm": Utils.confirm_message,
362-
"data-method": :delete, rel: :nofollow]}
389+
{name, [
390+
href: admin_resource_path(conn, :destroy),
391+
"data-confirm": Utils.confirm_message(),
392+
"data-method": :delete,
393+
rel: :nofollow
394+
]}
363395
end
396+
364397
defp action_link(conn, name, action, _id) do
365398
{name, [href: admin_resource_path(conn, action)]}
366399
end
367400

368401
@doc false
369402
def has_action?(conn, defn, action) do
370403
if ExAdmin.Utils.authorized_action?(conn, action, defn),
371-
do: _has_action?(defn, action), else: false
404+
do: _has_action?(defn, action),
405+
else: false
372406
end
373407

374408
defp _has_action?(defn, action) do
375-
except = Keyword.get defn.actions, :except, []
376-
only = Keyword.get defn.actions, :only, []
409+
except = Keyword.get(defn.actions, :except, [])
410+
only = Keyword.get(defn.actions, :only, [])
411+
377412
cond do
378413
action in defn.actions -> true
379414
action in only -> true
380415
action in except -> false
381416
true -> false
382417
end
383418
end
384-
385419
end

lib/ex_admin/adminlog.ex

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
defmodule ExAdmin.Adminlog do
2-
32
defmacro __using__(_) do
43
quote do
54
alias ExAdmin.Adminlog
@@ -8,30 +7,33 @@ defmodule ExAdmin.Adminlog do
87
end
98

109
defmacro debug(message) do
11-
if Mix.env in [:dev, :test] and Application.get_env(:ex_admin, :logger, false) do
10+
if Mix.env() in [:dev, :test] and Application.get_env(:ex_admin, :logger, false) do
1211
quote do
13-
Logger.debug unquote(message)
12+
Logger.debug(unquote(message))
1413
end
1514
end
1615
end
16+
1717
defmacro info(message) do
18-
if Mix.env in [:dev, :test] and Application.get_env(:ex_admin, :logger, false) do
18+
if Mix.env() in [:dev, :test] and Application.get_env(:ex_admin, :logger, false) do
1919
quote do
20-
Logger.info unquote(message)
20+
Logger.info(unquote(message))
2121
end
2222
end
2323
end
24+
2425
defmacro warn(message) do
25-
if Mix.env in [:dev, :test] and Application.get_env(:ex_admin, :logger, false) do
26+
if Mix.env() in [:dev, :test] and Application.get_env(:ex_admin, :logger, false) do
2627
quote do
27-
Logger.warn unquote(message)
28+
Logger.warn(unquote(message))
2829
end
2930
end
3031
end
32+
3133
defmacro error(message) do
32-
if Mix.env in [:dev, :test] and Application.get_env(:ex_admin, :logger, false) do
34+
if Mix.env() in [:dev, :test] and Application.get_env(:ex_admin, :logger, false) do
3335
quote do
34-
Logger.error unquote(message)
36+
Logger.error(unquote(message))
3537
end
3638
end
3739
end

0 commit comments

Comments
 (0)