diff --git a/.travis.yml b/.travis.yml index 100bd97..2d7931a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ before_script: - psql -c 'create database addict_test;' -U postgres language: elixir elixir: - - 1.2.0 + - 1.5.2 otp_release: - - 18.2.1 + - 20.1 sudo: false notifications: recipients: diff --git a/lib/addict/controller.ex b/lib/addict/controller.ex index cc90370..26c2db3 100644 --- a/lib/addict/controller.ex +++ b/lib/addict/controller.ex @@ -27,7 +27,7 @@ defmodule Addict.AddictController do Renders registration layout """ def register(%{method: "GET"} = conn, _) do - csrf_token = generate_csrf_token + csrf_token = generate_csrf_token() conn |> put_addict_layout |> render("register.html", csrf_token: csrf_token) @@ -54,7 +54,7 @@ defmodule Addict.AddictController do Renders login layout """ def login(%{method: "GET"} = conn, _) do - csrf_token = generate_csrf_token + csrf_token = generate_csrf_token() conn |> put_addict_layout |> render("login.html", csrf_token: csrf_token) @@ -90,7 +90,7 @@ defmodule Addict.AddictController do Renders Password Recovery layout """ def recover_password(%{method: "GET"} = conn, _) do - csrf_token = generate_csrf_token + csrf_token = generate_csrf_token() conn |> put_addict_layout |> render("recover_password.html", csrf_token: csrf_token) @@ -113,7 +113,7 @@ defmodule Addict.AddictController do Renders Password Reset layout """ def reset_password(%{method: "GET"} = conn, params) do - csrf_token = generate_csrf_token + csrf_token = generate_csrf_token() token = params["token"] signature = params["signature"] conn @@ -154,16 +154,16 @@ defmodule Addict.AddictController do end defp generate_csrf_token do - if Addict.Configs.generate_csrf_token != nil do - Addict.Helper.exec Addict.Configs.generate_csrf_token, [] + if Addict.Configs.generate_csrf_token() != nil do + Addict.Helper.exec Addict.Configs.generate_csrf_token(), [] else "" end end defp parse(user_params) do - if user_params[schema_name_string] != nil do - user_params[schema_name_string] + if user_params[schema_name_string()] != nil do + user_params[schema_name_string()] else user_params end diff --git a/lib/addict/mailers/mailers.ex b/lib/addict/mailers/mailers.ex index d0ca48e..61769fe 100644 --- a/lib/addict/mailers/mailers.ex +++ b/lib/addict/mailers/mailers.ex @@ -14,7 +14,7 @@ defmodule Addict.Mailers do end defp do_send_email(to, from, subject, html_body, mail_service) do - mail_service = to_string(mail_service) |> Mix.Utils.camelize + mail_service = to_string(mail_service) |> Macro.camelize mailer = Module.concat Addict.Mailers, mail_service mailer.send_email(to, from, subject, html_body) end diff --git a/lib/addict/mix/generate_boilerplate.ex b/lib/addict/mix/generate_boilerplate.ex index c3bc650..c4805ea 100644 --- a/lib/addict/mix/generate_boilerplate.ex +++ b/lib/addict/mix/generate_boilerplate.ex @@ -9,7 +9,7 @@ defmodule Mix.Tasks.Addict.Generate.Boilerplate do embed_template :view, """ defmodule Addict.AddictView do use Phoenix.HTML - use Phoenix.View, root: "web/templates/" + use Phoenix.View, root: "lib/<%= @web_directory %>/templates/" import Phoenix.Controller, only: [view_module: 1] import <%= @base_route_helper %> end @@ -22,42 +22,45 @@ defmodule Mix.Tasks.Addict.Generate.Boilerplate do Mix.shell.error "[x] Please make sure your Addict configuration exists first. Generate it via mix:" Mix.shell.error "[x] mix addict.generate.configs" else - base_module = guess_application_name Mix.shell.info "[o] Generating Addict boilerplate" - create_addict_templates - create_addict_view + create_addict_templates() + create_addict_view() end Mix.shell.info "[o] Done!" end defp create_addict_templates do - create_file Path.join(["web", "templates", "addict", "addict.html.eex"]) + create_file Path.join(["lib", guess_application_web_directory(), "templates", "addict", "addict.html.eex"]) |> Path.relative_to(Mix.Project.app_path), - template_text - create_file Path.join(["web", "templates", "addict", "login.html.eex"]) + template_text() + create_file Path.join(["lib", guess_application_web_directory(), "templates", "addict", "login.html.eex"]) |> Path.relative_to(Mix.Project.app_path), - login_text - create_file Path.join(["web", "templates", "addict", "register.html.eex"]) + login_text() + create_file Path.join(["lib", guess_application_web_directory(), "templates", "addict", "register.html.eex"]) |> Path.relative_to(Mix.Project.app_path), - register_text - create_file Path.join(["web", "templates", "addict", "recover_password.html.eex"]) + register_text() + create_file Path.join(["lib", guess_application_web_directory(), "templates", "addict", "recover_password.html.eex"]) |> Path.relative_to(Mix.Project.app_path), - recover_password_text - create_file Path.join(["web", "templates", "addict", "reset_password.html.eex"]) + recover_password_text() + create_file Path.join(["lib", guess_application_web_directory(), "templates", "addict", "reset_password.html.eex"]) |> Path.relative_to(Mix.Project.app_path), - reset_password_text + reset_password_text() end defp create_addict_view do - view_file = Path.join(["web", "views", "addict_view.ex"]) + view_file = Path.join(["lib", guess_application_web_directory(), "views", "addict_view.ex"]) |> Path.relative_to(Mix.Project.app_path) - create_file view_file, view_template(base_route_helper: (guess_application_name <> ".Router.Helpers")) + create_file view_file, view_template(base_route_helper: (guess_application_name() <> "Web.Router.Helpers"), web_directory: guess_application_web_directory()) end defp guess_application_name do - Mix.Project.config()[:app] |> Atom.to_string |> Mix.Utils.camelize + Mix.Project.config()[:app] |> Atom.to_string |> Macro.camelize + end + + defp guess_application_web_directory do + guess_application_name() <> "_web" |> String.downcase end defp addict_config_already_exists?(configs_path) do diff --git a/lib/addict/mix/generate_configs.ex b/lib/addict/mix/generate_configs.ex index 3732d02..ca76b6d 100644 --- a/lib/addict/mix/generate_configs.ex +++ b/lib/addict/mix/generate_configs.ex @@ -14,35 +14,35 @@ defmodule Mix.Tasks.Addict.Generate.Configs do Mix.shell.info "[o] Generating Addict configuration" guessed = Mix.shell.yes? "Is your application root module #{base_module}?" - base_module = + base_module = case guessed do true -> base_module false -> Mix.shell.prompt("Please insert your application root module:") |> String.rstrip end guessed = Mix.shell.yes? "Is your Ecto Repository module #{repo}?" - repo = + repo = case guessed do true -> repo false -> Mix.shell.prompt("Please insert your Ecto Repository module:") |> String.rstrip end guessed = Mix.shell.yes? "Is your User Schema module #{user_schema}?" - user_schema = + user_schema = case guessed do true -> user_schema false -> Mix.shell.prompt("Please insert your User Schema module:") |> String.rstrip end use_mailgun = Mix.shell.yes? "Will you be using Mailgun?" - mailgun_domain = + mailgun_domain = case use_mailgun do true -> Mix.shell.prompt("Please insert your Mailgun domain: (e.g.: https://api.mailgun.net/v3/sandbox123456.mailgun.org)") |> String.rstrip false -> "" end - mailgun_api_key = - case use_mailgun do + mailgun_api_key = + case use_mailgun do true -> Mix.shell.prompt("Please insert your Mailgun API key:") |> String.rstrip false -> "" end @@ -54,7 +54,7 @@ defmodule Mix.Tasks.Addict.Generate.Configs do end defp guess_application_name do - Mix.Project.config()[:app] |> Atom.to_string |> Mix.Utils.camelize + Mix.Project.config()[:app] |> Atom.to_string |> Macro.camelize end defp addict_config_already_exists?(configs_path) do diff --git a/mix.exs b/mix.exs index a186975..c96beaf 100644 --- a/mix.exs +++ b/mix.exs @@ -5,10 +5,10 @@ defmodule Addict.Mixfile do [app: :addict, version: "0.3.0", elixir: "~> 1.2", - description: description, - package: package, + description: description(), + package: package(), docs: &docs/0, - deps: deps] + deps: deps()] end def application do @@ -25,13 +25,13 @@ defmodule Addict.Mixfile do defp deps do [{:cowboy, "~> 1.0"}, - {:phoenix, "~> 1.1"}, + {:phoenix, "~> 1.3"}, {:ecto, "~> 2.0"}, {:comeonin, "~> 2.1" }, - {:mailgun, "~> 0.1"}, {:mock, "~> 0.1.3", only: :test}, {:postgrex, "~> 0.11", only: :test}, {:earmark, "~> 0.2", only: :dev}, + {:mailgun, github: "chrismccord/mailgun", branch: "master", override: true}, {:ex_doc, "~> 0.11", only: :dev}] end diff --git a/mix.lock b/mix.lock index 6e6c058..80522e5 100644 --- a/mix.lock +++ b/mix.lock @@ -1,6 +1,6 @@ %{"comeonin": {:hex, :comeonin, "2.1.1", "6187c3764e98c3a963650f64cef067e01daed2f2de4177f666f60b50c14e9981", [:mix, :make, :make], []}, "connection": {:hex, :connection, "1.0.3", "3145f7416be3df248a4935f24e3221dc467c1e3a158d62015b35bd54da365786", [:mix], []}, - "cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [:rebar, :make], [{:cowlib, "~> 1.0.0", [hex: :cowlib, optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, optional: false]}]}, + "cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"}, "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], []}, "db_connection": {:hex, :db_connection, "1.0.0-rc.3", "d9ceb670fe300271140af46d357b669983cd16bc0d01206d7d3222dde56cf038", [:mix], [{:sbroker, "~> 1.0.0-beta.3", [hex: :sbroker, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:connection, "~> 1.0.2", [hex: :connection, optional: false]}]}, "decimal": {:hex, :decimal, "1.1.2", "79a769d4657b2d537b51ef3c02d29ab7141d2b486b516c109642d453ee08e00c", [:mix], []}, @@ -8,13 +8,15 @@ "ecto": {:hex, :ecto, "2.0.2", "b02331c1f20bbe944dbd33c8ecd8f1ccffecc02e344c4471a891baf3a25f5406", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}, {:mariaex, "~> 0.7.7", [hex: :mariaex, optional: true]}, {:postgrex, "~> 0.11.2", [hex: :postgrex, optional: true]}, {:db_connection, "~> 1.0-rc.2", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}]}, "ecto_fixtures": {:hex, :ecto_fixtures, "0.0.2"}, "ex_doc": {:hex, :ex_doc, "0.11.4", "a064bdb720594c3745b94709b17ffb834fd858b4e0c1f48f37c0d92700759e02", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]}, - "mailgun": {:hex, :mailgun, "0.1.2", "37c1306675cf27a66a13dea3c9d479da2a990f0aed296b5addbd0b07529b667d", [:mix], [{:poison, "~> 1.4", [hex: :poison, optional: false]}]}, + "mailgun": {:git, "https://github.com/chrismccord/mailgun.git", "ace116f37a86b3b11cecad6f37c4599f4552452b", [branch: "master"]}, "meck": {:hex, :meck, "0.8.4", "59ca1cd971372aa223138efcf9b29475bde299e1953046a0c727184790ab1520", [:rebar, :make], []}, + "mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [], [], "hexpm"}, "mock": {:hex, :mock, "0.1.3", "657937b03f88fce89b3f7d6becc9f1ec1ac19c71081aeb32117db9bc4d9b3980", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, optional: false]}]}, - "phoenix": {:hex, :phoenix, "1.1.4", "65809fba92eb94377372a5fb5a561197654bb8406e773cc47ca1a031bbe58019", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}, {:plug, "~> 1.0", [hex: :plug, optional: false]}, {:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}]}, - "plug": {:hex, :plug, "1.1.2", "7ed5cdc0245a56fcc9ad905c059dd2314cea9d043e6d0b8fd99b4845a3e220d5", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}]}, - "poison": {:hex, :poison, "1.5.2", "560bdfb7449e3ddd23a096929fb9fc2122f709bcc758b2d5d5a5c7d0ea848910", [:mix], []}, + "phoenix": {:hex, :phoenix, "1.3.0", "1c01124caa1b4a7af46f2050ff11b267baa3edb441b45dbf243e979cd4c5891b", [], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [], [], "hexpm"}, + "plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"}, + "poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [], [], "hexpm"}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, "postgrex": {:hex, :postgrex, "0.11.2", "139755c1359d3c5c6d6e8b1ea72556d39e2746f61c6ddfb442813c91f53487e8", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.0-rc", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}, - "ranch": {:hex, :ranch, "1.2.1", "a6fb992c10f2187b46ffd17ce398ddf8a54f691b81768f9ef5f461ea7e28c762", [:make], []}, + "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [], [], "hexpm"}, "uuid": {:hex, :uuid, "1.1.3"}}