Skip to content

Commit

Permalink
make js paths configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Gugger committed Nov 14, 2024
1 parent ae662c3 commit 26b99ac
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/azure_auth/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ fn create_actix_admin_builder() -> ActixAdminBuilder {
navbar_title: "ActixAdmin Example",
user_tenant_ref: None,
base_path: "/admin",
custom_css_paths: None
custom_css_paths: None,
custom_js_paths: None
};

let mut admin_builder = ActixAdminBuilder::new(configuration);
Expand Down
1 change: 1 addition & 0 deletions examples/basic/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fn create_actix_admin_builder() -> ActixAdminBuilder {
user_tenant_ref: None,
base_path: "/admin",
custom_css_paths: None,
custom_js_paths: None
};

let mut admin_builder = ActixAdminBuilder::new(configuration);
Expand Down
3 changes: 2 additions & 1 deletion examples/chat_support/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ fn create_actix_admin_builder() -> ActixAdminBuilder {
navbar_title: "ActixAdmin Example",
user_tenant_ref: None,
base_path: "/absproxy/5000/admin",
custom_css_paths: None
custom_css_paths: None,
custom_js_paths: None
};

let mut admin_builder = ActixAdminBuilder::new(configuration);
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ pub struct ActixAdminConfiguration {
pub file_upload_directory: &'static str,
pub navbar_title: &'static str,
pub base_path: &'static str,
pub custom_css_paths: Option<Vec<String>>
pub custom_css_paths: Option<Vec<String>>,
pub custom_js_paths: Option<Vec<String>>
}

#[derive(Clone)]
Expand Down
1 change: 1 addition & 0 deletions src/routes/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub fn add_auth_context(session: &Session, actix_admin: &ActixAdmin, ctx: &mut C
let enable_auth = &actix_admin.configuration.enable_auth;
ctx.insert("enable_auth", &enable_auth);
ctx.insert("custom_css_paths", &actix_admin.configuration.custom_css_paths);
ctx.insert("custom_js_paths", &actix_admin.configuration.custom_js_paths);
ctx.insert("navbar_title", &actix_admin.configuration.navbar_title);
ctx.insert("base_path", &actix_admin.configuration.base_path);
ctx.insert("support_path", &actix_admin.support_path.as_ref());
Expand Down
16 changes: 11 additions & 5 deletions src/templates/bootstrapv5/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
<title>{{ navbar_title }}</title>

{% if custom_css_paths %}
{% for custom_css_path in custom_css_paths %}
<link rel="stylesheet" href="{{ custom_css_path }}">
{% endfor %}
{% for custom_css_path in custom_css_paths %}
<link rel="stylesheet" href="{{ custom_css_path }}">
{% endfor %}
{% else %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
{% endif %}

{% if custom_js_paths %}
{% for custom_js_path in custom_js_paths %}
<script src="{{ custom_js_path }}"></script>
{% endfor %}
{% else %}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<script src="https://unpkg.com/[email protected]"></script>
{% endif %}

<script>
document.onkeydown = function (e) {
Expand Down
10 changes: 8 additions & 2 deletions src/templates/bulma/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
{% endfor %}
{% else %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
{% endif %}

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<script src="https://unpkg.com/[email protected]"></script>
{% if custom_js_paths %}
{% for custom_js_path in custom_js_paths %}
<link rel="stylesheet" href="{{ custom_js_path }}">
{% endfor %}
{% else %}
<script src="https://unpkg.com/[email protected]"></script>
{% endif %}

<script>
document.onkeydown = function (e) {
Expand Down
3 changes: 2 additions & 1 deletion tests/test_setup/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ pub fn create_actix_admin_builder(
file_upload_directory: "./file_uploads",
navbar_title: "test",
base_path: "/admin",
custom_css_paths: None
custom_css_paths: None,
custom_js_paths: None,
};

let mut admin_builder = ActixAdminBuilder::new(configuration);
Expand Down

0 comments on commit 26b99ac

Please sign in to comment.