Skip to content
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

Embedded syntax #98

Closed
coder543 opened this issue Jan 11, 2018 · 3 comments
Closed

Embedded syntax #98

coder543 opened this issue Jan 11, 2018 · 3 comments

Comments

@coder543
Copy link

coder543 commented Jan 11, 2018

I did some experimentation tonight, and it seems entirely possible to have the different attributes support nice-looking simple things, in addition to complex expressions.

Currently, there is code like:

<div class="view",>
    <input class="toggle", type="checkbox", checked=is_complete, onclick=move|_| Msg::Toggle(idx), />
</div>

My testing shows it is possible to extend the macro in such a way that you can have:

<div class="view">
    <input class="toggle" type="checkbox" checked=is_complete onclick=move|_| Msg::Toggle(idx), />
</div>

The key to making this work is, unfortunately, duplication.

Instead of:

($stack:ident (checked = $kind:expr, $($tail:tt)*)) => {
    $crate::macros::set_checked(&mut $stack, $kind);
    html_impl! { $stack ($($tail)*) }
};

you can do something similar to:

($stack:ident (checked = $kind:expr, $($tail:tt)*)) => {
    $crate::macros::set_checked(&mut $stack, $kind);
    html_impl! { $stack ($($tail)*) }
};
($stack:ident (checked = $kind:tt $($tail:tt)*)) => {
    $crate::macros::set_checked(&mut $stack, $kind);
    html_impl! { $stack ($($tail)*) }
};

This way, users are able to either place a single token, like a string literal or a variable name, or they can place a full expression ended with a comma.

If this is something you're interested in, I can try to make the concept happen at full-scale at some point. I put in a couple of hours tonight, but I just reset my changes because I'm too tired. I also wonder if the macro might be generalized better, to reduce code duplication throughout the macro, and to make it more robust... less prone to errors that seem temperamental.

@machineloop
Copy link
Contributor

Good points @coder543! I agree, making it possible to paste HTML into the macro would be ideal from a front-end perspective. Often time I'll have static HTML that I use to start creating components, so going through and adding commas after every attribute has been a painpoint.

@therustmonk
Copy link
Member

@coder543 Thank you for the good idea! I will try it.

@jstarry
Copy link
Member

jstarry commented Jul 28, 2019

This is fixed in 0.7

@jstarry jstarry closed this as completed Jul 28, 2019
teymour-aldridge referenced this issue in teymour-aldridge/yew Jul 8, 2020
* Point to master branch for examples

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>
Co-authored-by: Justin Starry <justin.m.starry@gmail.com>
jstarry added a commit to jstarry/yew that referenced this issue Jul 10, 2020
* Point to master branch for examples

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>
Co-authored-by: Justin Starry <justin.m.starry@gmail.com>
jstarry added a commit that referenced this issue Jul 10, 2020
* GitBook: [master] 2 pages modified

* Added code examples for the router docs. (#67)

* GitBook: [master] 3 pages modified

* GitBook: [master] one page modified

* Update the sample doc app to use wasm-pack (#75)

* Update the sample doc app to use wasm-pack

According to the rest of the documentation, wasm-pack and web-sys are
the recommended tool to use. However, the sample app documents the usage
of cargo-web and stdweb.

The command lines are taken from the example folder of yew.

* Some grammar fixes

* Use cargo miniserve instead of python to server the files

* Add wasm-bindgen dependency

* Fixed bad link to build script for wasm-bindgen/cargo-web (#81)

* Fixed bad link to build script for wasm-bindgen/cargo-web

* yewstack/docs#81 Updated link for cargo-web

* Update miniserve cargo install command (#88)

* create as lib right away (#93)

* updated (#92)

* GitBook: [master] 29 pages modified

* update the docs to specify that local agents do not incur serialization overhead (#89)

* Add a note telling how to bypass the recursion limit of the html! macro. (#94)

* Add a note telling how to bypass the recursion limit of the html! macro.

* Update src/concepts/html/README.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Update src/concepts/html/README.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>
Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* Add latest Stack Overflow survey results (#95)

* Mention prop_or macro (#97)

* Mention prop_or macro

* Fix the prop_or vs prop_or_else mixup

* Update src/concepts/components/properties.md

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* Fix a typo. (#102)

* Point to master branch for examples (#98)

* Point to master branch for examples

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>
Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* Add code of conduct to documentation as well. (#104)

* Added "" for the version at line 25 (#107)

* Added "" for the version at line 25

* Update src/getting-started/starter-templates.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>
Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Removed periods and fixed spelling mistakes (#103)

* Added period to description

* Fixed the spelling of " Arguabley" to "Arguably"

* Update README.md

* Added period to description

* Added period to description

* Grammar and spelling correction

added period to description, fixed spelling of "encouter" to "encounter"

* Added period to description

* Added period to description

* Grammar and spelling

Added period to description, fixed spelling of "accross" to "across"

* Added period to description

* Added period to description

* Fixed spelling of "aggresive" to "aggressive"

* Removed period from description

* Update optimizations.md

* Removed period from description

* Removed period from description

* Removed period from description

* Removed period from description

* Removed period from description

* Removed period from description

* Removed period from description

* Removed period from description

* Removed period from description

* Removed period from description

* Removed period from description

* Update src/concepts/html/README.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>
Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Shorten line lengths. (#106)

* Shortens line lengths (to ~100 characters max per line).
 * A few stylistic improvements
 * Corrects a couple of typos
 * Fixes a few grammar errors

Co-authored-by: Justin Starry <justin.starry@icloud.com>

* bumping up the yew version in Cargo.toml (#107) (#109)

* bumping up the yew version in Cargo.toml (#107)

* bumping up the yew version for stdweb

* bumping up the yew version of ConsoleService link

* bumping up the yew version

* Update src/more/debugging.md

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* Add #[derive(Clone)] in examples (#111)

* Add #[derive(Clone)] in examples

Closes #110

* Add backticks to rust elements

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Another backtics

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Fix typo (#112)

* GitBook: [master] 29 pages modified

* Fix spellcheck

* Remove duplicate code of conduct

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>
Co-authored-by: Franck Royer <royer.franck@gmail.com>
Co-authored-by: Eamon Caton <etcaton@gmail.com>
Co-authored-by: David Poggi <drpoggi@users.noreply.github.com>
Co-authored-by: Stephan Dilly <dilly.stephan@gmail.com>
Co-authored-by: 洪慈吟 <lili668668@gmail.com>
Co-authored-by: Michal Kawalec <michal@monad.cat>
Co-authored-by: codec-abc <viot.camille@outlook.com>
Co-authored-by: Anthony Morris <anthony@amorrissound.com>
Co-authored-by: Günter Zöchbauer <guenter@gzoechbauer.com>
Co-authored-by: Darren Meehan <Darrenmeehan@users.noreply.github.com>
Co-authored-by: Nougator <37145431+nougator@users.noreply.github.com>
Co-authored-by: Dirk Puge <67125647+dirkpuge@users.noreply.github.com>
Co-authored-by: hituzi no sippo <43565959+hituzi-no-sippo@users.noreply.github.com>
Co-authored-by: Mingun <Alexander_Sergey@mail.ru>
Co-authored-by: FIGBERT <figbert@figbert.com>
jstarry added a commit that referenced this issue Jul 10, 2020
* Point to master branch for examples

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>
Co-authored-by: Justin Starry <justin.m.starry@gmail.com>
jstarry added a commit that referenced this issue Aug 16, 2020
* Point to master branch for examples

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>

* Update src/getting-started/examples.md

Co-authored-by: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com>
Co-authored-by: Justin Starry <justin.m.starry@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants