[Rt-commit] rt branch, 4.2/auto-discover-stylesheets, created. rt-4.2.4-15-g5b72ae1

? sunnavy sunnavy at bestpractical.com
Sat May 17 04:04:21 EDT 2014


The branch, 4.2/auto-discover-stylesheets has been created
        at  5b72ae16e97e8bc7c80a76f35605e77e9c74e365 (commit)

- Log -----------------------------------------------------------------
commit 5b72ae16e97e8bc7c80a76f35605e77e9c74e365
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat May 17 15:35:03 2014 +0800

    auto discover available stylesheets
    
    they are actually directory names in static/css/
    see also #14667

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 40dcec1..0ec23bb 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -53,6 +53,7 @@ use warnings;
 
 use File::Spec ();
 use Symbol::Global::Name;
+use List::MoreUtils 'uniq';
 
 =head1 NAME
 
@@ -138,6 +139,7 @@ can be set for each config optin:
 
 =cut
 
+my @stylesheets;
 our %META;
 %META = (
     # General user overridable options
@@ -201,8 +203,25 @@ our %META;
         Widget          => '/Widgets/Form/Select',
         WidgetArguments => {
             Description => 'Theme',                  #loc
-            # XXX: we need support for 'get values callback'
-            Values => [qw(rudder web2 aileron ballard)],
+            Callback    => sub {
+                unless (@stylesheets) {
+                    for my $static_path ( RT::Interface::Web->StaticRoots ) {
+                        my $css_path =
+                          File::Spec->catdir( $static_path, 'css' );
+                        next unless -d $css_path;
+                        if ( opendir my $dh, $css_path ) {
+                            push @stylesheets, grep {
+                                -e File::Spec->catfile( $css_path, $_, 'base.css' )
+                            } readdir $dh;
+                        }
+                        else {
+                            RT->Logger->error("Can't read $css_path: $!");
+                        }
+                    }
+                    @stylesheets = sort { lc $a cmp lc $b } uniq @stylesheets;
+                }
+                return { Values => \@stylesheets };
+            },
         },
         PostLoadCheck => sub {
             my $self = shift;

-----------------------------------------------------------------------


More information about the rt-commit mailing list