Diff -- /var/www/vhosts/3dshawn.com/site1/MODS/PageWrapper.pm
Diff
/var/www/vhosts/3dshawn.com/site1/MODS/PageWrapper.pm
added on local at 2026-07-10 18:57:30
Added
+78
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to f3ebd1740b5e
to f3ebd1740b5e
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.| 1 | package MODS::PageWrapper; | |
| 2 | #====================================================================== | |
| 3 | # DriftSense -- page wrapper. | |
| 4 | # | |
| 5 | # Loads TEMPLATES/page_wrapper.html, injects the CGI's rendered body | |
| 6 | # into $page_body, sets branding + active-nav-item tvars, and hands | |
| 7 | # the whole thing back through MODS::Template so its normal tag | |
| 8 | # resolution (variables, [if:...], [url:...]) runs. | |
| 9 | # | |
| 10 | # Usage from a CGI: | |
| 11 | # my $load = MODS::PageWrapper->new; | |
| 12 | # $load->wrapper( | |
| 13 | # page_title => 'Dashboard', | |
| 14 | # page_key => 'dashboard', # sets $active_dashboard = 1 for the sidebar | |
| 15 | # body_html => $rendered_body, | |
| 16 | # userinfo => $u, | |
| 17 | # ); | |
| 18 | #====================================================================== | |
| 19 | use strict; | |
| 20 | use warnings; | |
| 21 | use MODS::Config; | |
| 22 | use MODS::Template; | |
| 23 | ||
| 24 | my $cfg = MODS::Config->new; | |
| 25 | ||
| 26 | sub new { return bless({}, shift); } | |
| 27 | ||
| 28 | sub wrapper { | |
| 29 | my ($self, %args) = @_; | |
| 30 | my $tpl = MODS::Template->new; | |
| 31 | ||
| 32 | my $userinfo = $args{userinfo} || {}; | |
| 33 | my $initials = _initials($userinfo->{display_name} || $userinfo->{email} || 'User'); | |
| 34 | ||
| 35 | my $tvars = { | |
| 36 | # Branding | |
| 37 | brand_name => $cfg->settings('brand_name') || 'DriftSense', | |
| 38 | brand_tagline => $cfg->settings('brand_tagline') || '', | |
| 39 | ||
| 40 | # Page identity | |
| 41 | page_title => $args{page_title} || 'DriftSense', | |
| 42 | page_body => $args{body_html} // (@{$args{body_lines} || []} ? join('', @{$args{body_lines}}) : ''), | |
| 43 | ||
| 44 | # User | |
| 45 | user_name => $userinfo->{display_name} || $userinfo->{email} || 'Operator', | |
| 46 | user_initials => $initials, | |
| 47 | ||
| 48 | # Sidebar active-item flags (page_key sets exactly one) | |
| 49 | active_dashboard => 0, | |
| 50 | active_file_changes => 0, | |
| 51 | active_schema_changes => 0, | |
| 52 | active_table_locks => 0, | |
| 53 | active_named_releases => 0, | |
| 54 | active_databases => 0, | |
| 55 | active_file_monitors => 0, | |
| 56 | active_servers => 0, | |
| 57 | active_containers => 0, | |
| 58 | active_settings => 0, | |
| 59 | }; | |
| 60 | my $key = $args{page_key} || ''; | |
| 61 | $tvars->{"active_$key"} = 1 if exists $tvars->{"active_$key"}; | |
| 62 | ||
| 63 | my @html = $tpl->template('page_wrapper.html', $tvars); | |
| 64 | print @html; | |
| 65 | return; | |
| 66 | } | |
| 67 | ||
| 68 | sub _initials { | |
| 69 | my $s = shift; $s //= ''; | |
| 70 | my @p = split /[\s\@\.]+/, $s, 3; | |
| 71 | my $i = ''; | |
| 72 | $i .= uc(substr($p[0], 0, 1)) if defined $p[0] && length $p[0]; | |
| 73 | $i .= uc(substr($p[1], 0, 1)) if defined $p[1] && length $p[1]; | |
| 74 | $i = uc(substr($s, 0, 1)) unless length $i; | |
| 75 | return $i; | |
| 76 | } | |
| 77 | ||
| 78 | 1; |