Replace the input! macro with an Input builder #646

已合并
elegaanz 5 年前 将 4 次代码提交从 input-builder 合并至 master
elegaanz 评论于 5 年前 (从 github.com 迁移)

Pros:

  • less ambiguities
  • more type safety
  • less cloning (we don't clone forms for each input anymore)

Cons:

  • more verbose (but at the same time it is easier to parse IMO)
  • less natural syntax
Pros: - less ambiguities - more type safety - less cloning (we don't clone forms for each input anymore) Cons: - more verbose (but at the same time it is easier to parse IMO) - less natural syntax
codecov[bot] 评论于 5 年前 (从 github.com 迁移)

Codecov Report

Merging #646 into master will decrease coverage by 0.26%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master     #646      +/-   ##
==========================================
- Coverage   35.06%   34.79%   -0.27%     
==========================================
  Files          68       68              
  Lines        7945     8006      +61     
  Branches     1890     1894       +4     
==========================================
  Hits         2786     2786              
- Misses       4383     4444      +61     
  Partials      776      776
# [Codecov](https://codecov.io/gh/Plume-org/Plume/pull/646?src=pr&el=h1) Report > Merging [#646](https://codecov.io/gh/Plume-org/Plume/pull/646?src=pr&el=desc) into [master](https://codecov.io/gh/Plume-org/Plume/commit/a6c84daa1a242246ac01260eb9bc201dd6e47830?src=pr&el=desc) will **decrease** coverage by `0.26%`. > The diff coverage is `0%`. ```diff @@ Coverage Diff @@ ## master #646 +/- ## ========================================== - Coverage 35.06% 34.79% -0.27% ========================================== Files 68 68 Lines 7945 8006 +61 Branches 1890 1894 +4 ========================================== Hits 2786 2786 - Misses 4383 4444 +61 Partials 776 776 ```
igalic (从 github.com 迁移) 评审于 5 年前
igalic (从 github.com 迁移) 留下了一条评论

this looks pretty cool!

this looks pretty cool!
所有者

Maybe implementing https://docs.rs/ructe/0.6.2/ructe/templates/trait.ToHtml.html would make more sens than a stand-alone function? Also, clippy is complaining about conventions, to_* usually take by reference

Maybe implementing https://docs.rs/ructe/0.6.2/ructe/templates/trait.ToHtml.html would make more sens than a stand-alone function? Also, clippy is complaining about conventions, to_* usually take by reference
elegaanz 评论于 5 年前 (从 github.com 迁移)

I thought about it, but my function takes a gettex::Catalog, while ToHtml::to_html doesn't. I could have passed it as an argument to Input::new tho.

But I made the commit before reading your review, so it is Input::html now (I can still change it if you prefer).

I thought about it, but my function takes a `gettex::Catalog`, while `ToHtml::to_html` doesn't. I could have passed it as an argument to `Input::new` tho. But I made the commit before reading your review, so it is `Input::html` now (I can still change it if you prefer).
igalic 评论于 5 年前 (从 github.com 迁移)

definitely, what @fdb-hiroshima said


update / carification:
About implementing Ructe's ToHtml trait.

definitely, what @fdb-hiroshima said ****** update / carification: About implementing Ructe's `ToHtml` trait.
所有者

I did not notice the Catalog. It was just a suggestion, but as it's totally fine as is

I did not notice the Catalog. It was just a suggestion, but as it's totally fine as is
所有者

As .html() take the Catalog, and the provided label in Input::new is always translated, can't it be translated transparently from .html() instead of explicitly each time? (I don't know if it would be better or worst, that's an actual question)

As `.html()` take the Catalog, and the provided label in Input::new is _always_ translated, can't it be translated transparently from `.html()` instead of explicitly each time? (I don't know if it would be better or worst, that's an actual question)
elegaanz 评论于 5 年前 (从 github.com 迁移)

gettext-macros requires strings that are known at compile time, so that it can add them to the .pot file. With the latest version of the crate (which requires Rust 2018 for some reason, so we can't use it now), there is a new macro, called t that would allow us to do:

Input::new("email", t!("Your email address"))
    .input_type("email")
    .html(catalog);

Which would be a bit better (but we can't really do anything else than that I think, these strings should be marked as translatable with a macro at some point).

gettext-macros requires strings that are known at compile time, so that it can add them to the .pot file. With the latest version of the crate (which requires Rust 2018 for some reason, so we can't use it now), there is a new macro, called `t` that would allow us to do: ```rust Input::new("email", t!("Your email address")) .input_type("email") .html(catalog); ``` Which would be a bit better (but we can't really do anything else than that I think, these strings should be marked as translatable with a macro at some point).
trinity-1686a 评审于 5 年前
trinity-1686a 留下了一条评论
所有者

👀

👀
所有者

I think error is no longer put in a <p class="error" dir="auto">{}</p>

I think error is no longer put in a `<p class="error" dir="auto">{}</p>`
@ -13,0 +13,4 @@
.default(&form.title)
.error(&errors)
.set_prop("minlength", 1)
.html(ctx.1))
所有者

previously had the requiredproperty

previously had the `required`property
@ -18,3 +18,3 @@
<form method="post" action="@uri!(instance::update_settings)">
@input!(ctx.1, name (text), "Name", form, errors.clone(), "props")
@(Input::new("name", i18n!(ctx.1, "Name"))
所有者

what was props, why is it gone?

what was `props`, why is it gone?
trinity-1686a 评审于 5 年前
@ -13,0 +13,4 @@
.default(&form.title)
.error(&errors)
.set_prop("minlength", 1)
.html(ctx.1))
所有者

mb, it's added automagically when not optional

mb, it's added automagically when not optional
elegaanz (从 github.com 迁移) 评审于 5 年前
@ -18,3 +18,3 @@
<form method="post" action="@uri!(instance::update_settings)">
@input!(ctx.1, name (text), "Name", form, errors.clone(), "props")
@(Input::new("name", i18n!(ctx.1, "Name"))
elegaanz (从 github.com 迁移) 评论于 5 年前

I don't know to be honest, but it clearly was here by mistake (this argument was for additional HTML properties).

I don't know to be honest, but it clearly was here by mistake (this argument was for additional HTML properties).
trinity-1686a5 年前 批准此合并请求
trinity-1686a 留下了一条评论
所有者

👍

👍

评审人

trinity-1686a5 年前 批准此合并请求
该合并请求已作为 8ab690001d 被合并。
你也可以查看 命令行指令

第一步:

从你的仓库中签出一个新的分支并测试变更。
git checkout -b input-builder master
git pull origin input-builder

第二步:

合并变更并更新到 Forgejo 上
git checkout master
git merge --no-ff input-builder
git push origin master
登录 并参与到对话中。
无审核者
未选择里程碑
未指派成员
2 名参与者
通知
到期时间
到期日期无效或超出范围。请使用 'yyyy-mm-dd' 格式。

未设置到期时间。

依赖工单

没有设置依赖项。

参考:Plume/Plume#646
正在加载...
这个人很懒,什么都没留下。