🎨 Mejora presentación de la API en los paquetes
This commit is contained in:
parent
c5330036d6
commit
3690087005
12 changed files with 89 additions and 86 deletions
|
|
@ -24,7 +24,7 @@ impl PackageTrait for HljsSample {
|
|||
|
||||
async fn hljs_sample(request: HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
Page::new(request)
|
||||
.with_component(Snippet::with(
|
||||
.with_component(HljsSnippet::with(
|
||||
HljsLang::Rust,
|
||||
r###"
|
||||
use pagetop::prelude::*;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@
|
|||
|
||||
use pagetop::prelude::*;
|
||||
|
||||
use crate::hljs_mode::HljsMode;
|
||||
use crate::hljs_theme::HljsTheme;
|
||||
use crate::mode::HljsMode;
|
||||
use crate::theme::HljsTheme;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
use crate::config;
|
||||
use crate::hljs_lang::HljsLang;
|
||||
use crate::hljs_mode::HljsMode;
|
||||
use crate::hljs_theme::HljsTheme;
|
||||
use crate::lang::HljsLang;
|
||||
use crate::mode::HljsMode;
|
||||
use crate::theme::HljsTheme;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
|
@ -72,30 +72,34 @@
|
|||
|
||||
use pagetop::prelude::*;
|
||||
|
||||
// API *********************************************************************************************
|
||||
|
||||
pub mod config;
|
||||
|
||||
pub mod hljs_context;
|
||||
pub mod hljs_lang;
|
||||
pub mod hljs_mode;
|
||||
pub mod hljs_theme;
|
||||
pub mod snippet;
|
||||
|
||||
// PRELUDE *****************************************************************************************
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::hljs_context::HljsContext;
|
||||
pub use crate::hljs_lang::HljsLang;
|
||||
pub use crate::hljs_mode::HljsMode;
|
||||
pub use crate::hljs_theme::HljsTheme;
|
||||
pub use crate::snippet::Snippet;
|
||||
}
|
||||
// GLOBAL ******************************************************************************************
|
||||
|
||||
include_files!(hljs);
|
||||
|
||||
include_locales!(LOCALES_HLJS);
|
||||
|
||||
const HLJS_VERSION: &str = "11.7.0"; // Versión de la librería Highlight.js.
|
||||
|
||||
// API *********************************************************************************************
|
||||
|
||||
pub mod config;
|
||||
|
||||
pub mod context;
|
||||
pub mod lang;
|
||||
pub mod mode;
|
||||
pub mod theme;
|
||||
|
||||
pub mod snippet;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::context::HljsContext;
|
||||
pub use crate::lang::HljsLang;
|
||||
pub use crate::mode::HljsMode;
|
||||
pub use crate::theme::HljsTheme;
|
||||
|
||||
pub use crate::snippet::HljsSnippet;
|
||||
}
|
||||
|
||||
/// Implementa [`PackageTrait`].
|
||||
pub struct HighlightJS;
|
||||
|
||||
|
|
@ -113,15 +117,12 @@ impl PackageTrait for HighlightJS {
|
|||
}
|
||||
}
|
||||
|
||||
// Versión de la librería Highlight.js.
|
||||
const HLJS_VERSION: &str = "11.7.0";
|
||||
|
||||
// Define los recursos para la página según se use highlight.js en su versión "core" o "common".
|
||||
fn after_render_body(page: &mut Page) {
|
||||
use hljs_context::HljsContext;
|
||||
use hljs_lang::HljsLang;
|
||||
use hljs_mode::HljsMode;
|
||||
use hljs_theme::HljsTheme;
|
||||
use context::HljsContext;
|
||||
use lang::HljsLang;
|
||||
use mode::HljsMode;
|
||||
use theme::HljsTheme;
|
||||
|
||||
let cx = page.context();
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
use pagetop::prelude::*;
|
||||
|
||||
use crate::hljs_context::HljsContext;
|
||||
use crate::hljs_lang::HljsLang;
|
||||
use crate::context::HljsContext;
|
||||
use crate::lang::HljsLang;
|
||||
|
||||
#[derive(AutoDefault)]
|
||||
/// Component to put code snippets on web pages.
|
||||
pub struct Snippet {
|
||||
pub struct HljsSnippet {
|
||||
language: HljsLang,
|
||||
snippet: String,
|
||||
}
|
||||
|
||||
impl ComponentTrait for Snippet {
|
||||
impl ComponentTrait for HljsSnippet {
|
||||
fn new() -> Self {
|
||||
Snippet::default()
|
||||
HljsSnippet::default()
|
||||
}
|
||||
|
||||
fn setup_before_prepare(&mut self, cx: &mut Context) {
|
||||
|
|
@ -32,9 +32,11 @@ impl ComponentTrait for Snippet {
|
|||
}
|
||||
}
|
||||
|
||||
impl Snippet {
|
||||
impl HljsSnippet {
|
||||
pub fn with(language: HljsLang, code: impl Into<String>) -> Self {
|
||||
Snippet::new().with_language(language).with_snippet(code)
|
||||
HljsSnippet::new()
|
||||
.with_language(language)
|
||||
.with_snippet(code)
|
||||
}
|
||||
|
||||
// Hljs BUILDER.
|
||||
|
|
|
|||
36
packages/pagetop-mdbook/src/build.rs
Normal file
36
packages/pagetop-mdbook/src/build.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
use std::path::Path;
|
||||
|
||||
const COMMON_RESOURCES: [&str; 28] = [
|
||||
"css/chrome.css",
|
||||
"css/general.css",
|
||||
"css/print.css",
|
||||
"css/variables.css",
|
||||
"FontAwesome/css/font-awesome.css",
|
||||
"FontAwesome/fonts/fontawesome-webfont.eot",
|
||||
"FontAwesome/fonts/fontawesome-webfont.svg",
|
||||
"FontAwesome/fonts/fontawesome-webfont.ttf",
|
||||
"FontAwesome/fonts/fontawesome-webfont.woff",
|
||||
"FontAwesome/fonts/fontawesome-webfont.woff2",
|
||||
"FontAwesome/fonts/FontAwesome.ttf",
|
||||
"fonts/fonts.css",
|
||||
"fonts/OPEN-SANS-LICENSE.txt",
|
||||
"fonts/open-sans-v17-all-charsets-300.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-300italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-600.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-600italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-700.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-700italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-800.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-800italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-regular.woff2",
|
||||
"fonts/SOURCE-CODE-PRO-LICENSE.txt",
|
||||
"fonts/source-code-pro-v11-all-charsets-500.woff2",
|
||||
"ayu-highlight.css",
|
||||
"highlight.css",
|
||||
"tomorrow-night.css",
|
||||
];
|
||||
|
||||
pub fn except_common_resources(p: &Path) -> bool {
|
||||
!COMMON_RESOURCES.iter().any(|f| p.ends_with(f))
|
||||
}
|
||||
|
|
@ -1,44 +1,13 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
const COMMON_RESOURCES: [&str; 28] = [
|
||||
"css/chrome.css",
|
||||
"css/general.css",
|
||||
"css/print.css",
|
||||
"css/variables.css",
|
||||
"FontAwesome/css/font-awesome.css",
|
||||
"FontAwesome/fonts/fontawesome-webfont.eot",
|
||||
"FontAwesome/fonts/fontawesome-webfont.svg",
|
||||
"FontAwesome/fonts/fontawesome-webfont.ttf",
|
||||
"FontAwesome/fonts/fontawesome-webfont.woff",
|
||||
"FontAwesome/fonts/fontawesome-webfont.woff2",
|
||||
"FontAwesome/fonts/FontAwesome.ttf",
|
||||
"fonts/fonts.css",
|
||||
"fonts/OPEN-SANS-LICENSE.txt",
|
||||
"fonts/open-sans-v17-all-charsets-300.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-300italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-600.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-600italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-700.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-700italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-800.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-800italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-italic.woff2",
|
||||
"fonts/open-sans-v17-all-charsets-regular.woff2",
|
||||
"fonts/SOURCE-CODE-PRO-LICENSE.txt",
|
||||
"fonts/source-code-pro-v11-all-charsets-500.woff2",
|
||||
"ayu-highlight.css",
|
||||
"highlight.css",
|
||||
"tomorrow-night.css",
|
||||
];
|
||||
|
||||
pub fn except_common_resources(p: &Path) -> bool {
|
||||
!COMMON_RESOURCES.iter().any(|f| p.ends_with(f))
|
||||
}
|
||||
// GLOBAL ******************************************************************************************
|
||||
|
||||
include_files!(mdbook);
|
||||
|
||||
// API *********************************************************************************************
|
||||
|
||||
pub mod build;
|
||||
|
||||
pub struct MdBook;
|
||||
|
||||
impl PackageTrait for MdBook {
|
||||
|
|
|
|||
|
|
@ -19,21 +19,16 @@
|
|||
|
||||
use pagetop::prelude::*;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
// GLOBAL ******************************************************************************************
|
||||
|
||||
include_locales!(LOCALES_SEAORM);
|
||||
|
||||
// API *********************************************************************************************
|
||||
|
||||
pub mod config;
|
||||
|
||||
pub mod db;
|
||||
|
||||
// PRELUDE *****************************************************************************************
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::db;
|
||||
}
|
||||
|
||||
include_locales!(LOCALES_SEAORM);
|
||||
|
||||
/// Implementa [`PackageTrait`] y API específica.
|
||||
pub struct SeaORM;
|
||||
|
||||
|
|
@ -47,6 +42,6 @@ impl PackageTrait for SeaORM {
|
|||
}
|
||||
|
||||
fn init(&self) {
|
||||
LazyLock::force(&db::DBCONN);
|
||||
std::sync::LazyLock::force(&db::DBCONN);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ fn main() -> io::Result<()> {
|
|||
// Crea la colección de archivos estáticos.
|
||||
StaticFilesBundle::from_dir(
|
||||
"./static/doc",
|
||||
Some(pagetop_mdbook::except_common_resources),
|
||||
Some(pagetop_mdbook::build::except_common_resources),
|
||||
)
|
||||
.with_name("doc")
|
||||
.build()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue