Commit graph

24 commits

Author SHA1 Message Date
FloatingGhost d1db62ef58 Merge remote-tracking branch 'upstream/main' 2023-08-06 18:29:06 +01:00
FloatingGhost 1b1585657f fix tests 2023-08-06 18:12:51 +01:00
Mitchell Hanberg dc57221bc9
feat!: configure runtime attributes function (#202) 2023-06-12 23:38:16 -04:00
Mitchell Hanberg 07c82e21d3
Dynamic Attributes (#190)
* Move directories for ast tests to match convention

* feat!: Rename `:let` to `:let!`

We use the "bang" style as the reserved keyword to differentiate it from
other possible attributes.

* feat: use Phoenix.HTML as the default engine

I am choosing to leverage this library in order to quickly get dynamic
attributes (see #183) up and running.

This also ensures that folks who wish to use Temple outside of a Phoenix
project with get some nice HTML functions as well as properly escaped
HTML out of the box.

This can be made optional if Temple becomes decoupled from the render
and it including HTML specific packages becomes a strange.

* feat: Allow user to make their own Component module

The component module is essentially to defer compiling functions that the
user might not need. The component, render_slot, and inner_block functions
are only mean to be used when there isn't another implementation.

In the case of a LiveView application, LiveView is providing the
component runtime implementation. This was causing some compile time
warnings for temple, because it was using the LiveView engine at compile
time (for Temple, not the user's application) and LiveView hadn't been
compiled or loaded.

So, now we defer this to the user to make their own module and import it
where necessary.

* feat: Pass dynamic attributes with the :rest! attribute

The :rest! attribute can be used to pass in a dynamic list of attributes
to be mixed into the static ones at runtime.

Since this cannot be properly escaped by any engine, we have to mark it
as safe and then allow the function to escape it for us. I decided to
leverage the `attributes_escape/1` function from `phoenix_html`. There
isn't really any point in making my own version of this or vendoring it.

Now you can also pass a variable as the attributes as well if you only
want to pass through attributes from a calling component.

The :rest! attribute also works with components, allowing you to pass
a dynamic list of args into them.

Fixes #183

* Move test components to their own file.

* docs(components): Update documentation on Temple.Components

* docs(guides): Mention attributes_escape/1 function in the guides

* chore(test): Move helper to it's own module

* feat: rest! support for slots

* docs(guides): Dynamic attributes

* ci: downgrade runs-on to support OTP 23
2023-01-21 06:44:29 -05:00
Mitchell Hanberg f4ce790411
fix: runtime boolean attributes (#188)
Closes #187
2022-11-11 22:28:05 -05:00
Mitchell Hanberg db231e7b6b
Align component model with HEEx/Surface (#182)
* Align component model with HEEx/Surface

This change aligns the component model with HEEx/Surface. This shoudl
allow one to interop components created in any syntax with any other
syntax.

The advantage of this is folks can utilize component packages created
using a different syntax.

This includes several enhancements and breaking changes, please see the changelog and the migration guide for further details.

Closes #130
2022-10-12 09:17:23 -04:00
Mitchell Hanberg 99cbb42962
SVG (#181)
This basically just adds svg elements as void and nonvoid element
aliases and it works, will test on a real proejct before releasing the
next release.

Also, fixed the weird behaviour problem by defining types for each of the ast
nodes and then referencing those types when defining the ast type.

Unclear why this works, but I imagine it has to do with the types not
being a big part of the compilation process or something.

This also uses the typed_struct library to do so. Seems pretty slick and
does what it claims it does.
2022-09-19 20:35:45 -04:00
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 33c95186fb
Compile to EEx (#80)
Code is gross
2020-06-16 15:28:21 -04:00
Mitchell Hanberg 3993c798c0 Join markup with a new line
Text nodes separated by new lines still show whitespace when rendered,
so we should maintain user specified new lines.

Closes #59
Closes #60
2020-04-14 10:40:05 -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 ac56c3cc81 Improve tests for submit, phx_button, and phx_label 2019-08-27 21:57:41 -04:00
Shritesh dbb26a6d58 Fix phx_link, phx_button, submit, phx_label markup (#20)
The tests for phx_link were not testing the correct behavior, which is how this slipped by.
2019-08-27 21:51:10 -04:00
Mitchell Hanberg 74e7f3a25e defelement macro
- add location: :keep to all calls to quote
2019-08-20 23:13:10 -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
AJ Harrington f3aabf8f59 Updated html macro to put a <!DOCTYPE html> before the <html /> tag (#18)
Removed html from the list of nonvoid tags.  Implemented specifically
so the doctype declaration can be put in.  Not sure if this or adding
an if block to check the tag was a better solution.

Added tests for the html macro to the tests since it would no longer
show up in nonvoid_elements list.

mix test passes
2019-08-19 19:53:17 -04:00
Shritesh Bhattarai 43f10cd0de Add radio_button (#14) 2019-08-13 11:04:14 -04:00
Mitchell Hanberg 0521aa2aad Escape content passed to single arity tags 2019-08-07 21:08:16 -04:00
Mitchell Hanberg 7ad4b0e941 Rename Temple.htm to Temple.temple 2019-07-08 22:29:41 -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 eabe9cdd9b Fix collision of Temple.textarea and Phoenix.HTML.Form.textarea 2019-07-04 11:21:54 -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 9278f7fb4e Rename to Temple 2019-07-01 22:48:51 -04:00