-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Michael Howell <[email protected]>
- Loading branch information
Showing
17 changed files
with
171 additions
and
2,752 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use font_awesome_as_a_crate as fa; | ||
use handlebars::{ | ||
Context, Handlebars, Helper, Output, RenderContext, RenderError, RenderErrorReason, | ||
}; | ||
use log::trace; | ||
use std::str::FromStr; | ||
|
||
pub fn fa_helper( | ||
h: &Helper<'_>, | ||
_r: &Handlebars<'_>, | ||
_ctx: &Context, | ||
_rc: &mut RenderContext<'_, '_>, | ||
out: &mut dyn Output, | ||
) -> Result<(), RenderError> { | ||
trace!("fa_helper (handlebars helper)"); | ||
|
||
let type_ = h | ||
.param(0) | ||
.and_then(|v| v.value().as_str()) | ||
.and_then(|v| fa::Type::from_str(v).ok()) | ||
.ok_or_else(|| { | ||
RenderErrorReason::Other( | ||
"Param 0 with String type is required for fontawesome helper.".to_owned(), | ||
) | ||
})?; | ||
|
||
let name = h.param(1).and_then(|v| v.value().as_str()).ok_or_else(|| { | ||
RenderErrorReason::Other( | ||
"Param 1 with String type is required for fontawesome helper.".to_owned(), | ||
) | ||
})?; | ||
|
||
trace!("fa_helper: {} {}", type_, name); | ||
|
||
let name = name | ||
.strip_prefix("fa-") | ||
.or_else(|| name.strip_prefix("fab-")) | ||
.or_else(|| name.strip_prefix("fas-")) | ||
.unwrap_or(name); | ||
|
||
if let Some(id) = h.param(2).and_then(|v| v.value().as_str()) { | ||
out.write(&format!("<span class=\"fa-svg\" id=\"{}\">", id))?; | ||
} else { | ||
out.write("<span class=\"fa-svg\">")?; | ||
} | ||
out.write( | ||
fa::svg(type_, name) | ||
.map_err(|_| RenderErrorReason::Other(format!("Missing font {}", name)))?, | ||
)?; | ||
out.write("</span>")?; | ||
|
||
Ok(()) | ||
} |
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,3 +1,4 @@ | ||
pub mod fontawesome; | ||
pub mod navigation; | ||
pub mod theme; | ||
pub mod toc; |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.