Skip to content

Commit

Permalink
using config for helpers everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan committed Apr 15, 2019
1 parent 7b57ad1 commit 89ef6eb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/sort_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Sortex.SortView do
def column_class, do: "sortex-clickable-column"

def sorted_column(conn, opts) do
helper = opts[:helper]
helper_action = opts[:helper]
action = opts[:action] || :index
helpers_module = Application.get_env(:sortex, :route_helpers_module)

Expand All @@ -13,19 +13,19 @@ defmodule Sortex.SortView do

url =
case opts[:route_params] do
nil -> apply(helpers_module, helper, [conn, action, params])
route_params -> add_params(conn, helper, action, route_params, params)
nil -> apply(helpers_module, helper_action, [conn, action, params])
route_params -> add_params(helpers_module, conn, helper_action, action, route_params, params)
end

Phoenix.HTML.raw(~s(<a href="#{url}" class="#{column_class()}">#{title(opts, arrow)}</a>))
end

defp add_params(conn, helper, action, route_params, params) when is_list(route_params) do
apply(Helpers, helper, [conn, action] ++ route_params ++ [params])
defp add_params(helpers_module, conn, helper_action, action, route_params, params) when is_list(route_params) do
apply(helpers_module, helper_action, [conn, action] ++ route_params ++ [params])
end

defp add_params(conn, helper, action, route_params, params) do
apply(Helpers, helper, [conn, action, route_params, params])
defp add_params(helpers_module, conn, helper_action, action, route_params, params) do
apply(helpers_module, helper_action, [conn, action, route_params, params])
end

defp params(opts, query_params, direction) do
Expand Down

0 comments on commit 89ef6eb

Please sign in to comment.