Rename to Temple
This commit is contained in:
parent
dbf8dce765
commit
9278f7fb4e
27 changed files with 177 additions and 145 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -20,7 +20,7 @@ erl_crash.dump
|
|||
*.ez
|
||||
|
||||
# Ignore package tarball (built via "mix hex.build").
|
||||
dsl-*.tar
|
||||
temple-*.tar
|
||||
|
||||
/tmp/
|
||||
|
||||
|
|
24
README.md
24
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
|
||||
```
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
@ -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.
|
|
@ -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), "</form>")
|
||||
Utils.put_buffer(var!(buff, Temple.Tags), "</form>")
|
||||
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
|
||||
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
10
mix.exs
10
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/"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
defmodule Component do
|
||||
import Dsl
|
||||
import Temple
|
||||
|
||||
defcomponent :flex do
|
||||
div(class: "flex")
|
||||
|
|
|
@ -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{<button}
|
||||
assert String.starts_with?(result, ~s{<button})
|
||||
assert result =~ ~s{type="submit}
|
||||
assert result =~ ~s{Submit}
|
||||
assert String.ends_with? result, ~s{</button>}
|
||||
assert String.ends_with?(result, ~s{</button>})
|
||||
end
|
||||
|
||||
test "generates a submit/1 input that takes a block" do
|
||||
|
@ -483,10 +483,10 @@ defmodule Dsl.FormTest do
|
|||
end
|
||||
end
|
||||
|
||||
assert String.starts_with? result, ~s{<button}
|
||||
assert String.starts_with?(result, ~s{<button})
|
||||
assert result =~ ~s{type="submit}
|
||||
assert result =~ ~s{Submit}
|
||||
assert String.ends_with? result, ~s{</button>}
|
||||
assert String.ends_with?(result, ~s{</button>})
|
||||
end
|
||||
|
||||
test "generates a submit/2 input that takes text and opts" do
|
||||
|
@ -495,11 +495,11 @@ defmodule Dsl.FormTest do
|
|||
submit("Submit", class: "btn")
|
||||
end
|
||||
|
||||
assert String.starts_with? result, ~s{<button}
|
||||
assert String.starts_with?(result, ~s{<button})
|
||||
assert result =~ ~s{type="submit}
|
||||
assert result =~ ~s{class="btn"}
|
||||
assert result =~ ~s{Submit}
|
||||
assert String.ends_with? result, ~s{</button>}
|
||||
assert String.ends_with?(result, ~s{</button>})
|
||||
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{<button}
|
||||
assert String.starts_with?(result, ~s{<button})
|
||||
assert result =~ ~s{type="submit}
|
||||
assert result =~ ~s{class="btn"}
|
||||
assert result =~ ~s{Submit}
|
||||
assert String.ends_with? result, ~s{</button>}
|
||||
assert String.ends_with?(result, ~s{</button>})
|
||||
end
|
||||
|
||||
test "generates a phx_label/2 tag" do
|
|
@ -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
|
|
@ -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
|
|
@ -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 <safe>!"
|
||||
|
||||
result = Dsl.Utils.from_safe(partial)
|
||||
result = Temple.Utils.from_safe(partial)
|
||||
|
||||
assert result == expected
|
||||
end
|
|
@ -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
|
Reference in a new issue