Skip to content

Move templates closer to what handlebars-fluent uses #958

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

Merged
merged 4 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/i18n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,20 @@ impl HelperDef for I18NHelper {
id
} else {
return Err(RenderError::new(
"{{text}} must have at least one parameter",
"{{fluent}} must have at least one parameter",
));
};

let id = if let Some(id) = id.path() {
id
if id.path().is_some() {
return Err(RenderError::new(
"{{fluent}} takes a string parameter with no path",
));
}

let id = if let Json::String(ref s) = *id.value() {
s
} else {
return Err(RenderError::new("{{text}} takes an identifier parameter"));
return Err(RenderError::new("{{fluent}} takes a string parameter"));
};

let mut args = if h.hash().is_empty() {
Expand Down Expand Up @@ -213,23 +219,31 @@ impl HelperDef for I18NHelper {
let args = args.as_mut().unwrap();
for element in &tpl.elements {
if let TemplateElement::HelperBlock(ref block) = element {
if block.name != "textparam" {
if block.name != "fluentparam" {
return Err(RenderError::new(format!(
"{{{{text}}}} can only contain {{{{textparam}}}} elements, not {}",
"{{{{fluent}}}} can only contain {{{{fluentparam}}}} elements, not {}",
block.name
)));
}

let id = if let Some(el) = block.params.get(0) {
if let Parameter::Name(ref s) = *el {
s
if let Parameter::Literal(ref s) = *el {
if let Json::String(ref s) = *s {
s
} else {
return Err(RenderError::new(
"{{fluentparam}} takes a string parameter",
));
}
} else {
return Err(RenderError::new(
"{{textparam}} takes an identifier parameter",
"{{fluentparam}} takes a string parameter",
));
}
} else {
return Err(RenderError::new("{{textparam}} must have one parameter"));
return Err(RenderError::new("{{fluentparam}} must have one parameter"));
};

if let Some(ref tpl) = block.template {
let mut s = StringOutput::default();
tpl.render(reg, context, rcx, &mut s)?;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ fn main() {
let templating = Template::custom(|engine| {
engine
.handlebars
.register_helper("text", Box::new(I18NHelper::new()));
.register_helper("fluent", Box::new(I18NHelper::new()));
engine
.handlebars
.register_helper("team-text", Box::new(TeamHelper::new()));
Expand Down
6 changes: 3 additions & 3 deletions templates/404.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
<div class="flex-none flex-l mt5 mb5 tc tl-l">
<div class="w-70-l w-100">
<h1>{{text error404-page-title}}</h1>
<h2 class="subtitle">{{text error404-subtitle}}</h2>
<h1>{{fluent "error"404-page-title}}</h1>
<h2 class="subtitle">{{fluent "error"404-subtitle}}</h2>
</div>
<div class="w-30-l w-100 mt5 mt0-l">
<img id="ferris-error" src="/static/images/ferris-error.png" alt="{{text error404-img-alt}}">
<img id="ferris-error" src="/static/images/ferris-error.png" alt="{{fluent "error"404-img-alt}}">
</div>
</div>
</div>
Expand Down
90 changes: 45 additions & 45 deletions templates/community/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<header class="mt3 mt2-ns mb4 mb5-ns tc tl-ns">
<div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
<h1>{{text community-page-title}}</h1>
<h1>{{fluent "community-page-title"}}</h1>
</div>
</header>

Expand All @@ -11,19 +11,19 @@
<div class="flex flex-column flex-row-l">
<div class="mw-50-l mh2-l pt0 flex flex-column justify-between-l">
<p>
{{text community-blurb}}
{{fluent "community-blurb"}}
</p>
<p>
{{text community-twir}}
{{fluent "community-twir"}}
</p>
<a href="https://this-week-in-rust.org/" class="button button-secondary mb3">{{text community-twir-button}}</a>
<a href="https://this-week-in-rust.org/" class="button button-secondary mb3">{{fluent "community-twir-button"}}</a>
</div>
<div class="mw-50-l mh2-l pt0 flex flex-column justify-between-l">
<p>
{{text community-team-contact}}
{{fluent "community-team-contact"}}
</p>

<a href="mailto:[email protected]" class="button button-secondary mb3">{{text community-team-button}}</a>
<a href="mailto:[email protected]" class="button button-secondary mb3">{{fluent "community-team-button"}}</a>
</div>
</div>

Expand All @@ -33,48 +33,48 @@
<section id="contribute-talk" class="white">
<div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
<header>
<h2>{{text community-where}}</h2>
<h2>{{fluent "community-where"}}</h2>
<div class="highlight"></div>
</header>
<div class="flex flex-column flex-row-l">
<div class="mw-33-l mh3-l pt0 flex flex-column justify-start" id="users-forum">
<div class="flex-grow-1">
<h3 class="mt0 mb4">{{text community-urlo-header}}</h3>
<h3 class="mt0 mb4">{{fluent "community-urlo-header"}}</h3>
<p>
{{text community-urlo}}
{{fluent "community-urlo"}}
</p>
</div>

<a href="https://users.rust-lang.org" class="button button-secondary">{{text community-discourse-button}}</a>
<a href="https://users.rust-lang.org" class="button button-secondary">{{fluent "community-discourse-button"}}</a>
</div>

<div class="mw-33-l mh3-l pt4 pt0-l flex flex-column justify-start" id="internals-forum">
<div class="flex-grow-1">
<h3 class="mt0 mb4">{{text community-irlo-header}}</h3>
<h3 class="mt0 mb4">{{fluent "community-irlo-header"}}</h3>
<p>
{{text community-irlo}}
{{fluent "community-irlo"}}
</p>
</div>

<a href="https://internals.rust-lang.org" class="button button-secondary">{{text community-discourse-button}}</a>
<a href="https://internals.rust-lang.org" class="button button-secondary">{{fluent "community-discourse-button"}}</a>

</div>

<div class="mw-33-l mh3-l pt4 pt0-l flex flex-column justify-start" id="chat-platforms">
<div class="flex-grow-1">
<h3 class="mt0 mb4">{{text community-chat-header}}</h3>
<h3 class="mt0 mb4">{{fluent "community-chat-header"}}</h3>
<p>
{{text community-chat}}
{{fluent "community-chat"}}
</p>
</div>

{{!-- TODO: remove padding and margin once global declarations are gone --}}
<ul class="list pa0 ma0">
<li class="mb3">
<a href="https://discord.gg/rust-lang" class="button button-secondary">{{text discord}}</a>
<a href="https://discord.gg/rust-lang" class="button button-secondary">{{fluent "discord"}}</a>
</li>
<li class="mb3">
<a href="{{baseurl}}/governance" class="button button-secondary">{{text community-teams-learn}}</a>
<a href="{{baseurl}}/governance" class="button button-secondary">{{fluent "community-teams-learn"}}</a>
</li>
</ul>
</div>
Expand All @@ -85,57 +85,57 @@
<section id="community-events" class="green">
<div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
<header>
<h2>{{text community-events-header}}</h2>
<h2>{{fluent "community-events-header"}}</h2>
<div class="highlight"></div>
</header>
<div class="flex flex-column flex-row-l">
<div class="mw-50-l mh3-l pt0 flex flex-column justify-between" id="meetups-usergroups">
<div>
<h3 class="mt0 mb4">{{text community-meetup-header}}</h3>
<h3 class="mt0 mb4">{{fluent "community-meetup-header"}}</h3>
<p>
{{text community-meetup}}
{{fluent "community-meetup"}}
</p>
</div>
<ul class="list ma0 pa0">
<li class="mb3">
<a href="https://calendar.google.com/calendar/embed?showTitle=0&showPrint=0&showTabs=0&showCalendars=0&mode=AGENDA&height=400&wkst=1&bgcolor=%23FFFFFF&src=apd9vmbc22egenmtu5l6c5jbfc%40group.calendar.google.com&color=%23691426&ctz=Europe%2FMadrid"
class="button button-secondary">{{text community-calendar}}</a>
class="button button-secondary">{{fluent "community-calendar"}}</a>
</li>
<li class="mb3">
<a href="https://blog.rust-lang.org/2019/05/20/The-2019-Rust-Event-Lineup.html"
class="button button-secondary">{{text community-conference-lineup}}</a>
class="button button-secondary">{{fluent "community-conference-lineup"}}</a>
</li>
<li class="mb3">
<a href="https://timetill.rs"
target="_blank"
class="button button-secondary">{{text community-timetill-cta}}</a>
class="button button-secondary">{{fluent "community-timetill-cta"}}</a>
</li>
</ul>
</div>
<div class="mw-50-l mh3-l pt4 pt0-l flex flex-column justify-between" id="conferences">
<div>
<h3 class="mt0 mb4">{{text community-event-run-header}}</h3>
{{text community-event-run}}
<h3 class="mt0 mb4">{{fluent "community-event-run-header"}}</h3>
{{fluent "community-event-run"}}
</div>
<ul class="list ma0 pa0">
<li class="mb3">
<a href="https://github.com/rust-community/events-team#-rust-events-team" class="button button-secondary">{{text community-events-repo}}</a>
<a href="https://github.com/rust-community/events-team#-rust-events-team" class="button button-secondary">{{fluent "community-events-repo"}}</a>
</li>
<li class="mb3">
<a href="https://docs.google.com/forms/d/e/1FAIpQLSf52YXGhqBaHtCXtVna4iHYMK7IQaTqUW6V-ztsZC8C2TBInQ/viewform"
class="button button-secondary">{{text community-event-register}}</a>
class="button button-secondary">{{fluent "community-event-register"}}</a>
</li>
</ul>
</div>
</div>
<img src="/static/images/rustfest.jpg" alt="{{text community-rustfest-alt}}">
<img src="/static/images/rustfest.jpg" alt="{{fluent "community-rustfest-alt"}}">
</div>
</section>

<section id="rustbridge" class="white">
<div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
<header>
<h2>{{text community-rustbridge-header}}</h2>
<h2>{{fluent "community-rustbridge-header"}}</h2>
<div class="highlight"></div>
</header>

Expand All @@ -145,35 +145,35 @@
</div>
<div class="mw-67-l mh3-l">
<p>
{{text community-rustbridge}}
{{fluent "community-rustbridge"}}
</p>
<a href="https://github.com/rustbridge/team" class="button button-secondary">{{text community-rustbridge-button}}</a>
<a href="https://github.com/rustbridge/team" class="button button-secondary">{{fluent "community-rustbridge-button"}}</a>
</div>
</div>

<ul class="list ma0 pa0 flex flex-column flex-row-ns flex-wrap-m flex-nowrap-l justify-center">
<li class="tc max-width-half-m ph1-ns mb3"><img src="/static/images/rustbridge-rustconf.jpg" alt="{{text community-rustbridge-rustconf-alt}}" /></li>
<li class="tc max-width-half-m ph1-ns mb3"><img src="/static/images/rustbridge-paris.jpg" alt="{{text community-rustbridge-paris-alt}}" /></li>
<li class="tc max-width-half-m ph1-ns mb3"><img src="/static/images/rustbridge-berlin.jpg" alt="{{text community-rustbridge-berlin-alt}}" /></dv>
<li class="tc max-width-half-m ph1-ns mb3"><img src="/static/images/rustbridge-rbr.jpg" alt="{{text community-rustbridge-rbr-alt}}" /></li>
<li class="tc max-width-half-m ph1-ns mb3"><img src="/static/images/rustbridge-rustconf.jpg" alt="{{fluent "community-rustbridge-rustconf-alt"}}" /></li>
<li class="tc max-width-half-m ph1-ns mb3"><img src="/static/images/rustbridge-paris.jpg" alt="{{fluent "community-rustbridge-paris-alt"}}" /></li>
<li class="tc max-width-half-m ph1-ns mb3"><img src="/static/images/rustbridge-berlin.jpg" alt="{{fluent "community-rustbridge-berlin-alt"}}" /></dv>
<li class="tc max-width-half-m ph1-ns mb3"><img src="/static/images/rustbridge-rbr.jpg" alt="{{fluent "community-rustbridge-rbr-alt"}}" /></li>
</ul>
</div>
</section>

<section id="rustreach" class="red">
<div class="w-100 mw-none ph3 mw8-m mw9-l center">
<header>
<h2>{{text community-irr-header}}</h2>
<h2>{{fluent "community-irr-header"}}</h2>
<div class="highlight"></div>
</header>
<div class="w-100 flex flex-column flex-row-l">
<div class="mw-33-l mh3-l">
<img src="/static/images/rustreach.jpg" alt="increasing rust's reach logo"/>
</div>
<div class="mw-67-l mh3-l">
<p> {{text community-irr}}
<p> {{fluent "community-irr"}}
</p>
<a href="http://reach.rust-lang.org/" class="button button-secondary">{{text community-irr-button}}</a>
<a href="http://reach.rust-lang.org/" class="button button-secondary">{{fluent "community-irr-button"}}</a>
</div>
</div>
</div>
Expand All @@ -182,21 +182,21 @@
<section id="conduct" class="green">
<div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
<header>
<h2>{{text community-standards-header}}</h2>
<h2>{{fluent "community-standards-header"}}</h2>
<div class="highlight"></div>
</header>
<div class="f3 f2-l">
<p>
{{#text community-standards}}
{{#textparam url}}{{baseurl}}/policies/code-of-conduct{{/textparam}}
{{/text}}
{{#fluent "community-standards"}}
{{#fluentparam "url"}}{{baseurl}}/policies/code-of-conduct{{/fluentparam}}
{{/fluent}}
</p>
</div>

<div class="flex flex-column flex-row-l justify-between">
<a href="mailto:[email protected]" class="button button-secondary mw-33-l mh3-l w-100 mb3">{{text community-mod-button}}</a>
<a href="{{baseurl}}/policies/code-of-conduct" class="button button-secondary mw-33-l mh3-l w-100 mb3">{{text community-coc-button}}</a>
<a href="{{baseurl}}/policies/code-of-conduct#moderation" class="button button-secondary mw-33-l mh3-l w-100 mb3">{{text community-mod-guidelines-button}}</a>
<a href="mailto:[email protected]" class="button button-secondary mw-33-l mh3-l w-100 mb3">{{fluent "community-mod-button"}}</a>
<a href="{{baseurl}}/policies/code-of-conduct" class="button button-secondary mw-33-l mh3-l w-100 mb3">{{fluent "community-coc-button"}}</a>
<a href="{{baseurl}}/policies/code-of-conduct#moderation" class="button button-secondary mw-33-l mh3-l w-100 mb3">{{fluent "community-mod-guidelines-button"}}</a>
</div>
</div>
</section>
Expand Down
38 changes: 19 additions & 19 deletions templates/components/footer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@
<div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
<div class="flex flex-column flex-row-ns pv0-l">
<div class="flex flex-column mw8 w-100 measure-wide-l pv2 pv5-m pv2-ns ph4-m ph4-l" id="get-help">
<h4>{{text footer-get-help}}</h4>
<h4>{{fluent "footer-get-help"}}</h4>
<ul>
<li><a href="https://doc.rust-lang.org">{{text footer-doc}}</a></li>
<li><a href="https://users.rust-lang.org">{{text footer-ask}}</a></li>
<li><a href="http://ping.rust-lang.org">{{text footer-status}}</a></li>
<li><a href="https://doc.rust-lang.org">{{fluent "footer-doc"}}</a></li>
<li><a href="https://users.rust-lang.org">{{fluent "footer-ask"}}</a></li>
<li><a href="http://ping.rust-lang.org">{{fluent "footer-status"}}</a></li>
</ul>
<div class="languages">
<label for="language-footer" class="hidden">{{text choose-language}}</label>
<label for="language-footer" class="hidden">{{fluent "choose-language"}}</label>
<select id="language-footer">
{{> components/languages-dropdown}}
</select>
</div>
</div>
<div class="flex flex-column mw8 w-100 measure-wide-l pv2 pv5-m pv2-ns ph4-m ph4-l">
<h4>{{text footer-policies}}</h4>
<h4>{{fluent "footer-policies"}}</h4>
<ul>
<li><a href="{{baseurl}}/policies/code-of-conduct">{{text footer-coc}}</a></li>
<li><a href="{{baseurl}}/policies/licenses">{{text footer-licenses}}</a></li>
<li><a href="{{baseurl}}/policies/media-guide">{{text footer-media}}</a></li>
<li><a href="{{baseurl}}/policies/security">{{text footer-security}}</a></li>
<li><a href="{{baseurl}}/policies/privacy">{{text policies-privacy-link}}</a></li>
<li><a href="{{baseurl}}/policies">{{text footer-policies-all}}</a></li>
<li><a href="{{baseurl}}/policies/code-of-conduct">{{fluent "footer-coc"}}</a></li>
<li><a href="{{baseurl}}/policies/licenses">{{fluent "footer-licenses"}}</a></li>
<li><a href="{{baseurl}}/policies/media-guide">{{fluent "footer-media"}}</a></li>
<li><a href="{{baseurl}}/policies/security">{{fluent "footer-security"}}</a></li>
<li><a href="{{baseurl}}/policies/privacy">{{fluent "policies-privacy-link"}}</a></li>
<li><a href="{{baseurl}}/policies">{{fluent "footer-policies-all"}}</a></li>
</ul>
</div>
<div class="flex flex-column mw8 w-100 measure-wide-l pv2 pv5-m pv2-ns ph4-m ph4-l">
<h4>{{text footer-social}}</h4>
<h4>{{fluent "footer-social"}}</h4>
<div class="flex flex-row flex-wrap">
<a href="https://twitter.com/rustlang"><img src="/static/images/twitter.svg" alt="twitter logo" title="{{text footer-youtube-alt}}"/></a>
<a href="https://www.youtube.com/channel/UCaYhcUwRBNscFNUKTjgPFiA"><img class="pv2" src="/static/images/youtube.svg" alt="{{text footer-alt-youtube}}" title="YouTube"/></a>
<a href="https://discord.gg/rust-lang"><img src="/static/images/discord.svg" alt="discord logo" title="{{text footer-discord-alt}}"/></a>
<a href="https://github.com/rust-lang"><img src="/static/images/github.svg" alt="github logo" title="{{text footer-github-alt}}"/></a>
<a href="https://twitter.com/rustlang"><img src="/static/images/twitter.svg" alt="twitter logo" title="{{fluent "footer-youtube-alt"}}"/></a>
<a href="https://www.youtube.com/channel/UCaYhcUwRBNscFNUKTjgPFiA"><img class="pv2" src="/static/images/youtube.svg" alt="{{fluent "footer-alt-youtube"}}" title="YouTube"/></a>
<a href="https://discord.gg/rust-lang"><img src="/static/images/discord.svg" alt="discord logo" title="{{fluent "footer-discord-alt"}}"/></a>
<a href="https://github.com/rust-lang"><img src="/static/images/github.svg" alt="github logo" title="{{fluent "footer-github-alt"}}"/></a>
</div>
</div>

</div>
<div class="attribution">
<p>
{{text footer-attribution}}
{{fluent "footer-attribution"}}
</p>
<p>{{text footer-old-site}}</p>
<p>{{fluent "footer-old-site"}}</p>
</div>
</div>
</footer>
Loading