Layout::Base: stylesheets und javascript auch extern finden
[kivitendo-erp.git] / SL / Layout / Base.pm
index c259044..813db73 100644 (file)
@@ -3,6 +3,7 @@ package SL::Layout::Base;
 use strict;
 use parent qw(Rose::Object);
 
+use File::Slurp qw(read_file);
 use List::MoreUtils qw(uniq);
 use Time::HiRes qw();
 
@@ -19,6 +20,7 @@ use Rose::Object::MakeMethods::Generic (
 
 use SL::Menu;
 use SL::Presenter;
+use SL::System::Process;
 
 my %menu_cache;
 
@@ -38,12 +40,25 @@ sub init_sublayouts_by_name {
 
 sub get {
   $_[0]->sub_layouts;
-  $_[0]->sub_layouts_by_name->{$_[1]}
+  return grep { $_ } ($_[0]->sub_layouts_by_name->{$_[1]});
 }
 
 sub init_auto_reload_resources_param {
-  return '' unless $::lx_office_conf{debug}->{auto_reload_resources};
-  return sprintf('?rand=%d-%d-%d', Time::HiRes::gettimeofday(), int(rand 1000000000000));
+  return sprintf('?rand=%d-%d-%d', Time::HiRes::gettimeofday(), int(rand 1000000000000)) if $::lx_office_conf{debug}->{auto_reload_resources};
+
+  my $git_dir = SL::System::Process::exe_dir() . '/.git';
+
+  return '' unless -d $git_dir;
+
+  my $content = eval { scalar(read_file($git_dir . '/HEAD')) };
+
+  return '' unless ($content // '') =~ m{\Aref: ([^\r\n]+)};
+
+  $content = eval { scalar(read_file($git_dir . '/' . $1)) };
+
+  return '' unless ($content // '') =~ m{\A([0-9a-fA-F]+)};
+
+  return '?rand=' . $1;
 }
 
 ##########################################
@@ -109,6 +124,7 @@ sub _find_stylesheet {
   return "$css_path/$stylesheet" if -f "$css_path/$stylesheet";
   return "css/$stylesheet"       if -f "css/$stylesheet";
   return $stylesheet             if -f $stylesheet;
+  return $stylesheet             if $stylesheet =~ /^http/; # external
 }
 
 sub get_stylesheet_for_user {
@@ -150,6 +166,7 @@ sub _find_javascript {
 
   return "js/$javascript"        if -f "js/$javascript";
   return $javascript             if -f $javascript;
+  return $javascript             if $javascript =~ /^http/;
 }
 
 
@@ -330,7 +347,12 @@ classes, which should be changed. The other points work pretty well.
 
 =head1 BUGS
 
-None yet, if you don't count the horrible stylesheet/javascript interface.
+* stylesheet/javascript interface is a horrible mess.
+
+* It's currently not possible to do compositor layouts without assupmtions
+about the position of the content. That's because the content will return
+control to the actual controller, so the layouts need to know where to split
+pre- and post-content.
 
 =head1 AUTHOR