Commit graph

29 commits

Author SHA1 Message Date
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
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
f942817994
Utilize the EEx Engine instead of creating an EEx string (#177) 2022-04-19 23:56:46 -04:00
Mitchell Hanberg
c965048f40
Better whitespace handling and control (#145)
* Fine tune whitespace

The EEx outut now emits more human-readable and predictable formatting.
This includes proper indenting, at least for each "root" template.

* Internal whitespace control

You can now use a bang version of any nonvoid tag to emit the markup
witout the internal whitespace. This means that there will not be a
newline emitted after the opening tag and before the closing tag.
2021-08-29 17:45:07 -04:00
Mitchell Hanberg
d9f00e5147
Class object syntax (#140)
* Class object syntax

Allows for conditionally setting classes on an element.

* Docs for class bindings
2021-06-27 12:04:19 -04:00
Mitchell Hanberg
9d05f74cdf
Properly emit boolean attributes (#139)
* Update some docs

* Properly emit boolean attributes.

* Account for quoted literals when compiling attributes

* Update changelog
2021-06-26 21:47:21 -04:00
Mitchell Hanberg
b2bd06d037 Add some docs 2021-05-13 21:28:15 -04:00
Mitchell Hanberg
5150a93e38 emit live view compatible component and slot markup
- requires the development branch of live_view currently, if you are
  going to be using live view

ci

Docs

Raise minimum elixir version to 1.9

There is some bug in EEx that was fixed in 1.9 and I can't be bothered
to make it backwards compatible with the bug.

ugh

Remove commented out line
2021-05-13 00:21:43 -04:00
Mitchell Hanberg
074241be4e Rename Temple.EEx to Temple.Generator 2021-04-11 17:27:02 -04:00
Mitchell Hanberg
41f9b94d0f Hook the AST generation in to the temple macros
- Removes the old way
- Removes the ability to compact an element
2021-04-09 00:16:30 -04:00
Mitchell Hanberg
358b5ea4cc Start porting parsers to use AST 2021-04-09 00:16:30 -04:00
Mitchell Hanberg
ced2f6ab66 feat: New Component API 2021-01-02 13:22:03 -05:00
Mitchell Hanberg
59e64dce3b Parser abstraction
This implements a Temple.Parser behavior. This contracts requires a
`applicable/1` and `run/2` functions to be defined.

`applicable/1` is passed the unparsed AST, and returns true or false
as to whether this parser module should be run.

`run/2` is passed the unparsed AST as well as the buffer. It should add
parsed markup to the buffer.

The function either returns `:ok` if the AST is done, or
`{:component_applied, ast}`. If the latter is returned, the parser pass
starts over with the return ast.
2020-07-23 20:59:10 -04:00
Mitchell Hanberg
f8f1ec623f Plugin architecture for parsers 2020-07-15 22:32:27 -04:00
Mitchell Hanberg
33c95186fb
Compile to EEx (#80)
Code is gross
2020-06-16 15:28:21 -04:00
Mitchell Hanberg
1093a4d602 Rename props to assigns
This helps stay consistent with the Phoenix nomenclature.
2020-04-14 10:40:01 -04:00
zimt28
fa41e73bb0 Add @props access to components (#66)
* Add @props access to components

* Document `@props` assign
2020-04-14 10:40:00 -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
74e7f3a25e defelement macro
- add location: :keep to all calls to quote
2019-08-20 23:13:10 -04:00
Mitchell Hanberg
eb0fde6e83
Don't recursively call generated component macros (#12)
Recursively calling the macros works fine if you `import` the whole
module wherever you are using your components, but not if you `require`
the module.

This is because importing brings in the all the macros into the callers
namespace, which allows them to be called just by the macro name. When
you `require` the module, it will look for the generated 2-arity macro
in the callers namespace, which probably doesn't exist.

We get around this by not recursively calling them and avoiding the
problem all togther. A few utility functions solves the original issue
of wanting to DRY the file.
2019-08-10 01:09:24 -04:00
Mitchell Hanberg
0521aa2aad Escape content passed to single arity tags 2019-08-07 21:08:16 -04:00
Mitchell Hanberg
c91d742ba7 Explicitly import Temple instead of using __MODULE__ 2019-07-12 15:46:45 -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
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
Renamed from lib/dsl.ex (Browse further)