-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add command line argument for generating reason #150
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
248ce41
Add command line argument for generating reason
outkine bc162ac
Improve compliancy with example dir naming scheme
outkine b0951e2
Add links between the two syntax versions of the example
outkine 6063c19
Match based on filename when argument is absent
outkine 8980ee0
Rename --syntax-reason to --emit-reason
outkine 41fcc14
Clean up r-template-files
outkine cfb04ad
Remove package.json
outkine ec5f3c4
Refactor types
outkine 1870920
Fix argument help spacing
outkine File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# `r-template-files` | ||
|
||
<br> | ||
|
||
While templates can be written with other code in `.re` files, they can also | ||
live in their own source files. This can be useful as templates become larger, | ||
or when you have many templates. | ||
|
||
If your template file is mostly HTML, you can give it a name like | ||
`template.eml.html`, to trigger HTML syntax highlighting by your editor. | ||
Additionally, if you are using `ocamlformat`, the `.html` extension will | ||
prevent errors that come from `ocamlformat` attempting to format the syntax of | ||
the template. | ||
|
||
This example does just that. It splits the code of the basic template example, | ||
[**r-template**](../r-template#files), into two files. The first is the | ||
template, in | ||
[`template.eml.html`](https://github.com/aantron/dream/blob/master/example/r-template-files/template.eml.html): | ||
|
||
```html | ||
let render = param => { | ||
<html> | ||
<body> | ||
<h1>The URL parameter was <%s param %>!</h1> | ||
</body> | ||
</html> | ||
aantron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
``` | ||
|
||
After preprocessing by the templater, this file becomes `template.ml`, so it | ||
defines a module `Template`, containing a function `Template.render`. We call | ||
this function from the main server in | ||
[`server.ml`](https://github.com/aantron/dream/blob/master/example/w-template-files/server.ml): | ||
|
||
```reason | ||
let () = | ||
Dream.run @@ | ||
Dream.logger @@ | ||
Dream.router([ | ||
Dream.get("/:word", request => | ||
Dream.param("word", request) |> Template.render |> Dream.html | ||
), | ||
]) @@ | ||
Dream.not_found; | ||
``` | ||
|
||
<pre><code><b>$ cd example/r-template-files</b> | ||
<b>$ npm install esy && npx esy</b> | ||
<b>$ npx esy start</b></code></pre> | ||
|
||
<br> | ||
|
||
**See also:** | ||
|
||
- [**r-template**](../r-template#files) for comments on the | ||
[`dune` file](https://github.com/aantron/dream/blob/master/example/w-template-files/dune). | ||
- [**7-template**](../7-template#files) for comments on [security | ||
information](https://github.com/aantron/dream/tree/master/example/7-template#security). | ||
- [**w-template-files**](../w-template-files) for the OCaml version of this example. | ||
|
||
<br> | ||
|
||
[Up to the example index](../#examples) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(executable | ||
(name server) | ||
(libraries dream)) | ||
|
||
(rule | ||
(targets template.re) | ||
(deps template.eml.html) | ||
(action (run dream_eml %{deps} --workspace %{workspace_root} --emit-reason))) | ||
|
||
(data_only_dirs _esy esy.lock lib node_modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(lang dune 2.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"dependencies": { | ||
"@opam/dream": "1.0.0~alpha2", | ||
"@opam/dune": "^2.0", | ||
"ocaml": "4.12.x" | ||
}, | ||
"devDependencies": { | ||
"@opam/ocaml-lsp-server": "*", | ||
"@opam/ocamlfind-secondary": "*" | ||
}, | ||
"resolutions": { | ||
"@opam/conf-libev": "esy-packages/libev:package.json#0b5eb6685b688649045aceac55dc559f6f21b829" | ||
}, | ||
"scripts": { | ||
"start": "dune exec --root . ./server.exe" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
let () = | ||
Dream.run @@ | ||
Dream.logger @@ | ||
Dream.router([ | ||
Dream.get("/:word", request => | ||
Dream.param("word", request) |> Template.render |> Dream.html | ||
), | ||
]) @@ | ||
Dream.not_found; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
let render = param => { | ||
<html> | ||
<body> | ||
<h1>The URL parameter was <%s param %>!</h1> | ||
</body> | ||
</html> | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason users will typically use
refmt
rather thanocamlformat
, and I haven't directly tested what will happen if you applyrefmt
to aneml
file, or what it looks like in an editor.