diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..562e886 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +[ + import_deps: [:phoenix], + inputs: ["*.{ex,exs}", "{config,lib,priv,test}/**/*.{ex,exs}"] +] diff --git a/config/config.exs b/config/config.exs index cbb472a..c3ff5fc 100644 --- a/config/config.exs +++ b/config/config.exs @@ -3,3 +3,5 @@ use Mix.Config config :phoenix, :template_engines, slim: PhoenixSlime.Engine, slime: PhoenixSlime.Engine + +config :phoenix, :json_library, Jason diff --git a/lib/mix/tasks/phoenix.gen.html.slime.ex b/lib/mix/tasks/phoenix.gen.html.slime.ex deleted file mode 100644 index de23404..0000000 --- a/lib/mix/tasks/phoenix.gen.html.slime.ex +++ /dev/null @@ -1,185 +0,0 @@ -defmodule Mix.Tasks.Phoenix.Gen.Html.Slime do - use Mix.Task - - @shortdoc "Generates controller, model and views for an HTML based resource using Slime templates" - - @moduledoc """ - This file was adapted from the original Phoenix html generator found here: - - https://github.com/phoenixframework/phoenix/blob/v1.1/lib/mix/tasks/phoenix.gen.html.ex - - Generates a Phoenix resource. - - mix phoenix_slime.gen.html User users name:string age:integer - - The first argument is the module name followed by - its plural name (used for resources and schema). - - The generated resource will contain: - - * a schema in web/models - * a view in web/views - * a controller in web/controllers - * a migration file for the repository - * default CRUD templates in web/templates - * test files for generated model and controller - - The generated model can be skipped with `--no-model`. - Read the documentation for `phoenix.gen.model` for more - information on attributes and namespaced resources. - """ - def run(args) do - switches = [binary_id: :boolean, model: :boolean] - - {opts, parsed, _} = OptionParser.parse(args, switches: switches) - [singular, plural | attrs] = validate_args!(parsed) - - default_opts = Application.get_env(:phoenix, :generators, []) - opts = Keyword.merge(default_opts, opts) - - attrs = Mix.Phoenix.Schema.attrs(attrs) - binding = Mix.Phoenix.inflect(singular) - path = binding[:path] - route = String.split(path, "/") |> Enum.drop(-1) |> Kernel.++([plural]) |> Enum.join("/") - - binding = - binding ++ - [ - plural: plural, - route: route, - attrs: attrs, - binary_id: opts[:binary_id], - sample_id: sample_id(opts), - inputs: inputs(attrs), - params: Mix.Phoenix.Schema.params(attrs), - template_singular: String.replace(binding[:singular], "_", " "), - template_plural: String.replace(plural, "_", " ") - ] - - Mix.Phoenix.check_module_name_availability!(binding[:module] <> "Controller") - Mix.Phoenix.check_module_name_availability!(binding[:module] <> "View") - - Mix.Phoenix.copy_from(paths(), "priv/templates/phoenix.gen.html", binding, [ - {:eex, "controller.ex", "web/controllers/#{path}_controller.ex"}, - {:eex, "view.ex", "web/views/#{path}_view.ex"}, - {:eex, "controller_test.exs", "test/controllers/#{path}_controller_test.exs"} - ]) - - extension = PhoenixSlime.ConfiguredExtension.file_extension() - - Mix.Phoenix.copy_from(slime_paths(), "priv/templates/phoenix.gen.html.slime", binding, [ - {:eex, "edit.html.eex", "web/templates/#{path}/edit.html.#{extension}"}, - {:eex, "form.html.eex", "web/templates/#{path}/form.html.#{extension}"}, - {:eex, "index.html.eex", "web/templates/#{path}/index.html.#{extension}"}, - {:eex, "new.html.eex", "web/templates/#{path}/new.html.#{extension}"}, - {:eex, "show.html.eex", "web/templates/#{path}/show.html.#{extension}"} - ]) - - instructions = """ - - Add the resource to your browser scope in web/router.ex: - - resources "/#{route}", #{binding[:scoped]}Controller - """ - - if opts[:model] != false do - Mix.Task.run("phoenix.gen.model", ["--instructions", instructions | args]) - else - Mix.shell().info(instructions) - end - end - - defp sample_id(opts) do - if Keyword.get(opts, :binary_id, false) do - Keyword.get(opts, :sample_binary_id, "11111111-1111-1111-1111-111111111111") - else - -1 - end - end - - defp validate_args!([_, plural | _] = args) do - cond do - String.contains?(plural, ":") -> - raise_with_help() - - plural != Phoenix.Naming.underscore(plural) -> - Mix.raise( - "Expected the second argument, #{inspect(plural)}, to be all lowercase using snake_case convention" - ) - - true -> - args - end - end - - defp validate_args!(_) do - raise_with_help() - end - - defp raise_with_help do - Mix.raise(""" - mix phoenix_slime.gen.html expects both singular and plural names - of the generated resource followed by any number of attributes: - - mix phoenix_slime.gen.html User users name:string - """) - end - - defp inputs(attrs) do - Enum.map(attrs, fn - {_, {:array, _}} -> - {nil, nil, nil} - - {_, {:references, _}} -> - {nil, nil, nil} - - {key, :integer} -> - {label(key), ~s(= number_input f, #{inspect(key)}, class: "form-control"), error(key)} - - {key, :float} -> - {label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"), - error(key)} - - {key, :decimal} -> - {label(key), ~s(= number_input f, #{inspect(key)}, step: "any", class: "form-control"), - error(key)} - - {key, :boolean} -> - {label(key), ~s(= checkbox f, #{inspect(key)}, class: "form-control"), error(key)} - - {key, :text} -> - {label(key), ~s(= textarea f, #{inspect(key)}, class: "form-control"), error(key)} - - {key, :date} -> - {label(key), ~s(= date_select f, #{inspect(key)}, class: "form-control"), error(key)} - - {key, :time} -> - {label(key), ~s(= time_select f, #{inspect(key)}, class: "form-control"), error(key)} - - {key, :utc_datetime} -> - {label(key), ~s(= datetime_select f, #{inspect(key)}, class: "form-control"), error(key)} - - {key, :naive_datetime} -> - {label(key), ~s(= datetime_select f, #{inspect(key)}, class: "form-control"), error(key)} - - {key, _} -> - {label(key), ~s(= text_input f, #{inspect(key)}, class: "form-control"), error(key)} - end) - end - - defp label(key) do - ~s(= label f, #{inspect(key)}, class: "control-label") - end - - defp error(field) do - ~s(= error_tag f, #{inspect(field)}) - end - - defp paths do - [".", :phoenix] - end - - defp slime_paths do - [".", :phoenix_slime] - end -end diff --git a/lib/mix/tasks/phoenix.gen.layout.slime.ex b/lib/mix/tasks/phoenix.gen.layout.slime.ex deleted file mode 100644 index c11556b..0000000 --- a/lib/mix/tasks/phoenix.gen.layout.slime.ex +++ /dev/null @@ -1,32 +0,0 @@ -defmodule Mix.Tasks.Phoenix.Gen.Layout.Slime do - use Mix.Task - - @shortdoc "Generates a default Phoenix layout file in Slime" - - @moduledoc """ - Generates a Phoenix layout file in Slime. - - mix phoenix_slime.gen.layout - - """ - def run(_args) do - binding = [application_module: "ApplicationName"] - - extension = PhoenixSlime.ConfiguredExtension.file_extension() - - Mix.Phoenix.copy_from(slime_paths(), "priv/templates/phoenix.gen.layout.slime", binding, [ - {:eex, "app.html.eex", "web/templates/layout/app.html.#{extension}"} - ]) - - instructions = """ - - A new web/templates/layout/app.html.#{extension} file was generated. - """ - - Mix.shell().info(instructions) - end - - defp slime_paths do - [".", :phoenix_slime] - end -end diff --git a/lib/mix/tasks/phx.gen.layout.slime.ex b/lib/mix/tasks/phx.gen.layout.slime.ex index cb8f79c..a387c6c 100644 --- a/lib/mix/tasks/phx.gen.layout.slime.ex +++ b/lib/mix/tasks/phx.gen.layout.slime.ex @@ -16,7 +16,7 @@ defmodule Mix.Tasks.Phx.Gen.Layout.Slime do extension = PhoenixSlime.ConfiguredExtension.file_extension() - Mix.Phoenix.copy_from(slime_paths(), "priv/templates/phoenix.gen.layout.slime", binding, [ + Mix.Phoenix.copy_from(slime_paths(), "priv/templates/phx.gen.layout.slime", binding, [ {:eex, "app.html.eex", "#{web_prefix}/templates/layout/app.html.#{extension}"} ]) diff --git a/mix.exs b/mix.exs index d7ee3fb..8a3fe53 100644 --- a/mix.exs +++ b/mix.exs @@ -10,7 +10,8 @@ defmodule PhoenixSlime.Mixfile do description: "Phoenix Template Engine for Slim-like templates", elixir: "~> 1.4", package: package(), - version: @version] + version: @version + ] end def application do @@ -18,18 +19,22 @@ defmodule PhoenixSlime.Mixfile do end def deps do - [{:phoenix, "~> 1.3"}, - {:phoenix_html, "~> 2.10"}, - {:cowboy, "~> 1.0"}, - {:slime, "~> 1.0"}, - {:ex_doc, ">= 0.0.0", only: :dev}, - {:earmark, ">= 0.0.0", only: :dev}] + [ + {:phoenix, "~> 1.4"}, + {:phoenix_html, "~> 2.10"}, + {:jason, "~> 1.0", optional: true}, + {:slime, "~> 1.0"}, + {:ex_doc, ">= 0.0.0", only: :dev}, + {:earmark, ">= 0.0.0", only: :dev} + ] end defp package do - [maintainers: ["Sean Callan"], - files: ["lib", "priv", "mix.exs", "README*", "LICENSE*"], - licenses: ["MIT"], - links: %{github: "https://github.com/slime-lang/phoenix_slime"}] + [ + maintainers: ["Sean Callan"], + files: ["lib", "priv", "mix.exs", "README*", "LICENSE*"], + licenses: ["MIT"], + links: %{github: "https://github.com/slime-lang/phoenix_slime"} + ] end end diff --git a/mix.lock b/mix.lock index d0bb979..b81e676 100644 --- a/mix.lock +++ b/mix.lock @@ -1,14 +1,16 @@ -%{"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, optional: false]}]}, - "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], []}, - "earmark": {:hex, :earmark, "1.0.1", "2c2cd903bfdc3de3f189bd9a8d4569a075b88a8981ded9a0d95672f6e2b63141", [:mix], []}, - "ex_doc": {:hex, :ex_doc, "0.13.2", "1059a588d2ad3ffab25a0b85c58abf08e437d3e7a9124ac255e1d15cec68ab79", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]}, - "mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], []}, - "neotoma": {:hex, :neotoma, "1.7.3", "d8bd5404b73273989946e4f4f6d529e5c2088f5fa1ca790b4dbe81f4be408e61", [:rebar], []}, - "phoenix": {:hex, :phoenix, "1.3.0", "1c01124caa1b4a7af46f2050ff11b267baa3edb441b45dbf243e979cd4c5891b", [:mix], [{: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_html": {:hex, :phoenix_html, "2.10.3", "432dec9e04372eeb7a6dbf59a778cf43eb44518441932217371fa535f2bcfd80", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, - "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [:mix], [], "hexpm"}, - "plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [:mix], [{: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, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}, - "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], []}, - "slim_fast": {:hex, :slim_fast, "0.6.0"}, - "slime": {:hex, :slime, "1.0.0", "1566bf978cd7dc4043e1c6bd4beb03f94f586460920a1860e4cb30a5b6f3335d", [:mix], [{:neotoma, "~> 1.7", [hex: :neotoma, optional: false]}]}} +%{ + "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, + "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, + "makeup": {:hex, :makeup, "0.5.5", "9e08dfc45280c5684d771ad58159f718a7b5788596099bdfb0284597d368a882", [:mix], [{:nimble_parsec, "~> 0.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.10.0", "0f09c2ddf352887a956d84f8f7e702111122ca32fbbc84c2f0569b8b65cbf7fa", [:mix], [{:makeup, "~> 0.5.5", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, + "mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"}, + "neotoma": {:hex, :neotoma, "1.7.3", "d8bd5404b73273989946e4f4f6d529e5c2088f5fa1ca790b4dbe81f4be408e61", [:rebar], [], "hexpm"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"}, + "phoenix": {:hex, :phoenix, "1.4.0", "56fe9a809e0e735f3e3b9b31c1b749d4b436e466d8da627b8d82f90eaae714d2", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"}, + "phoenix_html": {:hex, :phoenix_html, "2.12.0", "1fb3c2e48b4b66d75564d8d63df6d53655469216d6b553e7e14ced2b46f97622", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"}, + "plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"}, + "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"}, + "slime": {:hex, :slime, "1.2.0", "d46ede53c96b743dfdd23821268dc9b01f04ffea65d9d57c4e3d9200b162df02", [:mix], [{:neotoma, "~> 1.7", [hex: :neotoma, repo: "hexpm", optional: false]}], "hexpm"}, +} diff --git a/priv/templates/phoenix.gen.html.slime/edit.html.eex b/priv/templates/phoenix.gen.html.slime/edit.html.eex deleted file mode 100644 index 551585c..0000000 --- a/priv/templates/phoenix.gen.html.slime/edit.html.eex +++ /dev/null @@ -1,5 +0,0 @@ -h2 Edit <%= template_singular %> - -= render "form.html", changeset: @changeset, action: <%= singular %>_path(@conn, :update, @<%= singular %>) - -= link "Back", to: <%= singular %>_path(@conn, :index) diff --git a/priv/templates/phoenix.gen.html.slime/form.html.eex b/priv/templates/phoenix.gen.html.slime/form.html.eex deleted file mode 100644 index 1ffc54d..0000000 --- a/priv/templates/phoenix.gen.html.slime/form.html.eex +++ /dev/null @@ -1,10 +0,0 @@ -= form_for @changeset, @action, fn f -> - = if @changeset.action do - .alert.alert-danger - p Oops, something went wrong! Please check the errors below. -<%= for {label, input, error} <- inputs, input do %> .form-group - <%= label %> - <%= input %> - <%= error %> -<% end %> .form-group - = submit "Submit", class: "btn btn-primary" diff --git a/priv/templates/phoenix.gen.html.slime/index.html.eex b/priv/templates/phoenix.gen.html.slime/index.html.eex deleted file mode 100644 index 0d8da97..0000000 --- a/priv/templates/phoenix.gen.html.slime/index.html.eex +++ /dev/null @@ -1,19 +0,0 @@ -h2 Listing <%= template_plural %> - -table.table - thead - tr -<%= for {k, _} <- attrs do %> th <%= Phoenix.Naming.humanize(Atom.to_string(k)) %> -<% end %> th - tbody - = for <%= singular %> <- @<%= plural %> do - tr -<%= for {k, _} <- attrs do %> td= <%= singular %>.<%= k %> -<% end %> td class="text-right" - = link "Show", to: <%= singular %>_path(@conn, :show, <%= singular %>), class: "btn btn-default btn-xs" - |   - = link "Edit", to: <%= singular %>_path(@conn, :edit, <%= singular %>), class: "btn btn-default btn-xs" - |   - = link "Delete", to: <%= singular %>_path(@conn, :delete, <%= singular %>), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" - -= link "New <%= template_singular %>", to: <%= singular %>_path(@conn, :new) diff --git a/priv/templates/phoenix.gen.html.slime/new.html.eex b/priv/templates/phoenix.gen.html.slime/new.html.eex deleted file mode 100644 index 3818d98..0000000 --- a/priv/templates/phoenix.gen.html.slime/new.html.eex +++ /dev/null @@ -1,5 +0,0 @@ -h2 New <%= template_singular %> - -= render "form.html", changeset: @changeset, action: <%= singular %>_path(@conn, :create) - -= link "Back", to: <%= singular %>_path(@conn, :index) diff --git a/priv/templates/phoenix.gen.html.slime/show.html.eex b/priv/templates/phoenix.gen.html.slime/show.html.eex deleted file mode 100644 index 8257def..0000000 --- a/priv/templates/phoenix.gen.html.slime/show.html.eex +++ /dev/null @@ -1,10 +0,0 @@ -h2 Show <%= template_singular %> - -ul -<%= for {k, _} <- attrs do %> li - strong <%= Phoenix.Naming.humanize(Atom.to_string(k)) %>:  - = @<%= singular %>.<%= k %> -<% end %> -= link "Edit", to: <%= singular %>_path(@conn, :edit, @<%= singular %>) -|   -= link "Back", to: <%= singular %>_path(@conn, :index) diff --git a/priv/templates/phx.gen.html/edit.html.eex b/priv/templates/phx.gen.html/edit.html.eex index 65e48d9..65a94b1 100644 --- a/priv/templates/phx.gen.html/edit.html.eex +++ b/priv/templates/phx.gen.html/edit.html.eex @@ -1,5 +1,5 @@ h2 Edit <%= schema.human_singular %> -= render "form.html", Map.put(assigns, :action, <%= schema.route_helper %>_path(@conn, :update, @<%= schema.singular %>)) += render "form.html", Map.put(assigns, :action, Routes.<%= schema.route_helper %>_path(@conn, :update, @<%= schema.singular %>)) -= link "Back", to: <%= schema.route_helper %>_path(@conn, :index) += link "Back", to: Routes.<%= schema.route_helper %>_path(@conn, :index) diff --git a/priv/templates/phx.gen.html/index.html.eex b/priv/templates/phx.gen.html/index.html.eex index b7bae0a..714fd95 100644 --- a/priv/templates/phx.gen.html/index.html.eex +++ b/priv/templates/phx.gen.html/index.html.eex @@ -10,10 +10,10 @@ table.table tr <%= for {k, _} <- schema.attrs do %> td= <%= schema.singular %>.<%= k %> <% end %> td class="text-right" - = link "Show", to: <%= schema.route_helper %>_path(@conn, :show, <%= schema.singular %>), class: "btn btn-default btn-xs" + = link "Show", to: Routes.<%= schema.route_helper %>_path(@conn, :show, <%= schema.singular %>), class: "btn btn-default btn-xs" |   - = link "Edit", to: <%= schema.route_helper %>_path(@conn, :edit, <%= schema.singular %>), class: "btn btn-default btn-xs" + = link "Edit", to: Routes.<%= schema.route_helper %>_path(@conn, :edit, <%= schema.singular %>), class: "btn btn-default btn-xs" |   - = link "Delete", to: <%= schema.route_helper %>_path(@conn, :delete, <%= schema.singular %>), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" + = link "Delete", to: Routes.<%= schema.route_helper %>_path(@conn, :delete, <%= schema.singular %>), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" -= link "New <%= schema.human_singular %>", to: <%= schema.route_helper %>_path(@conn, :new) += link "New <%= schema.human_singular %>", to: Routes.<%= schema.route_helper %>_path(@conn, :new) diff --git a/priv/templates/phx.gen.html/new.html.eex b/priv/templates/phx.gen.html/new.html.eex index f4332b2..b5863fc 100644 --- a/priv/templates/phx.gen.html/new.html.eex +++ b/priv/templates/phx.gen.html/new.html.eex @@ -1,5 +1,5 @@ h2 New <%= schema.human_singular %> -= render "form.html", Map.put(assigns, :action, <%= schema.singular %>_path(@conn, :create)) += render "form.html", Map.put(assigns, :action, Routes.<%= schema.singular %>_path(@conn, :create)) -= link "Back", to: <%= schema.route_helper %>_path(@conn, :index) += link "Back", to: Routes.<%= schema.route_helper %>_path(@conn, :index) diff --git a/priv/templates/phx.gen.html/show.html.eex b/priv/templates/phx.gen.html/show.html.eex index aae9bbc..a23ec56 100644 --- a/priv/templates/phx.gen.html/show.html.eex +++ b/priv/templates/phx.gen.html/show.html.eex @@ -5,6 +5,6 @@ ul strong <%= Phoenix.Naming.humanize(Atom.to_string(k)) %>:  = @<%= schema.singular %>.<%= k %> <% end %> -= link "Edit", to: <%= schema.route_helper %>_path(@conn, :edit, @<%= schema.singular %>) += link "Edit", to: Routes.<%= schema.route_helper %>_path(@conn, :edit, @<%= schema.singular %>) |   -= link "Back", to: <%= schema.route_helper %>_path(@conn, :index) += link "Back", to: Routes.<%= schema.route_helper %>_path(@conn, :index) diff --git a/priv/templates/phoenix.gen.layout.slime/app.html.eex b/priv/templates/phx.gen.layout.slime/app.html.eex similarity index 84% rename from priv/templates/phoenix.gen.layout.slime/app.html.eex rename to priv/templates/phx.gen.layout.slime/app.html.eex index 7112f4e..741af25 100644 --- a/priv/templates/phoenix.gen.layout.slime/app.html.eex +++ b/priv/templates/phx.gen.layout.slime/app.html.eex @@ -7,7 +7,7 @@ html lang="en" meta content="" name="description" meta content="" name="author" title Hello <%= application_module %>! - link rel="stylesheet" href="#{static_path(@conn, "/css/app.css")}" + link rel="stylesheet" href="#{Routes.static_path(@conn, "/css/app.css")}" body .container @@ -24,4 +24,4 @@ html lang="en" main role="main" = render @view_module, @view_template, assigns - script src="#{static_path(@conn, "/js/app.js")}" + script src="#{Routes.static_path(@conn, "/js/app.js")}" diff --git a/test/mix/mix_helper.exs b/test/mix/mix_helper.exs index b10fef6..a81bb5e 100644 --- a/test/mix/mix_helper.exs +++ b/test/mix/mix_helper.exs @@ -11,9 +11,9 @@ defmodule MixHelper do def in_tmp(which, function) do path = Path.join(tmp_path(), which) - File.rm_rf! path - File.mkdir_p! path - File.cd! path, function + File.rm_rf!(path) + File.mkdir_p!(path) + File.cd!(path, function) end def assert_file(file) do @@ -27,9 +27,11 @@ defmodule MixHelper do def assert_file(file, match) do cond do is_list(match) -> - assert_file file, &(Enum.each(match, fn(m) -> assert &1 =~ m end)) + assert_file(file, &Enum.each(match, fn m -> assert &1 =~ m end)) + is_binary(match) or Regex.regex?(match) -> - assert_file file, &(assert &1 =~ match) + assert_file(file, &assert(&1 =~ match)) + is_function(match, 1) -> assert_file(file) match.(File.read!(file)) @@ -39,6 +41,7 @@ defmodule MixHelper do def with_generator_env(new_env, fun) do old = Application.get_env(:phoenix, :generators) Application.put_env(:phoenix, :generators, new_env) + try do fun.() after diff --git a/test/mix/tasks/phoenix.gen.html.slime_test.exs b/test/mix/tasks/phoenix.gen.html.slime_test.exs deleted file mode 100644 index 225c32d..0000000 --- a/test/mix/tasks/phoenix.gen.html.slime_test.exs +++ /dev/null @@ -1,238 +0,0 @@ -Code.require_file "../mix_helper.exs", __DIR__ - -defmodule PhoenixSlime.DupHTMLController do -end - -defmodule PhoenixSlime.DupHTMLView do -end - -defmodule Mix.Tasks.Phoenix.Gen.Html.SlimeTest do - use ExUnit.Case - import MixHelper - - setup do - Mix.Task.clear - :ok - end - - test "generates html resource" do - in_tmp "generates html resource", fn -> - Mix.Tasks.Phoenix.Gen.Html.Slime.run ["user", "users", "name", "age:integer", "height:decimal", - "nicks:array:text", "famous:boolean", "born_at:naive_datetime", - "secret:uuid", "first_login:date", "alarm:time", - "address_id:references:addresses"] - - assert_file "web/models/user.ex" - assert_file "test/models/user_test.exs" - assert [_] = Path.wildcard("priv/repo/migrations/*_create_user.exs") - - assert_file "web/controllers/user_controller.ex", fn file -> - assert file =~ "defmodule PhoenixSlime.UserController" - assert file =~ "use PhoenixSlime.Web, :controller" - assert file =~ "Repo.get!" - end - - assert_file "web/views/user_view.ex", fn file -> - assert file =~ "defmodule PhoenixSlime.UserView do" - assert file =~ "use PhoenixSlime.Web, :view" - end - - assert_file "web/templates/user/edit.html.slime", fn file -> - assert file =~ "action: user_path(@conn, :update, @user)" - end - - assert_file "web/templates/user/form.html.slime", fn file -> - assert file =~ ~s(= text_input f, :name, class: "form-control") - assert file =~ ~s(= number_input f, :age, class: "form-control") - assert file =~ ~s(= number_input f, :height, step: "any", class: "form-control") - assert file =~ ~s(= checkbox f, :famous, class: "form-control") - assert file =~ ~s(= datetime_select f, :born_at, class: "form-control") - assert file =~ ~s(= text_input f, :secret, class: "form-control") - assert file =~ ~s(= label f, :name, class: "control-label") - assert file =~ ~s(= label f, :age, class: "control-label") - assert file =~ ~s(= label f, :height, class: "control-label") - assert file =~ ~s(= label f, :famous, class: "control-label") - assert file =~ ~s(= label f, :born_at, class: "control-label") - assert file =~ ~s(= label f, :secret, class: "control-label") - - refute file =~ ~s(= label f, :address_id) - refute file =~ ~s(= number_input f, :address_id) - refute file =~ ":nicks" - end - - assert_file "web/templates/user/index.html.slime", fn file -> - assert file =~ "th Name" - assert file =~ "= for user <- @users do" - assert file =~ "td= user.name" - end - - assert_file "web/templates/user/new.html.slime", fn file -> - assert file =~ "action: user_path(@conn, :create)" - end - - assert_file "web/templates/user/show.html.slime", fn file -> - assert file =~ "strong Name:" - assert file =~ "= @user.name" - end - - assert_file "test/controllers/user_controller_test.exs", fn file -> - assert file =~ "defmodule PhoenixSlime.UserControllerTest" - assert file =~ "use PhoenixSlime.ConnCase" - - assert file =~ ~S|@valid_attrs %{age: 42| - assert file =~ ~S|@invalid_attrs %{}| - refute file =~ ~S|address_id: nil| - - assert file =~ ~S|test "lists all entries on index"| - assert file =~ ~S|conn = get conn, user_path(conn, :index)| - assert file =~ ~S|assert html_response(conn, 200) =~ "Listing users"| - - assert file =~ ~S|test "renders form for new resources"| - assert file =~ ~S|conn = get conn, user_path(conn, :new)| - assert file =~ ~S|assert html_response(conn, 200) =~ "New user"| - - assert file =~ ~S|test "creates resource and redirects when data is valid"| - assert file =~ ~S|conn = post conn, user_path(conn, :create), user: @valid_attrs| - assert file =~ ~S|assert redirected_to(conn) == user_path(conn, :index)| - assert file =~ ~r/creates.*when data is valid.*?assert Repo\.get_by\(User, @valid_attrs\).*?end/s - - assert file =~ ~S|test "does not create resource and renders errors when data is invalid"| - assert file =~ ~S|conn = post conn, user_path(conn, :create), user: @invalid_attrs| - - assert file =~ ~S|test "shows chosen resource"| - assert file =~ ~S|user = Repo.insert! %User{}| - assert file =~ ~S|assert html_response(conn, 200) =~ "Show user"| - - assert file =~ ~S|test "renders form for editing chosen resource"| - assert file =~ ~S|assert html_response(conn, 200) =~ "Edit user"| - - assert file =~ ~S|test "updates chosen resource and redirects when data is valid"| - assert file =~ ~S|conn = put conn, user_path(conn, :update, user), user: @valid_attrs| - assert file =~ ~r/updates.*when data is valid.*?assert Repo\.get_by\(User, @valid_attrs\).*?end/s - - assert file =~ ~S|test "does not update chosen resource and renders errors when data is invalid"| - assert file =~ ~S|conn = put conn, user_path(conn, :update, user), user: @invalid_attrs| - - assert file =~ ~S|test "deletes chosen resource"| - assert file =~ ~S|conn = delete conn, user_path(conn, :delete, user)| - end - - assert_received {:mix_shell, :info, ["\nAdd the resource" <> _ = message]} - assert message =~ ~s(resources "/users", UserController) - end - end - - test "generates nested resource" do - in_tmp "generates nested resource", fn -> - Mix.Tasks.Phoenix.Gen.Html.Slime.run ["Admin.SuperUser", "super_users", "name:string"] - - assert_file "web/models/admin/super_user.ex" - assert [_] = Path.wildcard("priv/repo/migrations/*_create_admin_super_user.exs") - - assert_file "web/controllers/admin/super_user_controller.ex", fn file -> - assert file =~ "defmodule PhoenixSlime.Admin.SuperUserController" - assert file =~ "use PhoenixSlime.Web, :controller" - assert file =~ "Repo.get!" - end - - assert_file "web/views/admin/super_user_view.ex", fn file -> - assert file =~ "defmodule PhoenixSlime.Admin.SuperUserView do" - assert file =~ "use PhoenixSlime.Web, :view" - end - - assert_file "web/templates/admin/super_user/edit.html.slime", fn file -> - assert file =~ "h2 Edit super user" - assert file =~ "action: super_user_path(@conn, :update, @super_user)" - end - - assert_file "web/templates/admin/super_user/form.html.slime", fn file -> - assert file =~ ~s(= text_input f, :name, class: "form-control") - end - - assert_file "web/templates/admin/super_user/index.html.slime", fn file -> - assert file =~ "h2 Listing super users" - assert file =~ "th Name" - assert file =~ "= for super_user <- @super_users do" - end - - assert_file "web/templates/admin/super_user/new.html.slime", fn file -> - assert file =~ "h2 New super user" - assert file =~ "action: super_user_path(@conn, :create)" - end - - assert_file "web/templates/admin/super_user/show.html.slime", fn file -> - assert file =~ "h2 Show super user" - assert file =~ "strong Name:" - assert file =~ "= @super_user.name" - end - - assert_file "test/controllers/admin/super_user_controller_test.exs", fn file -> - assert file =~ ~S|assert html_response(conn, 200) =~ "Listing super users"| - assert file =~ ~S|assert html_response(conn, 200) =~ "New super user"| - assert file =~ ~S|assert html_response(conn, 200) =~ "Show super user"| - assert file =~ ~S|assert html_response(conn, 200) =~ "Edit super user"| - end - - assert_received {:mix_shell, :info, ["\nAdd the resource" <> _ = message]} - assert message =~ ~s(resources "/admin/super_users", Admin.SuperUserController) - end - end - - test "generates html resource without model" do - in_tmp "generates html resource without model", fn -> - Mix.Tasks.Phoenix.Gen.Html.Slime.run ["Admin.User", "users", "--no-model", "name:string"] - - refute File.exists? "web/models/admin/user.ex" - assert [] = Path.wildcard("priv/repo/migrations/*_create_admin_user.exs") - - assert_file "web/templates/admin/user/form.html.slime", fn file -> - refute file =~ ~s(--no-model) - end - end - end - - describe "when :use_slim_extension env is set to true" do - setup do - Application.put_env(:phoenix_slime, :use_slim_extension, true) - on_exit fn -> - Application.delete_env(:phoenix_slime, :use_slim_extension) - end - :ok - end - - test "generates files with .slim extension " do - in_tmp "generates .slim", fn -> - Mix.Tasks.Phoenix.Gen.Html.Slime.run ["User", "users"] - - assert File.exists? "web/templates/user/edit.html.slim" - assert File.exists? "web/templates/user/form.html.slim" - assert File.exists? "web/templates/user/index.html.slim" - assert File.exists? "web/templates/user/new.html.slim" - assert File.exists? "web/templates/user/show.html.slim" - end - end - end - - - test "plural can't contain a colon" do - assert_raise Mix.Error, fn -> - Mix.Tasks.Phoenix.Gen.Html.Slime.run ["Admin.User", "name:string", "foo:string"] - end - end - - test "plural can't have uppercased characters or camelized format" do - assert_raise Mix.Error, fn -> - Mix.Tasks.Phoenix.Gen.Html.Slime.run ["Admin.User", "Users", "foo:string"] - end - - assert_raise Mix.Error, fn -> - Mix.Tasks.Phoenix.Gen.Html.Slime.run ["Admin.User", "AdminUsers", "foo:string"] - end - end - - test "name is already defined" do - assert_raise Mix.Error, fn -> - Mix.Tasks.Phoenix.Gen.Html.Slime.run ["DupHTML", "duphtmls"] - end - end -end diff --git a/test/mix/tasks/phoenix.gen.layout.slime_test.exs b/test/mix/tasks/phoenix.gen.layout.slime_test.exs deleted file mode 100644 index 3a52cdf..0000000 --- a/test/mix/tasks/phoenix.gen.layout.slime_test.exs +++ /dev/null @@ -1,40 +0,0 @@ -Code.require_file "../mix_helper.exs", __DIR__ - -defmodule Mix.Tasks.Phoenix.Gen.Layout.SlimeTest do - use ExUnit.Case - import MixHelper - - setup do - Mix.Task.clear - :ok - end - - test "generates a slime layout file" do - in_tmp "generates slime layout file", fn -> - Mix.Tasks.Phoenix.Gen.Layout.Slime.run [] - - assert_file "web/templates/layout/app.html.slime", fn file -> - assert file =~ "p.alert.alert-info" - assert file =~ "p.alert.alert-danger" - end - - end - end - - describe "when :use_slim_extension env is set to true" do - setup do - Application.put_env(:phoenix_slime, :use_slim_extension, true) - on_exit fn -> - Application.delete_env(:phoenix_slime, :use_slim_extension) - end - :ok - end - - test "generates a file with .slim extension " do - in_tmp "generates .slim", fn -> - Mix.Tasks.Phoenix.Gen.Layout.Slime.run [] - assert File.exists? "web/templates/layout/app.html.slim" - end - end - end -end diff --git a/test/mix/tasks/phx.gen.html.slime_test.exs b/test/mix/tasks/phx.gen.html.slime_test.exs index ea4f622..b66726c 100644 --- a/test/mix/tasks/phx.gen.html.slime_test.exs +++ b/test/mix/tasks/phx.gen.html.slime_test.exs @@ -1,4 +1,4 @@ -Code.require_file "../mix_helper.exs", __DIR__ +Code.require_file("../mix_helper.exs", __DIR__) # defmodule PhoenixSlime.DupHTMLController do # end @@ -12,28 +12,26 @@ defmodule Mix.Tasks.Phx.Gen.Html.SlimeTest do alias Mix.Tasks.Phx.Gen setup do - Mix.Task.clear + Mix.Task.clear() :ok end test "generates html resource" do - in_tmp "generates html resource", fn -> - Gen.Html.Slime.run( - ~w(Accounts User users name age:integer height:decimal nicks:array:text + in_tmp("generates html resource", fn -> + Gen.Html.Slime.run(~w(Accounts User users name age:integer height:decimal nicks:array:text famous:boolean born_at:naive_datetime secret:uuid first_login:date - alarm:time address_id:references:addresses) - ) + alarm:time address_id:references:addresses)) - assert_file "lib/phoenix_slime/accounts/user.ex" - assert_file "lib/phoenix_slime/accounts/accounts.ex" - assert_file "test/phoenix_slime/accounts/accounts_test.exs" + assert_file("lib/phoenix_slime/accounts/user.ex") + assert_file("lib/phoenix_slime/accounts/accounts.ex") + assert_file("test/phoenix_slime/accounts/accounts_test.exs") assert [_] = Path.wildcard("priv/repo/migrations/*_create_users.exs") - assert_file "lib/phoenix_slime_web/templates/user/edit.html.slime", fn file -> - assert file =~ ":action, user_path(@conn, :update, @user)" - end + assert_file("lib/phoenix_slime_web/templates/user/edit.html.slime", fn file -> + assert file =~ ":action, Routes.user_path(@conn, :update, @user)" + end) - assert_file "lib/phoenix_slime_web/templates/user/form.html.slime", fn file -> + assert_file("lib/phoenix_slime_web/templates/user/form.html.slime", fn file -> assert file =~ ~s(= text_input f, :name, class: "form-control") assert file =~ ~s(= number_input f, :age, class: "form-control") assert file =~ ~s(= number_input f, :height, step: "any", class: "form-control") @@ -50,101 +48,102 @@ defmodule Mix.Tasks.Phx.Gen.Html.SlimeTest do refute file =~ ~s(= label f, :address_id) refute file =~ ~s(= number_input f, :address_id) refute file =~ ":nicks" - end + end) - assert_file "lib/phoenix_slime_web/templates/user/index.html.slime", fn file -> + assert_file("lib/phoenix_slime_web/templates/user/index.html.slime", fn file -> assert file =~ "th Name" assert file =~ "= for user <- @users do" assert file =~ "td= user.name" - end + end) - assert_file "lib/phoenix_slime_web/templates/user/new.html.slime", fn file -> - assert file =~ ":action, user_path(@conn, :create)" - end + assert_file("lib/phoenix_slime_web/templates/user/new.html.slime", fn file -> + assert file =~ ":action, Routes.user_path(@conn, :create)" + end) - assert_file "lib/phoenix_slime_web/templates/user/show.html.slime", fn file -> + assert_file("lib/phoenix_slime_web/templates/user/show.html.slime", fn file -> assert file =~ "strong Name:" assert file =~ "= @user.name" - end + end) - assert_file "test/phoenix_slime_web/controllers/user_controller_test.exs" + assert_file("test/phoenix_slime_web/controllers/user_controller_test.exs") assert_received {:mix_shell, :info, ["\nAdd the resource" <> _ = message]} assert message =~ ~s(resources "/users", UserController) - end + end) end test "with --web namespace generates namespaced web modules and directories" do - in_tmp "generates web resource", fn -> + in_tmp("generates web resource", fn -> Gen.Html.Slime.run(~w(Blog Post posts title:string --web Blog)) - assert_file "test/phoenix_slime_web/controllers/blog/post_controller_test.exs" - assert_file "lib/phoenix_slime_web/controllers/blog/post_controller.ex" + assert_file("test/phoenix_slime_web/controllers/blog/post_controller_test.exs") + assert_file("lib/phoenix_slime_web/controllers/blog/post_controller.ex") - assert_file "lib/phoenix_slime_web/templates/blog/post/form.html.slime" - assert_file "lib/phoenix_slime_web/templates/blog/post/edit.html.slime" - assert_file "lib/phoenix_slime_web/templates/blog/post/index.html.slime" - assert_file "lib/phoenix_slime_web/templates/blog/post/new.html.slime" - assert_file "lib/phoenix_slime_web/templates/blog/post/show.html.slime" + assert_file("lib/phoenix_slime_web/templates/blog/post/form.html.slime") + assert_file("lib/phoenix_slime_web/templates/blog/post/edit.html.slime") + assert_file("lib/phoenix_slime_web/templates/blog/post/index.html.slime") + assert_file("lib/phoenix_slime_web/templates/blog/post/new.html.slime") + assert_file("lib/phoenix_slime_web/templates/blog/post/show.html.slime") - assert_file "lib/phoenix_slime_web/views/blog/post_view.ex" - end + assert_file("lib/phoenix_slime_web/views/blog/post_view.ex") + end) end test "generates html resource without schema file" do - in_tmp "generates html resource without schema", fn -> - Gen.Html.Slime.run ~w(Admin User users --no-schema name:string) + in_tmp("generates html resource without schema", fn -> + Gen.Html.Slime.run(~w(Admin User users --no-schema name:string)) - refute_file "lib/phoenix_slime/admin/user.ex" + refute_file("lib/phoenix_slime/admin/user.ex") - assert_file "lib/phoenix_slime_web/templates/user/form.html.slime", fn file -> + assert_file("lib/phoenix_slime_web/templates/user/form.html.slime", fn file -> refute file =~ ~s(--no-schema) - end - end + end) + end) end describe "when :use_slim_extension env is set to true" do setup do Application.put_env(:phoenix_slime, :use_slim_extension, true) - on_exit fn -> + + on_exit(fn -> Application.delete_env(:phoenix_slime, :use_slim_extension) - end + end) + :ok end test "generates files with .slim extension " do - in_tmp "generates .slim", fn -> - Mix.Tasks.Phx.Gen.Html.Slime.run ~w(Admin User users) - - assert_file "lib/phoenix_slime_web/templates/user/edit.html.slim" - assert_file "lib/phoenix_slime_web/templates/user/form.html.slim" - assert_file "lib/phoenix_slime_web/templates/user/index.html.slim" - assert_file "lib/phoenix_slime_web/templates/user/new.html.slim" - assert_file "lib/phoenix_slime_web/templates/user/show.html.slim" - end + in_tmp("generates .slim", fn -> + Mix.Tasks.Phx.Gen.Html.Slime.run(~w(Admin User users)) + + assert_file("lib/phoenix_slime_web/templates/user/edit.html.slim") + assert_file("lib/phoenix_slime_web/templates/user/form.html.slim") + assert_file("lib/phoenix_slime_web/templates/user/index.html.slim") + assert_file("lib/phoenix_slime_web/templates/user/new.html.slim") + assert_file("lib/phoenix_slime_web/templates/user/show.html.slim") + end) end end - test "plural can't contain a colon" do assert_raise Mix.Error, fn -> - Mix.Tasks.Phx.Gen.Html.Slime.run ["Blog", "Post", "title:string", "content:string"] + Mix.Tasks.Phx.Gen.Html.Slime.run(["Blog", "Post", "title:string", "content:string"]) end end test "plural can't have uppercased characters or camelized format" do assert_raise Mix.Error, fn -> - Mix.Tasks.Phx.Gen.Html.Slime.run ["Blog", "User", "Users", "foo:string"] + Mix.Tasks.Phx.Gen.Html.Slime.run(["Blog", "User", "Users", "foo:string"]) end assert_raise Mix.Error, fn -> - Mix.Tasks.Phx.Gen.Html.Slime.run ["Admin", "User", "AdminUsers", "foo:string"] + Mix.Tasks.Phx.Gen.Html.Slime.run(["Admin", "User", "AdminUsers", "foo:string"]) end end test "name is already defined" do assert_raise Mix.Error, fn -> - Mix.Tasks.Phx.Gen.Html.Slime.run ["DupHTML", "duphtmls"] + Mix.Tasks.Phx.Gen.Html.Slime.run(["DupHTML", "duphtmls"]) end end end diff --git a/test/mix/tasks/phx.gen.layout.slime_test.exs b/test/mix/tasks/phx.gen.layout.slime_test.exs index 98cff5f..9661fd2 100644 --- a/test/mix/tasks/phx.gen.layout.slime_test.exs +++ b/test/mix/tasks/phx.gen.layout.slime_test.exs @@ -1,41 +1,42 @@ -Code.require_file "../mix_helper.exs", __DIR__ +Code.require_file("../mix_helper.exs", __DIR__) defmodule Mix.Tasks.Phx.Gen.Layout.SlimeTest do use ExUnit.Case import MixHelper setup do - Mix.Task.clear + Mix.Task.clear() :ok end test "generates a slime layout file" do - in_tmp "generates slime layout file", fn -> - Mix.Tasks.Phx.Gen.Layout.Slime.run [] + in_tmp("generates slime layout file", fn -> + Mix.Tasks.Phx.Gen.Layout.Slime.run([]) - assert_file "lib/phoenix_slime_web/templates/layout/app.html.slime", fn file -> + assert_file("lib/phoenix_slime_web/templates/layout/app.html.slime", fn file -> assert file =~ "Hello PhoenixSlime" assert file =~ "p.alert.alert-info" assert file =~ "p.alert.alert-danger" - end - - end + end) + end) end describe "when :use_slim_extension env is set to true" do setup do Application.put_env(:phoenix_slime, :use_slim_extension, true) - on_exit fn -> + + on_exit(fn -> Application.delete_env(:phoenix_slime, :use_slim_extension) - end + end) + :ok end test "generates a file with .slim extension " do - in_tmp "generates .slim", fn -> - Mix.Tasks.Phx.Gen.Layout.Slime.run [] - assert File.exists? "lib/phoenix_slime_web/templates/layout/app.html.slim" - end + in_tmp("generates .slim", fn -> + Mix.Tasks.Phx.Gen.Layout.Slime.run([]) + assert File.exists?("lib/phoenix_slime_web/templates/layout/app.html.slim") + end) end end end diff --git a/test/phoenix_slime_test.exs b/test/phoenix_slime_test.exs index 655261f..acd83b6 100644 --- a/test/phoenix_slime_test.exs +++ b/test/phoenix_slime_test.exs @@ -9,11 +9,14 @@ defmodule PhoenixSlimeTest do end test "render a slime template with layout" do - html = View.render(MyApp.PageView, "new.html", - message: "hi", - layout: {MyApp.PageView, "application.html"} - ) - assert html == {:safe, [[["" | ""], "" | "

New Template

"] | ""]} + html = + View.render(MyApp.PageView, "new.html", + message: "hi", + layout: {MyApp.PageView, "application.html"} + ) + + assert html == + {:safe, [[["" | ""], "" | "

New Template

"] | ""]} end test "render a slime template without layout" do