-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from vidhanio/hypertext
feat: enhance hypertext usage
- Loading branch information
Showing
11 changed files
with
377 additions
and
375 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,35 +1,34 @@ | ||
use crate::api::common::Topic; | ||
use std::fmt::Write; | ||
use hypertext::{maud, Renderable}; | ||
|
||
pub fn render_byline(authors: &[Topic]) -> String { | ||
match authors.len() { | ||
0 => "".to_string(), | ||
1 => format_author(&authors[0]), | ||
author_count => { | ||
/* Chain author names together */ | ||
let mut byline = "By ".to_string(); | ||
use crate::api::common::Topic; | ||
use hypertext::html_elements; | ||
|
||
for author in authors[..author_count - 2].iter() { | ||
byline.push_str(&format_author(author)); | ||
byline.push_str(", "); | ||
pub fn render_byline(authors: &[Topic]) -> impl Renderable + '_ { | ||
maud! { | ||
@match authors.len() { | ||
0 => {}, | ||
1 => (format_author(&authors[0])), | ||
author_count => { | ||
"By " | ||
@for author in &authors[..author_count - 2] { | ||
(format_author(author)) ", " | ||
} | ||
(format_author(&authors[author_count - 2])) | ||
" and " | ||
(format_author(&authors[author_count - 1])) | ||
} | ||
|
||
let _ = write!( | ||
byline, | ||
"{} and {}", | ||
format_author(&authors[author_count - 2]), | ||
format_author(&authors[author_count - 1]) | ||
); | ||
|
||
byline | ||
} | ||
} | ||
} | ||
|
||
pub fn format_author(author: &Topic) -> String { | ||
if let Some(url) = &author.topic_url { | ||
format!("<a href=\"{}\">{}</a>", url, author.byline) | ||
} else { | ||
author.byline.clone() | ||
pub fn format_author(author: &Topic) -> impl Renderable + '_ { | ||
maud! { | ||
@if let Some(url) = &author.topic_url { | ||
a href=(url) { | ||
(&author.byline) | ||
} | ||
} @else { | ||
(&author.byline) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,38 +1,37 @@ | ||
use std::fmt::Write; | ||
use hypertext::{html_elements, maud, Renderable}; | ||
|
||
use crate::api::legacy_article::LegacyArticleAuthor; | ||
|
||
pub fn render_byline(authors: &[LegacyArticleAuthor]) -> String { | ||
match authors.len() { | ||
0 => "".to_string(), | ||
1 => format_author(&authors[0]), | ||
author_count => { | ||
/* Chain author names together */ | ||
let mut byline = "By ".to_string(); | ||
|
||
for author in authors[..author_count - 2].iter() { | ||
byline.push_str(&format_author(author)); | ||
byline.push_str(", "); | ||
pub fn render_byline(authors: &[LegacyArticleAuthor]) -> impl Renderable + '_ { | ||
maud! { | ||
@match authors.len() { | ||
0 => {}, | ||
1 => (format_author(&authors[0])), | ||
author_count => { | ||
"By " | ||
@for author in &authors[..author_count - 2] { | ||
(format_author(author)) ", " | ||
} | ||
(format_author(&authors[author_count - 2])) | ||
" and " | ||
(format_author(&authors[author_count - 1])) | ||
} | ||
|
||
let _ = write!( | ||
byline, | ||
"{} and {}", | ||
format_author(&authors[author_count - 2]), | ||
format_author(&authors[author_count - 1]) | ||
); | ||
|
||
byline | ||
} | ||
} | ||
} | ||
|
||
pub fn format_author(author: &LegacyArticleAuthor) -> String { | ||
match author | ||
.url | ||
.strip_prefix("https://www.reuters.com/journalists/") | ||
{ | ||
Some(path) => format!("<a href=\"/authors/{}/\">{}</a>", path, author.name), | ||
None => format!("<a href=\"{}\">{}</a>", author.url, author.name), | ||
pub fn format_author(author: &LegacyArticleAuthor) -> impl Renderable + '_ { | ||
maud! { | ||
a href=@if let Some(path) = author | ||
.url | ||
.strip_prefix("https://www.reuters.com/journalists/") | ||
{ | ||
"/journalists/" (path) "/" | ||
} @else { | ||
(&author.url) | ||
} | ||
{ | ||
(&author.name) | ||
} | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
use hypertext::{Attribute, GlobalAttributes}; | ||
|
||
pub mod about; | ||
pub mod article; | ||
pub mod internet_news; | ||
pub mod markets; | ||
pub mod search; | ||
|
||
trait HtmxAttributes: GlobalAttributes { | ||
#[allow(non_upper_case_globals)] | ||
const property: Attribute = Attribute; | ||
} | ||
|
||
impl<T: GlobalAttributes> HtmxAttributes for T {} |
Oops, something went wrong.