From 9278f7fb4e46a28c8c3fb7c85d25d536b359e5da Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Mon, 1 Jul 2019 22:48:51 -0400 Subject: [PATCH] Rename to Temple --- .gitignore | 2 +- README.md | 24 ++--- .../{dsl.gen.html.ex => temple.gen.html.ex} | 89 +++++++++++++------ ...dsl.gen.layout.ex => temple.gen.layout.ex} | 14 +-- lib/mix/tasks/update_mdn_docs.ex | 2 +- lib/{dsl.ex => temple.ex} | 32 +++---- lib/{dsl => temple}/engine.ex | 18 ++-- lib/{dsl => temple}/form.ex | 40 ++++----- lib/{dsl => temple}/link.ex | 14 +-- lib/{dsl => temple}/tags.ex | 30 +++---- lib/{dsl => temple}/utils.ex | 5 +- mix.exs | 12 +-- .../controller.ex | 0 .../controller_test.exs | 0 .../edit.html.exs | 0 .../form.html.exs | 0 .../index.html.exs | 0 .../new.html.exs | 0 .../show.html.exs | 0 .../{dsl.gen.html => temple.gen.html}/view.ex | 0 .../app.html.eex | 0 test/support/component.ex | 2 +- test/{dsl => temple}/form_test.exs | 20 ++--- test/{dsl => temple}/html_test.exs | 4 +- test/{dsl => temple}/link_test.exs | 4 +- test/{dsl => temple}/utils_test.exs | 6 +- test/{dsl_test.exs => temple_test.exs} | 4 +- 27 files changed, 177 insertions(+), 145 deletions(-) rename lib/mix/tasks/{dsl.gen.html.ex => temple.gen.html.ex} (76%) rename lib/mix/tasks/{dsl.gen.layout.ex => temple.gen.layout.ex} (59%) rename lib/{dsl.ex => temple.ex} (82%) rename lib/{dsl => temple}/engine.ex (79%) rename lib/{dsl => temple}/form.ex (85%) rename lib/{dsl => temple}/link.ex (75%) rename lib/{dsl => temple}/tags.ex (77%) rename lib/{dsl => temple}/utils.ex (89%) rename priv/templates/{dsl.gen.html => temple.gen.html}/controller.ex (100%) rename priv/templates/{dsl.gen.html => temple.gen.html}/controller_test.exs (100%) rename priv/templates/{dsl.gen.html => temple.gen.html}/edit.html.exs (100%) rename priv/templates/{dsl.gen.html => temple.gen.html}/form.html.exs (100%) rename priv/templates/{dsl.gen.html => temple.gen.html}/index.html.exs (100%) rename priv/templates/{dsl.gen.html => temple.gen.html}/new.html.exs (100%) rename priv/templates/{dsl.gen.html => temple.gen.html}/show.html.exs (100%) rename priv/templates/{dsl.gen.html => temple.gen.html}/view.ex (100%) rename priv/templates/{dsl.gen.layout => temple.gen.layout}/app.html.eex (100%) rename test/{dsl => temple}/form_test.exs (97%) rename test/{dsl => temple}/html_test.exs (99%) rename test/{dsl => temple}/link_test.exs (99%) rename test/{dsl => temple}/utils_test.exs (76%) rename test/{dsl_test.exs => temple_test.exs} (98%) diff --git a/.gitignore b/.gitignore index b03116d..0652411 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ erl_crash.dump *.ez # Ignore package tarball (built via "mix hex.build"). -dsl-*.tar +temple-*.tar /tmp/ diff --git a/README.md b/README.md index 5737ccc..e161ff4 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ -# Dsl +# Temple -[![Build Status](https://travis-ci.com/mhanberg/dsl.svg?branch=master)](https://travis-ci.com/mhanberg/dsl) +[![Build Status](https://travis-ci.com/mhanberg/temple.svg?branch=master)](https://travis-ci.com/mhanberg/temple) -Dsl is a DSL for writing HTML using Elixir. +Temple is a DSL for writing HTML using Elixir. -You're probably here because you want to use Dsl to write Phoenix templates, which is why Dsl includes a [Phoenix template engine](#phoenix-templates) and Dsl-compatible [Phoenix form helpers](#phoenixhtml). +You're probably here because you want to use Temple to write Phoenix templates, which is why Temple includes a [Phoenix template engine](#phoenix-templates) and Temple-compatible [Phoenix form helpers](#phoenixhtml). ## Installation If [available in Hex](https://hex.pm/docs/publish), the package can be installed -by adding `dsl` to your list of dependencies in `mix.exs`: +by adding `temple` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:dsl, "~> 0.1.0"} + {:temple, "~> 0.1.0"} ] end ``` @@ -22,7 +22,7 @@ end ## Usage ```elixir -use Dsl +use Temple htm do h2 "todos" @@ -53,7 +53,7 @@ end ### Components -Dsl provides an API for creating custom components that act as custom HTML elements. +Temple provides an API for creating custom components that act as custom HTML elements. These components can be given `props` that are available inside the component definition as module attributes. The contents of a components `do` block are available as a special `@children` attribute. @@ -75,9 +75,9 @@ end ### Phoenix.HTML -Dsl provides macros for working with the helpers provided by the [Phoenix.HTML](https://www.github.com/phoenixframework/phoenix_html) package. +Temple provides macros for working with the helpers provided by the [Phoenix.HTML](https://www.github.com/phoenixframework/phoenix_html) package. -Most of the macros are purely wrappers, while the semantics of some are changed to work with Dsl. +Most of the macros are purely wrappers, while the semantics of some are changed to work with Temple. ```elixir htm do @@ -93,13 +93,13 @@ Add the templating engine to your Phoenix configuration. ```elixir # config.exs -config :phoenix, :template_engines, exs: Dsl.Engine +config :phoenix, :template_engines, exs: Temple.Engine # your_app_web.ex def view do quote do # ... - use Dsl # Replaces the call to import Phoenix.HTML + use Temple # Replaces the call to import Phoenix.HTML end end ``` diff --git a/lib/mix/tasks/dsl.gen.html.ex b/lib/mix/tasks/temple.gen.html.ex similarity index 76% rename from lib/mix/tasks/dsl.gen.html.ex rename to lib/mix/tasks/temple.gen.html.ex index e99a58c..d511826 100644 --- a/lib/mix/tasks/dsl.gen.html.ex +++ b/lib/mix/tasks/temple.gen.html.ex @@ -1,10 +1,10 @@ -defmodule Mix.Tasks.Dsl.Gen.Html do - @shortdoc "Generates controller, views, and context for an HTML resource in Dsl" +defmodule Mix.Tasks.Temple.Gen.Html do + @shortdoc "Generates controller, views, and context for an HTML resource in Temple" @moduledoc """ - Generates controller, views, and context for an HTML resource Dsl. + Generates controller, views, and context for an HTML resource Temple. - mix dsl.gen.html Accounts User users name:string age:integer + mix temple.gen.html Accounts User users name:string age:integer The first argument is the context module followed by the schema module and its plural name (used as the schema table name). @@ -53,7 +53,7 @@ defmodule Mix.Tasks.Dsl.Gen.Html do You can customize the web module namespace by passing the `--web` flag with a module name, for example: - mix phx.gen.html.dsl Sales User users --web Sales + mix phx.gen.html.temple Sales User users --web Sales Which would generate a `lib/app_web/controllers/sales/user_controller.ex` and `lib/app_web/views/sales/user_view.ex`. @@ -71,7 +71,7 @@ defmodule Mix.Tasks.Dsl.Gen.Html do the plural name provided for the resource. To customize this value, a `--table` option may be provided. For example: - mix phx.gen.html.dsl Accounts User users --table cms_users + mix phx.gen.html.temple Accounts User users --table cms_users ## binary_id @@ -102,15 +102,15 @@ defmodule Mix.Tasks.Dsl.Gen.Html do @doc false def run(args) do - if Mix.Project.umbrella? do - Mix.raise "mix dsl.gen.html can only be run inside an application directory" + if Mix.Project.umbrella?() do + Mix.raise("mix temple.gen.html can only be run inside an application directory") end {context, schema} = Gen.Context.build(args) Gen.Context.prompt_for_code_injection(context) binding = [context: context, schema: schema, inputs: inputs(schema)] - paths = [".", :dsl] + paths = [".", :temple] prompt_for_conflicts(context) @@ -125,9 +125,11 @@ defmodule Mix.Tasks.Dsl.Gen.Html do |> Kernel.++(context_files(context)) |> Mix.Phoenix.prompt_for_conflicts() end + defp context_files(%Context{generate?: true} = context) do Gen.Context.files_to_be_generated(context) end + defp context_files(%Context{generate?: false}) do [] end @@ -139,48 +141,63 @@ defmodule Mix.Tasks.Dsl.Gen.Html do web_path = to_string(schema.web_path) [ - {:eex, "controller.ex", Path.join([web_prefix, "controllers", web_path, "#{schema.singular}_controller.ex"])}, - {:eex, "edit.html.exs", Path.join([web_prefix, "templates", web_path, schema.singular, "edit.html.exs"])}, - {:eex, "form.html.exs", Path.join([web_prefix, "templates", web_path, schema.singular, "form.html.exs"])}, - {:eex, "index.html.exs", Path.join([web_prefix, "templates", web_path, schema.singular, "index.html.exs"])}, - {:eex, "new.html.exs", Path.join([web_prefix, "templates", web_path, schema.singular, "new.html.exs"])}, - {:eex, "show.html.exs", Path.join([web_prefix, "templates", web_path, schema.singular, "show.html.exs"])}, + {:eex, "controller.ex", + Path.join([web_prefix, "controllers", web_path, "#{schema.singular}_controller.ex"])}, + {:eex, "edit.html.exs", + Path.join([web_prefix, "templates", web_path, schema.singular, "edit.html.exs"])}, + {:eex, "form.html.exs", + Path.join([web_prefix, "templates", web_path, schema.singular, "form.html.exs"])}, + {:eex, "index.html.exs", + Path.join([web_prefix, "templates", web_path, schema.singular, "index.html.exs"])}, + {:eex, "new.html.exs", + Path.join([web_prefix, "templates", web_path, schema.singular, "new.html.exs"])}, + {:eex, "show.html.exs", + Path.join([web_prefix, "templates", web_path, schema.singular, "show.html.exs"])}, {:eex, "view.ex", Path.join([web_prefix, "views", web_path, "#{schema.singular}_view.ex"])}, - {:eex, "controller_test.exs", Path.join([test_prefix, "controllers", web_path, "#{schema.singular}_controller_test.exs"])}, + {:eex, "controller_test.exs", + Path.join([test_prefix, "controllers", web_path, "#{schema.singular}_controller_test.exs"])} ] end @doc false def copy_new_files(%Context{} = context, paths, binding) do files = files_to_be_generated(context) - IO.inspect files, label: "files" + IO.inspect(files, label: "files") + + Mix.Phoenix.copy_from(paths, "priv/templates/temple.gen.html", binding, files) + + if context.generate?, + do: Gen.Context.copy_new_files(context, Mix.Phoenix.generator_paths(), binding) - Mix.Phoenix.copy_from(paths, "priv/templates/dsl.gen.html", binding, files) - if context.generate?, do: Gen.Context.copy_new_files(context, Mix.Phoenix.generator_paths(), binding) context end @doc false def print_shell_instructions(%Context{schema: schema, context_app: ctx_app} = context) do if schema.web_namespace do - Mix.shell.info """ + Mix.shell().info(""" - Add the resource to your #{schema.web_namespace} :browser scope in #{Mix.Phoenix.web_path(ctx_app)}/router.ex: + Add the resource to your #{schema.web_namespace} :browser scope in #{ + Mix.Phoenix.web_path(ctx_app) + }/router.ex: - scope "/#{schema.web_path}", #{inspect Module.concat(context.web_module, schema.web_namespace)}, as: :#{schema.web_path} do + scope "/#{schema.web_path}", #{ + inspect(Module.concat(context.web_module, schema.web_namespace)) + }, as: :#{schema.web_path} do pipe_through :browser ... - resources "/#{schema.plural}", #{inspect schema.alias}Controller + resources "/#{schema.plural}", #{inspect(schema.alias)}Controller end - """ + """) else - Mix.shell.info """ + Mix.shell().info(""" Add the resource to your browser scope in #{Mix.Phoenix.web_path(ctx_app)}/router.ex: - resources "/#{schema.plural}", #{inspect schema.alias}Controller - """ + resources "/#{schema.plural}", #{inspect(schema.alias)}Controller + """) end + if context.generate?, do: Gen.Context.print_shell_instructions(context) end @@ -188,29 +205,43 @@ defmodule Mix.Tasks.Dsl.Gen.Html do Enum.map(schema.attrs, fn {_, {:references, _}} -> {nil, nil, nil} + {key, :integer} -> {label(key), ~s(number_input form, #{inspect(key)}), error(key)} + {key, :float} -> {label(key), ~s(number_input form, #{inspect(key)}, step: "any"), error(key)} + {key, :decimal} -> {label(key), ~s(number_input form, #{inspect(key)}, step: "any"), error(key)} + {key, :boolean} -> {label(key), ~s(checkbox form, #{inspect(key)}), error(key)} + {key, :text} -> {label(key), ~s(textarea form, #{inspect(key)}), error(key)} + {key, :date} -> {label(key), ~s(date_select form, #{inspect(key)}), error(key)} + {key, :time} -> {label(key), ~s(time_select form, #{inspect(key)}), error(key)} + {key, :utc_datetime} -> {label(key), ~s(datetime_select form, #{inspect(key)}), error(key)} + {key, :naive_datetime} -> {label(key), ~s(datetime_select form, #{inspect(key)}), error(key)} + {key, {:array, :integer}} -> {label(key), ~s(multiple_select form, #{inspect(key)}, ["1": 1, "2": 2]), error(key)} + {key, {:array, _}} -> - {label(key), ~s(multiple_select form, #{inspect(key)}, ["Option 1": "option1", "Option 2": "option2"]), error(key)} - {key, _} -> + {label(key), + ~s(multiple_select form, #{inspect(key)}, ["Option 1": "option1", "Option 2": "option2"]), + error(key)} + + {key, _} -> {label(key), ~s(text_input form, #{inspect(key)}), error(key)} end) end diff --git a/lib/mix/tasks/dsl.gen.layout.ex b/lib/mix/tasks/temple.gen.layout.ex similarity index 59% rename from lib/mix/tasks/dsl.gen.layout.ex rename to lib/mix/tasks/temple.gen.layout.ex index 9fb2061..3646f52 100644 --- a/lib/mix/tasks/dsl.gen.layout.ex +++ b/lib/mix/tasks/temple.gen.layout.ex @@ -1,18 +1,18 @@ -defmodule Mix.Tasks.Dsl.Gen.Layout do +defmodule Mix.Tasks.Temple.Gen.Layout do use Mix.Task - @shortdoc "Generates a default Phoenix layout file in Dsl" + @shortdoc "Generates a default Phoenix layout file in Temple" @moduledoc """ - Generates a Phoenix layout file in Dsl. - mix dsl.gen.layout + Generates a Phoenix layout file in Temple. + mix temple.gen.layout """ def run(_args) do context_app = Mix.Phoenix.context_app() web_prefix = Mix.Phoenix.web_path(context_app) binding = [application_module: Mix.Phoenix.base()] - Mix.Phoenix.copy_from(dsl_paths(), "priv/templates/dsl.gen.layout", binding, [ + Mix.Phoenix.copy_from(temple_paths(), "priv/templates/temple.gen.layout", binding, [ {:eex, "app.html.eex", "#{web_prefix}/templates/layout/app.html.exs"} ]) @@ -23,7 +23,7 @@ defmodule Mix.Tasks.Dsl.Gen.Layout do Mix.shell().info(instructions) end - defp dsl_paths do - [".", :dsl] + defp temple_paths do + [".", :temple] end end diff --git a/lib/mix/tasks/update_mdn_docs.ex b/lib/mix/tasks/update_mdn_docs.ex index f99fadb..4b4d6c8 100644 --- a/lib/mix/tasks/update_mdn_docs.ex +++ b/lib/mix/tasks/update_mdn_docs.ex @@ -6,7 +6,7 @@ defmodule Mix.Tasks.UpdateMdnDocs do @shortdoc "Update the MDN documentation" def run(_) do - (Dsl.Tags.nonvoid_elements() ++ Dsl.Tags.void_elements()) + (Temple.Tags.nonvoid_elements() ++ Temple.Tags.void_elements()) |> Enum.map(fn el -> Task.async(fn -> el = to_string(el) diff --git a/lib/dsl.ex b/lib/temple.ex similarity index 82% rename from lib/dsl.ex rename to lib/temple.ex index 046b6f3..5dc1f16 100644 --- a/lib/dsl.ex +++ b/lib/temple.ex @@ -1,21 +1,21 @@ -defmodule Dsl do +defmodule Temple do @moduledoc """ - Documentation for Dsl. + Documentation for Temple. """ defmacro __using__(_) do quote do import unquote(__MODULE__) - import Dsl.Tags - import Dsl.Form - import Dsl.Link + import Temple.Tags + import Temple.Form + import Temple.Link end end @doc """ Creates a markup context. - All tags must be called inside of a `Dsl.htm/1` block. + All tags must be called inside of a `Temple.htm/1` block. Returns a safe result of the form `{:safe, result}` @@ -41,14 +41,14 @@ defmodule Dsl do import Phoenix.HTML.Link, except: [link: 1, link: 2] import Phoenix.HTML.Form, only: [] - Dsl.Utils.lexical_scope(fn -> - {:ok, var!(buff, Dsl.Tags)} = Dsl.Utils.start_buffer([]) + Temple.Utils.lexical_scope(fn -> + {:ok, var!(buff, Temple.Tags)} = Temple.Utils.start_buffer([]) unquote(block) - markup = Dsl.Utils.get_buffer(var!(buff, Dsl.Tags)) + markup = Temple.Utils.get_buffer(var!(buff, Temple.Tags)) - :ok = Dsl.Utils.stop_buffer(var!(buff, Dsl.Tags)) + :ok = Temple.Utils.stop_buffer(var!(buff, Temple.Tags)) markup |> Enum.reverse() |> Enum.join("") |> Phoenix.HTML.raw() end) @@ -70,8 +70,8 @@ defmodule Dsl do """ defmacro text(text) do quote do - Dsl.Utils.put_buffer( - var!(buff, Dsl.Tags), + Temple.Utils.put_buffer( + var!(buff, Temple.Tags), unquote(text) |> to_string |> Phoenix.HTML.html_escape() |> Phoenix.HTML.safe_to_string() ) end @@ -105,9 +105,9 @@ defmodule Dsl do """ defmacro partial(partial) do quote do - Dsl.Utils.put_buffer( - var!(buff, Dsl.Tags), - unquote(partial) |> Dsl.Utils.from_safe() + Temple.Utils.put_buffer( + var!(buff, Temple.Tags), + unquote(partial) |> Temple.Utils.from_safe() ) end end @@ -169,7 +169,7 @@ defmodule Dsl do outer = unquote(Macro.escape(block)) - |> Macro.prewalk(&Dsl.Utils.insert_props(&1, [{:children, inner} | props])) + |> Macro.prewalk(&Temple.Utils.insert_props(&1, [{:children, inner} | props])) name = unquote(name) diff --git a/lib/dsl/engine.ex b/lib/temple/engine.ex similarity index 79% rename from lib/dsl/engine.ex rename to lib/temple/engine.ex index 6bfafb2..05616b8 100644 --- a/lib/dsl/engine.ex +++ b/lib/temple/engine.ex @@ -1,31 +1,31 @@ -defmodule Dsl.Engine do +defmodule Temple.Engine do @behaviour Phoenix.Template.Engine @moduledoc """ - Dsl provides a templating engine for use in Phoenix web applications. + Temple provides a templating engine for use in Phoenix web applications. - You can configure your application to use Dsl templates by adding the following configuration. + You can configure your application to use Temple templates by adding the following configuration. ```elixir # config.exs - config :phoenix, :template_engines, exs: Dsl.Engine + config :phoenix, :template_engines, exs: Temple.Engine # your_app_web.ex def view do quote do # ... - use Dsl # Replaces the call to import Phoenix.HTML + use Temple # Replaces the call to import Phoenix.HTML end end ``` ## Usage - Dsl templates use the `.exs` extension, because they are written with pure Elixir! + Temple templates use the `.exs` extension, because they are written with pure Elixir! `assigns` (@conn, etc) are handled the same as normal `Phoenix.HTML.Engine` templates. - Note: The `Dsl.htm/1` macro is _not_ needed for Dsl templates due to the engine taking care of that for you. + Note: The `Temple.htm/1` macro is _not_ needed for Temple templates due to the engine taking care of that for you. ``` # app.html.exs @@ -76,7 +76,7 @@ defmodule Dsl.Engine do |> handle_assigns() quote do - use Dsl + use Temple htm do: unquote(template) end @@ -93,7 +93,7 @@ defmodule Dsl.Engine do :error -> raise ArgumentError, """ - assign @#{unquote(key)} not available in Dsl template. + assign @#{unquote(key)} not available in Temple template. Please make sure all proper assigns have been set. If this is a child template, ensure assigns are given explicitly by the parent template as they are not automatically forwarded. diff --git a/lib/dsl/form.ex b/lib/temple/form.ex similarity index 85% rename from lib/dsl/form.ex rename to lib/temple/form.ex index ab07978..f5bfa1d 100644 --- a/lib/dsl/form.ex +++ b/lib/temple/form.ex @@ -1,15 +1,15 @@ -defmodule Dsl.Form do +defmodule Temple.Form do @moduledoc """ - This modules wraps all of the functions from the `Phoenix.HTML.Form` module to make them compatible with with Dsl. + This modules wraps all of the functions from the `Phoenix.HTML.Form` module to make them compatible with with Temple. """ alias Phoenix.HTML - alias Dsl.Utils + alias Temple.Utils @doc """ Generates an empty form tag. - See `Dsl.Form.form_for/4` for more details + See `Temple.Form.form_for/4` for more details """ defmacro form_for(form_data, action) do quote do @@ -45,9 +45,9 @@ defmodule Dsl.Form do quote do var!(form) = HTML.Form.form_for(unquote_splicing([form_data, action, opts])) - Utils.put_buffer(var!(buff, Dsl.Tags), var!(form) |> HTML.Safe.to_iodata()) + Utils.put_buffer(var!(buff, Temple.Tags), var!(form) |> HTML.Safe.to_iodata()) _ = unquote(block) - Utils.put_buffer(var!(buff, Dsl.Tags), "") + Utils.put_buffer(var!(buff, Temple.Tags), "") end end @@ -84,7 +84,7 @@ defmodule Dsl.Form do {:safe, input} = apply(Phoenix.HTML.Form, unquote(helper), [unquote_splicing([form, field, opts])]) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end end @@ -96,7 +96,7 @@ defmodule Dsl.Form do quote do {:safe, input} = Phoenix.HTML.Form.reset(unquote_splicing([value, opts])) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -112,7 +112,7 @@ defmodule Dsl.Form do {:safe, input} = Phoenix.HTML.Form.submit(do: content) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -120,7 +120,7 @@ defmodule Dsl.Form do quote do {:safe, input} = Phoenix.HTML.Form.submit(unquote(value)) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -136,7 +136,7 @@ defmodule Dsl.Form do {:safe, input} = Phoenix.HTML.Form.submit(unquote(opts), do: content) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -144,7 +144,7 @@ defmodule Dsl.Form do quote do {:safe, input} = Phoenix.HTML.Form.submit(unquote_splicing([value, opts])) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -155,7 +155,7 @@ defmodule Dsl.Form do quote do {:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field])) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -171,7 +171,7 @@ defmodule Dsl.Form do {:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field]), do: content) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -179,7 +179,7 @@ defmodule Dsl.Form do quote do {:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field, text_or_opts])) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -195,7 +195,7 @@ defmodule Dsl.Form do {:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field, opts]), do: content) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -203,7 +203,7 @@ defmodule Dsl.Form do quote do {:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field, text, opts])) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -215,7 +215,7 @@ defmodule Dsl.Form do {:safe, input} = Phoenix.HTML.Form.multiple_select(unquote_splicing([form, field, options, attrs])) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -226,7 +226,7 @@ defmodule Dsl.Form do quote do {:safe, input} = Phoenix.HTML.Form.select(unquote_splicing([form, field, options, attrs])) - Utils.put_buffer(var!(buff, Dsl.Tags), input) + Utils.put_buffer(var!(buff, Temple.Tags), input) end end @@ -283,7 +283,7 @@ defmodule Dsl.Form do Enum.map(form.hidden, fn {k, v} -> Phoenix.HTML.Form.hidden_input(form, k, value: v) end) - |> Enum.each(&Utils.put_buffer(var!(buff, Dsl.Tags), &1)) + |> Enum.each(&Utils.put_buffer(var!(buff, Temple.Tags), &1)) var!(inner_form) = form diff --git a/lib/dsl/link.ex b/lib/temple/link.ex similarity index 75% rename from lib/dsl/link.ex rename to lib/temple/link.ex index a34a399..0edf835 100644 --- a/lib/dsl/link.ex +++ b/lib/temple/link.ex @@ -1,9 +1,9 @@ -defmodule Dsl.Link do +defmodule Temple.Link do alias Phoenix.HTML - alias Dsl.Utils + alias Temple.Utils @moduledoc """ - This modules wraps all of the functions from the `Phoenix.HTML.Link` module to make them compatible with with Dsl. + This modules wraps all of the functions from the `Phoenix.HTML.Link` module to make them compatible with with Temple. """ @doc """ @@ -18,7 +18,7 @@ defmodule Dsl.Link do {:safe, link} = HTML.Link.link(content, unquote(opts)) - Utils.put_buffer(var!(buff, Dsl.Tags), link) + Utils.put_buffer(var!(buff, Temple.Tags), link) end end @@ -26,7 +26,7 @@ defmodule Dsl.Link do quote do {:safe, link} = HTML.Link.link(unquote_splicing([content, opts])) - Utils.put_buffer(var!(buff, Dsl.Tags), link) + Utils.put_buffer(var!(buff, Temple.Tags), link) end end @@ -42,7 +42,7 @@ defmodule Dsl.Link do {:safe, link} = HTML.Link.button(content, unquote(opts)) - Utils.put_buffer(var!(buff, Dsl.Tags), link) + Utils.put_buffer(var!(buff, Temple.Tags), link) end end @@ -50,7 +50,7 @@ defmodule Dsl.Link do quote do {:safe, link} = HTML.Link.button(unquote_splicing([content, opts])) - Utils.put_buffer(var!(buff, Dsl.Tags), link) + Utils.put_buffer(var!(buff, Temple.Tags), link) end end end diff --git a/lib/dsl/tags.ex b/lib/temple/tags.ex similarity index 77% rename from lib/dsl/tags.ex rename to lib/temple/tags.ex index 8587ba0..7b4465a 100644 --- a/lib/dsl/tags.ex +++ b/lib/temple/tags.ex @@ -1,6 +1,6 @@ -defmodule Dsl.Tags do +defmodule Temple.Tags do @moduledoc """ - The `Dsl.Tags` module defines macros for all HTML5 compliant elements. + The `Temple.Tags` module defines macros for all HTML5 compliant elements. ## Attributes @@ -91,8 +91,8 @@ defmodule Dsl.Tags do el = unquote(el) quote do - Dsl.Utils.put_open_tag(var!(buff, Dsl.Tags), unquote(el), []) - Dsl.Utils.put_close_tag(var!(buff, Dsl.Tags), unquote(el)) + Temple.Utils.put_open_tag(var!(buff, Temple.Tags), unquote(el), []) + Temple.Utils.put_close_tag(var!(buff, Temple.Tags), unquote(el)) end end @@ -102,9 +102,9 @@ defmodule Dsl.Tags do el = unquote(el) quote do - Dsl.Utils.put_open_tag(var!(buff, Dsl.Tags), unquote(el), []) + Temple.Utils.put_open_tag(var!(buff, Temple.Tags), unquote(el), []) _ = unquote(inner) - Dsl.Utils.put_close_tag(var!(buff, Dsl.Tags), unquote(el)) + Temple.Utils.put_close_tag(var!(buff, Temple.Tags), unquote(el)) end end @@ -112,8 +112,8 @@ defmodule Dsl.Tags do el = unquote(el) quote do - Dsl.Utils.put_open_tag(var!(buff, Dsl.Tags), unquote(el), unquote(attrs_or_content)) - Dsl.Utils.put_close_tag(var!(buff, Dsl.Tags), unquote(el)) + Temple.Utils.put_open_tag(var!(buff, Temple.Tags), unquote(el), unquote(attrs_or_content)) + Temple.Utils.put_close_tag(var!(buff, Temple.Tags), unquote(el)) end end @@ -123,9 +123,9 @@ defmodule Dsl.Tags do el = unquote(el) quote do - Dsl.Utils.put_open_tag(var!(buff, Dsl.Tags), unquote_splicing([el, attrs])) + Temple.Utils.put_open_tag(var!(buff, Temple.Tags), unquote_splicing([el, attrs])) _ = unquote(inner) - Dsl.Utils.put_close_tag(var!(buff, Dsl.Tags), unquote(el)) + Temple.Utils.put_close_tag(var!(buff, Temple.Tags), unquote(el)) end end @@ -133,9 +133,9 @@ defmodule Dsl.Tags do el = unquote(el) quote do - Dsl.Utils.put_open_tag(var!(buff, Dsl.Tags), unquote_splicing([el, attrs])) + Temple.Utils.put_open_tag(var!(buff, Temple.Tags), unquote_splicing([el, attrs])) text unquote(content) - Dsl.Utils.put_close_tag(var!(buff, Dsl.Tags), unquote(el)) + Temple.Utils.put_close_tag(var!(buff, Temple.Tags), unquote(el)) end end end @@ -153,9 +153,9 @@ defmodule Dsl.Tags do quote do attrs = unquote(attrs) - Dsl.Utils.put_buffer( - var!(buff, Dsl.Tags), - "<#{unquote(el)}#{Dsl.Utils.compile_attrs(attrs)}>" + Temple.Utils.put_buffer( + var!(buff, Temple.Tags), + "<#{unquote(el)}#{Temple.Utils.compile_attrs(attrs)}>" ) end end diff --git a/lib/dsl/utils.ex b/lib/temple/utils.ex similarity index 89% rename from lib/dsl/utils.ex rename to lib/temple/utils.ex index 5edce7a..7d0638c 100644 --- a/lib/dsl/utils.ex +++ b/lib/temple/utils.ex @@ -1,11 +1,12 @@ -defmodule Dsl.Utils do +defmodule Temple.Utils do @moduledoc false def put_open_tag(buff, el, attrs) when is_list(attrs) do put_buffer(buff, "<#{el}#{compile_attrs(attrs)}>") end - def put_open_tag(buff, el, content) when is_binary(content) or is_number(content) or is_atom(content) do + def put_open_tag(buff, el, content) + when is_binary(content) or is_number(content) or is_atom(content) do put_buffer(buff, "<#{el}>") put_buffer(buff, content) end diff --git a/mix.exs b/mix.exs index 24b909b..fbb2819 100644 --- a/mix.exs +++ b/mix.exs @@ -1,19 +1,19 @@ -defmodule Dsl.MixProject do +defmodule Temple.MixProject do use Mix.Project def project do [ - app: :dsl, - name: "Dsl", + app: :temple, + name: "Temple", version: "0.1.0", elixirc_paths: elixirc_paths(Mix.env()), elixir: "~> 1.7", start_permanent: Mix.env() == :prod, deps: deps(), aliases: aliases(), - source_url: "https://github.com/mhanberg/dsl", + source_url: "https://github.com/mhanberg/temple", docs: [ - main: "Dsl", + main: "Temple", extras: ["README.md"], deps: [ phoenix_html: "https://hexdocs.pm/phoenix_html/" @@ -33,7 +33,7 @@ defmodule Dsl.MixProject do extra_applications: [:logger] ] end - + defp aliases do [ docs: ["update_mdn_docs", "docs"] diff --git a/priv/templates/dsl.gen.html/controller.ex b/priv/templates/temple.gen.html/controller.ex similarity index 100% rename from priv/templates/dsl.gen.html/controller.ex rename to priv/templates/temple.gen.html/controller.ex diff --git a/priv/templates/dsl.gen.html/controller_test.exs b/priv/templates/temple.gen.html/controller_test.exs similarity index 100% rename from priv/templates/dsl.gen.html/controller_test.exs rename to priv/templates/temple.gen.html/controller_test.exs diff --git a/priv/templates/dsl.gen.html/edit.html.exs b/priv/templates/temple.gen.html/edit.html.exs similarity index 100% rename from priv/templates/dsl.gen.html/edit.html.exs rename to priv/templates/temple.gen.html/edit.html.exs diff --git a/priv/templates/dsl.gen.html/form.html.exs b/priv/templates/temple.gen.html/form.html.exs similarity index 100% rename from priv/templates/dsl.gen.html/form.html.exs rename to priv/templates/temple.gen.html/form.html.exs diff --git a/priv/templates/dsl.gen.html/index.html.exs b/priv/templates/temple.gen.html/index.html.exs similarity index 100% rename from priv/templates/dsl.gen.html/index.html.exs rename to priv/templates/temple.gen.html/index.html.exs diff --git a/priv/templates/dsl.gen.html/new.html.exs b/priv/templates/temple.gen.html/new.html.exs similarity index 100% rename from priv/templates/dsl.gen.html/new.html.exs rename to priv/templates/temple.gen.html/new.html.exs diff --git a/priv/templates/dsl.gen.html/show.html.exs b/priv/templates/temple.gen.html/show.html.exs similarity index 100% rename from priv/templates/dsl.gen.html/show.html.exs rename to priv/templates/temple.gen.html/show.html.exs diff --git a/priv/templates/dsl.gen.html/view.ex b/priv/templates/temple.gen.html/view.ex similarity index 100% rename from priv/templates/dsl.gen.html/view.ex rename to priv/templates/temple.gen.html/view.ex diff --git a/priv/templates/dsl.gen.layout/app.html.eex b/priv/templates/temple.gen.layout/app.html.eex similarity index 100% rename from priv/templates/dsl.gen.layout/app.html.eex rename to priv/templates/temple.gen.layout/app.html.eex diff --git a/test/support/component.ex b/test/support/component.ex index 080da29..f8e592b 100644 --- a/test/support/component.ex +++ b/test/support/component.ex @@ -1,5 +1,5 @@ defmodule Component do - import Dsl + import Temple defcomponent :flex do div(class: "flex") diff --git a/test/dsl/form_test.exs b/test/temple/form_test.exs similarity index 97% rename from test/dsl/form_test.exs rename to test/temple/form_test.exs index 5e7dfef..1022128 100644 --- a/test/dsl/form_test.exs +++ b/test/temple/form_test.exs @@ -1,6 +1,6 @@ -defmodule Dsl.FormTest do +defmodule Temple.FormTest do use ExUnit.Case, async: true - use Dsl + use Temple describe "form_for" do test "returns a form tag" do @@ -469,10 +469,10 @@ defmodule Dsl.FormTest do submit("Submit") end - assert String.starts_with? result, ~s{} + assert String.ends_with?(result, ~s{}) end test "generates a submit/2 input that takes opts and a block" do @@ -510,11 +510,11 @@ defmodule Dsl.FormTest do end end - assert String.starts_with? result, ~s{} + assert String.ends_with?(result, ~s{}) end test "generates a phx_label/2 tag" do diff --git a/test/dsl/html_test.exs b/test/temple/html_test.exs similarity index 99% rename from test/dsl/html_test.exs rename to test/temple/html_test.exs index 7d022cc..6d4b4e7 100644 --- a/test/dsl/html_test.exs +++ b/test/temple/html_test.exs @@ -1,6 +1,6 @@ -defmodule Dsl.HtmlTest do +defmodule Temple.HtmlTest do use ExUnit.Case, async: true - use Dsl + use Temple describe "non-void elements" do test "renders two divs" do diff --git a/test/dsl/link_test.exs b/test/temple/link_test.exs similarity index 99% rename from test/dsl/link_test.exs rename to test/temple/link_test.exs index c9c8214..a0fd155 100644 --- a/test/dsl/link_test.exs +++ b/test/temple/link_test.exs @@ -1,6 +1,6 @@ -defmodule Dsl.LinkTest do +defmodule Temple.LinkTest do use ExUnit.Case, async: true - use Dsl + use Temple describe "phx_link" do test "emits a link" do diff --git a/test/dsl/utils_test.exs b/test/temple/utils_test.exs similarity index 76% rename from test/dsl/utils_test.exs rename to test/temple/utils_test.exs index 39160d9..b47d991 100644 --- a/test/dsl/utils_test.exs +++ b/test/temple/utils_test.exs @@ -1,4 +1,4 @@ -defmodule Dsl.UtilsTest do +defmodule Temple.UtilsTest do use ExUnit.Case, async: true describe "from_safe/1" do @@ -6,7 +6,7 @@ defmodule Dsl.UtilsTest do expected = "I am safe!" partial = {:safe, expected} - result = Dsl.Utils.from_safe(partial) + result = Temple.Utils.from_safe(partial) assert result == expected end @@ -15,7 +15,7 @@ defmodule Dsl.UtilsTest do expected = "I am <safe>!" partial = "I am !" - result = Dsl.Utils.from_safe(partial) + result = Temple.Utils.from_safe(partial) assert result == expected end diff --git a/test/dsl_test.exs b/test/temple_test.exs similarity index 98% rename from test/dsl_test.exs rename to test/temple_test.exs index c36c4f3..4886a73 100644 --- a/test/dsl_test.exs +++ b/test/temple_test.exs @@ -1,6 +1,6 @@ -defmodule DslTest do +defmodule TempleTest do use ExUnit.Case, async: true - use Dsl + use Temple describe "custom component" do test "defines a basic component" do