Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow to inject arbitrary components into the <head>#1499

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
levkk merged 2 commits intomasterfromlevkk-analytics
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
22 changes: 21 additions & 1 deletionpgml-dashboard/src/components/layouts/head/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
use pgml_components::component;
use pgml_components::{component, Component};
use sailfish::TemplateOnce;

#[derive(TemplateOnce, Default, Clone)]
Expand All@@ -10,6 +10,7 @@ pub struct Head {
pub preloads: Vec<String>,
pub context: Option<String>,
pub canonical: Option<String>,
pub additional_components: Vec<Component>,
}

impl Head {
Expand DownExpand Up@@ -58,6 +59,25 @@ impl Head {
self.context = context.to_owned();
self
}

/// Add a component to `<head>`.
///
/// This can be anything, e.g. a `<script>` tag or a `<meta>` or just some HTML or text.
///
/// # Example
///
/// ```
/// use pgml_components::Component;
/// use pgml_components::layouts::Head;
///
/// let head = Head::new()
/// .add_component(Component::from("<script>console.log('hello');</script>"));
/// ```
///
pub fn add_component(mut self, component: Component) -> Self {
self.additional_components.push(component);
self
}
}

component!(Head);
Expand Down
4 changes: 4 additions & 0 deletionspgml-dashboard/src/components/layouts/head/template.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,4 +97,8 @@
};
</script>
<% } %>

<% for component in additional_components { %>
<%+ component %>
<% } %>
</head>
11 changes: 10 additions & 1 deletionpgml-dashboard/src/components/layouts/marketing/base/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ use crate::components::notifications::marketing::AlertBanner;
use crate::guards::Cluster;
use crate::models::User;
use crate::Notification;
use pgml_components::component;
use pgml_components::{component, Component};
use sailfish::TemplateOnce;
use std::fmt;

Expand DownExpand Up@@ -72,6 +72,15 @@ impl Base {
rsp
}

/// Add a component to the `<head>`.
///
/// See [`Head::add_component`](crate::components::layouts::Head::add_component) for more information.
///
pub fn add_head_component(mut self, component: Component) -> Self {
self.head = self.head.add_component(component);
self
}

pub fn footer(mut self, footer: String) -> Self {
self.footer = Some(footer);
self
Expand Down
11 changes: 11 additions & 0 deletionspgml-dashboard/src/templates/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -163,6 +163,17 @@ impl<'a> WebAppBase<'a> {
self
}

/// Add a component to head (`<head>`).
///
/// # Arguments
///
/// * `component` - The component to add to the head.
///
pub fn add_head_component(&mut self, component: Component) -> &mut Self {
self.head = self.head.clone().add_component(component);
self
}

pub fn render<T>(&mut self, template: T) -> String
where
T: sailfish::TemplateOnce,
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp