Commit graph

20 commits

Author SHA1 Message Date
Mitchell Hanberg 2f042506b6
feat: Mix task to convert HTML into Temple (#180) 2022-09-11 22:39:31 -04:00
Mitchell Hanberg f942817994
Utilize the EEx Engine instead of creating an EEx string (#177) 2022-04-19 23:56:46 -04:00
Mitchell Hanberg 1a5837d1b7 Components API
Components work very similarly to how they worked before, but with a few
differences.

To define a component, you can create a file in your configured temple
components directory, which defaults to `lib/components`. You would
probably want ot change that to be `lib/my_app_web/components` if you
are building a phoenix app.

This file should be of the `.exs` extension, and contain any temple
compatible code.

You can then use this component in any other temple template.

For example, if I were to define a `flex` component, I would create a
file called `lib/my_app_web/components/flex.exs`, with the following
contents.

```elixir
div class: "flex #{@temple[:class]}", id: @id do
  @children
end
```

And we could use the component like so

```elixir
flex class: "justify-between items-center", id: "arnold" do
  div do: "Hi"
  div do: "I'm"
  div do: "Arnold"
  div do: "Schwarzenegger"
end
```

We've demonstated several features to components in this example.

We can pass assigns to our component, and access them just like we would
in a normal phoenix template. If they don't match up with any assigns we
passed to our component, they will be rendered as-is, and will become a
normal Phoenix assign.

You can also access a special `@temple` assign. This allows you do
optionally pass an assign, and not have the `@my_assign` pass through.
If you didn't pass it to your component, it will evaluate to nil.

The block passed to your component can be accessed as `@children`. This
allows your components to wrap a body of markup from the call site.

In order for components to trigger a recompile when they are changed,
you can call `use Temple.Recompiler` in your `lib/my_app_web.ex` file,
in the `view`, `live_view`, and `live_component` functions

```elixir
def view do
  quote do
    # ...
    use Temple.Recompiler
    # ...
  end
end
```
2020-07-15 22:32:27 -04:00
Mitchell Hanberg 4498eabedb Context/LiveView generator 2020-06-30 20:43:04 -04:00
Mitchell Hanberg 33c95186fb
Compile to EEx (#80)
Code is gross
2020-06-16 15:28:21 -04:00
Mitchell Hanberg 916a9469d6 Remove mdn docs
They became broken at some point, and are probably not too useful
anyway. We can bring them back in the future.
2020-04-14 10:39:58 -04:00
Adam Rutkowski 3e3f4480fa Ensure optional Phoenix is optional (#39) 2020-01-07 23:44:39 -05:00
Shritesh d1fceaf75f Don't depend on floki in prod (#28)
* Set @preferred_cli_env for Convert Task to :dev

* Set floki dep to :dev and :test, bump nimble_parsec
2019-09-25 15:16:56 -04:00
Mitchell Hanberg 5acd6fc079
Svg module (#25)
* Temple.Svg

- scopes update_mdn_task to the temple namespace
- introduces new temple.convert mix task to convert plain HTML and SVG to
  Temple syntax

* Rename Temple.Tags to Temple.Html

* Remove hackney

I'm not sure why it was even in there ¯\_(ツ)_/¯

* Update floki

* Document temple.convert in README
2019-09-13 21:36:16 -04:00
Mitchell Hanberg b0a7f9da11 Extract helper module for creating elements
Also removes illegal `html` macros, which allows use to only define one
clause and remove some tests.
2019-08-20 21:01:07 -04:00
Mitchell Hanberg d210d3bff5 Extract safe result from hidden fields within inputs_for/4
Also switches to using `with` instead of `lexical_scoping` because it is
more idiomatic.
2019-07-07 22:26:32 -04:00
Mitchell Hanberg 2929e6c7c3 Remove IO.inspect 2019-07-05 22:36:59 -04:00
Mitchell Hanberg 8daf85fdb3 Allow defcomponent to work with runtime values for assigns
Also allows tags and defcomponents to accept maps in addition to keyword
lists
2019-07-04 00:16:29 -04:00
Mitchell Hanberg cf0707f8aa Fix mdn docs 2019-07-03 21:42:30 -04:00
Mitchell Hanberg 9278f7fb4e Rename to Temple 2019-07-01 22:48:51 -04:00
Mitchell Hanberg dbf8dce765 Phoenix generators for layout and html resource 2019-07-01 22:14:32 -04:00
Mitchell Hanberg fb5147ff97 Improve doc generation
- Downloads all the mdn documentation in parallel
- Enables the `--silent` flag for curl
- Aliases the docs mix task to run update_mdn_docs first
2019-06-30 21:59:38 -04:00
Mitchell Hanberg 6b55fc7665 Implement remaining from helpers 2019-06-01 00:02:49 -04:00
Mitchell Hanberg 71e6c91c8f Extract Form module and rename Html module to Tags 2019-05-10 15:56:09 -04:00
Mitchell Hanberg db17577bb5 Document void and nonvoid element macros
The mix task will fetch the element documentation from MDN for each
element and include that in the documentation.

The main documentation for these macros will be in the moduledoc
2019-05-08 22:09:14 -04:00