aantron / dream

Tidy, feature-complete Web framework
https://aantron.github.io/dream/
MIT License
1.58k stars 125 forks source link

how to apply ocamlformat #55

Open cdaringe opened 3 years ago

cdaringe commented 3 years ago

problem

dune build @fmt --watch yields

ocamlformat: ignoring "src/bin/server/bin.eml.ml" (syntax error)

when using eml

discussion

do you use ocamlformat? if so, how? perhaps https://dune.readthedocs.io/en/stable/dune-files.html#dialect is relevant?

aantron commented 3 years ago

Ah, this is indeed an oversight. I don't use OCamlFormat, as you can probably tell :)

The original intent was that as projects get more elaborate, the templates will get factored out into their own files, that are mostly HTML with only a bit of OCaml code. Those files shouldn't require formatting (at least by an OCaml formatter). They would be named like foo.eml.html to trigger HTML highlighting due to their mostly HTML content. I think that would bypass the OCamlFormat error.

Another option is to try refmt. Perhaps eml is similar enough to JSX. It might be awkward to set up and use for .eml.ml files, though.

Thanks for the link to (dialect ...). It looks almost useful for this, but:

It's likely possible to at least disable OCamlFormat on template files by either patching Dune, or by changing conventions on the Dream side.

tungd commented 3 years ago

This is not directly answer the question but I got away with this by having templates in a separate file, using the Reason syntax and TyXML JSX support.

As a side note, I'd love it if TyXML JSX would become the "endorsed" template solution replacing the current one. I do like the built-in template solution but I'd much prefer Reason/JSX for tooling reasons.

aantron commented 3 years ago

I think TyXML JSX (+ Melange) is basically the "endorsed" solution for Reason, and will be good for a large proportion of users. I have a TODO for making it more prominent in the README. But I don't want to offer it as the basic default, because it is Reason-only, it's an extra thing to learn, it's verbose in places, a bit non-obvious, it doesn't match JS JSX 100%, etc. So, I'd rather offer "plain, completely obvious HTML" for people that don't want to bother with JSX. But it's, of course, a great choice for people already using JSX or who absolutely need to use it in files that they need tooling support for, especially if they are also using it client-side.

@cdaringe You may want to see the TyXML JSX example, if you haven't already.

I also want to more greatly emphasize, in the README, how interchangeable everything in Dream is. And, indeed, it is correct to put "endorsed" in quotes, because Dream doesn't really "endorse" much :)

cdaringe commented 3 years ago

I did end up finding tyxml from your links! Was surprised that the jsx ppx was reason only, but the html ppx worked fine :)

thangngoc89 commented 3 years ago

@cdaringe that is because the JSX part is done by refmt (reason parser + printer). Tyxml has tyxml_ppx for ocaml syntax by the way

https://github.com/ocsigen/tyxml/tree/master/ppx