This repository has been archived by the owner on Jul 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Improve html docs #100
Open
zoechi
wants to merge
12
commits into
yewstack:master
Choose a base branch
from
zoechi:improve_html_docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Improve html docs #100
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f668fa6
Extend html! docs a bit
zoechi 543b186
Extend html! docs a bit
zoechi ca3a5cf
Update according to the suggestions
zoechi 9196862
Add link from properties to components where its shown how to pass th…
zoechi 905b7a9
Update src/concepts/html/README.md
zoechi 70ba8a6
Update src/concepts/html/README.md
zoechi 494bce8
Update src/concepts/html/README.md
zoechi 220f324
Apply the PR suggestions
zoechi 4484dba
Merge branch 'improve_html_docs' of github.com:zoechi/docs into impro…
zoechi 6be5c81
Add bullet about upper/lowercase distinction for tag and component
zoechi f2eea56
Improve links
zoechi 907779d
Using short names for link references seems better than numbers
zoechi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2,17 +2,28 @@ | |||||||
description: The procedural macro for generating HTML and SVG | ||||||||
--- | ||||||||
|
||||||||
# Using html! | ||||||||
# Using [`html!`][yew_macro_html] | ||||||||
|
||||||||
The `html!` macro allows you to write HTML and SVG code declaratively. It is similar to JSX \(a Javascript extension which allows you to write HTML code inside of Javascript\). | ||||||||
The [`html!`][1] macro allows you to write HTML and SVG code declaratively. It is similar to JSX \(a Javascript extension which allows you to write HTML code inside of Javascript\). | ||||||||
|
||||||||
**Important notes** | ||||||||
|
||||||||
1. The `html!` macro only accepts one root html node \(you can counteract this by [using fragments or iterators](lists.md)\) | ||||||||
2. An empty `html! {}` invocation is valid and will not render anything | ||||||||
3. Literals must always be quoted and wrapped in braces: `html! { "Hello, World" }` | ||||||||
|
||||||||
- The [`html!`][yew_macro_html] macro only accepts one root HTML node (you can overcome this by [using fragments or iterators](lists.md)) | ||||||||
- An empty `html! {}` invocation is valid and will not render anything. | ||||||||
- Literals inside of tags must always be quoted and wrapped with braces (this is different to attribute values - see below) | ||||||||
* `html! { "Hello, World" }` | ||||||||
* `html! { <div>{ "Hell, World" }</div> }` | ||||||||
* `html! { <div>{ String::from("foo") + "bar" }</div>` | ||||||||
- Quoted attribute values are taken literally. The value is set at compile-time and does not change at run-time. | ||||||||
* `html! { <div> id="bar"</div> }` | ||||||||
- Unquoted attribute values are interpreted as expressions and therefore have to be valid Rust expressions. | ||||||||
* `let foo = "bar"; html! { <div id=foo></div> }` | ||||||||
* `html! { <div id=String::from("foo") + "bar"></div> }` | ||||||||
- HTML tags names need to start with a lowercase letter. Besides that every valid HTML tag name is allowed. If the tag name starts with an uppercase letter it is interpreted as component name and attributes are passed as component properties. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
{% hint style="info" %} | ||||||||
The `html!` macro can reach easily the default recursion limit of the compiler. It is advised to bump its value if you encouter compilation errors. Use an attribute like `#![recursion_limit="1024"]` to bypass the problem. See the [official documentation](https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute) and [this Stack Overflow question](https://stackoverflow.com/questions/27454761/what-is-a-crate-attribute-and-where-do-i-add-it) for details. | ||||||||
The [`html!`][yew_macro_html] macro can reach easily the default recursion limit of the compiler. It is advised to bump its value if you encouter compilation errors. Use an attribute like `#![recursion_limit="1024"]` to bypass the problem. See the [official documentation][rust_recursion_limit] and [this Stack Overflow question][so_crate_attr] for details. | ||||||||
{% endhint %} | ||||||||
|
||||||||
{% page-ref page="lists.md" %} | ||||||||
|
@@ -22,3 +33,7 @@ The `html!` macro can reach easily the default recursion limit of the compiler. | |||||||
{% page-ref page="literals-and-expressions.md" %} | ||||||||
|
||||||||
{% page-ref page="components.md" %} | ||||||||
|
||||||||
[yew_macro_html]: https://docs.rs/yew/latest/yew/macro.html.html | ||||||||
[rust_recursion_limit]: https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute | ||||||||
[so_crate_attr]: https://stackoverflow.com/questions/27454761/what-is-a-crate-attribute-and-where-do-i-add-it |
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.
This is a bit confusing because literals are also expressions. I'd prefer if we left these notes out