🎉 [jquery] Módulo para incluir jQuery en páginas
This commit is contained in:
parent
20f6c85e68
commit
b95a154a34
6 changed files with 97 additions and 0 deletions
21
pagetop-jquery/Cargo.toml
Normal file
21
pagetop-jquery/Cargo.toml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[package]
|
||||||
|
name = "pagetop-jquery"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
authors = [
|
||||||
|
"Manuel Cillero <manuel@cillero.es>"
|
||||||
|
]
|
||||||
|
description = """\
|
||||||
|
Manages the user registration and login system.\
|
||||||
|
"""
|
||||||
|
homepage = "https://pagetop.cillero.es"
|
||||||
|
repository = "https://github.com/manuelcillero/pagetop"
|
||||||
|
license = "Apache-2.0 OR MIT"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
pagetop = { path = "../pagetop", version = "0.0", features = ["database"], default-features = false }
|
||||||
|
static-files = "0.2.3"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
pagetop-build = { path = "../pagetop-build", version = "0.0" }
|
||||||
26
pagetop-jquery/README.md
Normal file
26
pagetop-jquery/README.md
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
Módulo para añadir jQuery a las páginas generadas con **PageTop**.
|
||||||
|
|
||||||
|
[PageTop](https://github.com/manuelcillero/pagetop/tree/main/pagetop), es un entorno de desarrollo
|
||||||
|
basado en algunos de los *crates* más estables y populares del ecosistema Rust para proporcionar
|
||||||
|
APIs, patrones de desarrollo y buenas prácticas para la creación de soluciones web SSR (*Server-Side
|
||||||
|
Rendering*).
|
||||||
|
|
||||||
|
|
||||||
|
# 🚧 Advertencia
|
||||||
|
|
||||||
|
**PageTop** sólo libera actualmente versiones de desarrollo. La API no es estable y los cambios son
|
||||||
|
constantes. No puede considerarse preparado hasta que se libere la versión **0.1.0**.
|
||||||
|
|
||||||
|
|
||||||
|
# 📜 Licencia
|
||||||
|
|
||||||
|
Este proyecto tiene licencia, de hecho tiene dos, puedes aplicar cualquiera de las siguientes a tu
|
||||||
|
elección:
|
||||||
|
|
||||||
|
* Licencia Apache versión 2.0
|
||||||
|
([LICENSE-APACHE](https://github.com/manuelcillero/pagetop/blob/main/LICENSE-APACHE) o
|
||||||
|
[http://www.apache.org/licenses/LICENSE-2.0]).
|
||||||
|
|
||||||
|
* Licencia MIT
|
||||||
|
([LICENSE-MIT](https://github.com/manuelcillero/pagetop/blob/main/LICENSE-MIT) o
|
||||||
|
[http://opensource.org/licenses/MIT]).
|
||||||
3
pagetop-jquery/build.rs
Normal file
3
pagetop-jquery/build.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() -> std::io::Result<()> {
|
||||||
|
pagetop_build::bundle_resources("./static", "jquery", None)
|
||||||
|
}
|
||||||
44
pagetop-jquery/src/lib.rs
Normal file
44
pagetop-jquery/src/lib.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
|
pub_handle!(MODULE_JQUERY);
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/jquery.rs"));
|
||||||
|
|
||||||
|
const JQUERY_PARAM: &str = "jquery.add";
|
||||||
|
const JQUERY_SOURCE: &str = "/jquery/js/jquery.min.js";
|
||||||
|
|
||||||
|
pub struct JQuery;
|
||||||
|
|
||||||
|
impl ModuleTrait for JQuery {
|
||||||
|
fn handle(&self) -> Handle {
|
||||||
|
MODULE_JQUERY
|
||||||
|
}
|
||||||
|
|
||||||
|
fn configure_service(&self, cfg: &mut server::web::ServiceConfig) {
|
||||||
|
serve_static_files!(cfg, "/jquery", bundle_jquery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JQuery {
|
||||||
|
pub fn add_jquery(rcx: &mut RenderContext) {
|
||||||
|
match rcx.get_param::<bool>(JQUERY_PARAM) {
|
||||||
|
Some(true) => {}
|
||||||
|
_ => {
|
||||||
|
rcx.alter(ContextOp::AddJavaScript(
|
||||||
|
JavaScript::located(JQUERY_SOURCE)
|
||||||
|
.with_version("3.6.0")
|
||||||
|
.with_weight(isize::MIN)
|
||||||
|
.with_mode(ModeJS::Normal),
|
||||||
|
));
|
||||||
|
rcx.set_param::<bool>(JQUERY_PARAM, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_jquery(rcx: &mut RenderContext) {
|
||||||
|
if let Some(true) = rcx.get_param::<bool>(JQUERY_PARAM) {
|
||||||
|
rcx.alter(ContextOp::RemoveJavaScript(JQUERY_SOURCE));
|
||||||
|
rcx.set_param::<bool>(JQUERY_PARAM, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
pagetop-jquery/static/js/jquery.min.js
vendored
Normal file
2
pagetop-jquery/static/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
pagetop-jquery/static/js/jquery.min.map
Normal file
1
pagetop-jquery/static/js/jquery.min.map
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue