From e316e9aa916aba848ed6b1ae79f463cb86ea9b80 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Tue, 25 Jul 2023 20:02:50 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20New=20into=5Fstring()=20methods?= =?UTF-8?q?=20for=20L10n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop-homedemo/src/lib.rs | 2 +- pagetop/src/core/component/l10n.rs | 8 ++++++-- pagetop/src/html.rs | 8 ++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pagetop-homedemo/src/lib.rs b/pagetop-homedemo/src/lib.rs index 28e4c056..ae0d8824 100644 --- a/pagetop-homedemo/src/lib.rs +++ b/pagetop-homedemo/src/lib.rs @@ -142,7 +142,7 @@ fn about_pagetop() -> Container { .with_component(Paragraph::with(L10n::t("pagetop_text2", &LOCALES_HOMEDEMO))) .with_component(Paragraph::with( L10n::e("pagetop_text3", &LOCALES_HOMEDEMO) - .with_arg("href", "https://docs.rs/pagetop/latest/pagetop".to_string()), + .with_arg("href", "https://docs.rs/pagetop/latest/pagetop"), )), ), ) diff --git a/pagetop/src/core/component/l10n.rs b/pagetop/src/core/component/l10n.rs index 5829c943..d014dea7 100644 --- a/pagetop/src/core/component/l10n.rs +++ b/pagetop/src/core/component/l10n.rs @@ -96,8 +96,8 @@ impl L10n { } #[fn_builder] - pub fn alter_arg(&mut self, arg: &'static str, value: String) -> &mut Self { - self.args.insert(arg, value); + pub fn alter_arg(&mut self, arg: &'static str, value: impl Into) -> &mut Self { + self.args.insert(arg, value.into()); self } @@ -115,4 +115,8 @@ impl L10n { pub fn args(&self) -> &HashMap<&str, String> { &self.args } + + pub fn into_string(&self, cx: &mut Context) -> Option { + self.prepare_component(cx).into_string() + } } diff --git a/pagetop/src/html.rs b/pagetop/src/html.rs index c0ebacc5..a67d8274 100644 --- a/pagetop/src/html.rs +++ b/pagetop/src/html.rs @@ -39,4 +39,12 @@ impl PrepareMarkup { PrepareMarkup::With(markup) => markup, } } + + pub fn into_string(self) -> Option { + match self { + PrepareMarkup::None => None, + PrepareMarkup::Text(text) => Some(text.to_string()), + PrepareMarkup::With(markup) => Some(markup.into_string()), + } + } }