[Jifty-commit] r3654 - in jifty/trunk: lib/Jifty lib/Jifty/Plugin lib/Jifty/View/Static

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Jul 10 21:34:35 EDT 2007


Author: trs
Date: Tue Jul 10 21:34:34 2007
New Revision: 3654

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Plugin/CompressedCSSandJS.pm
   jifty/trunk/lib/Jifty/Util.pm
   jifty/trunk/lib/Jifty/View/Static/Handler.pm
   jifty/trunk/lib/Jifty/Web.pm

Log:
 r25118 at zot:  tom | 2007-07-10 21:33:18 -0400
 - Plugin CSS and JS (which should be put in share/plugin/Jifty/Plugin/Foo/web/static/{css,js}) is now compressed by CCJS
 - CCJS can compress more than just main.css by calling Jifty->web->add_css("file.css")


Modified: jifty/trunk/lib/Jifty/Plugin/CompressedCSSandJS.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/CompressedCSSandJS.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/CompressedCSSandJS.pm	Tue Jul 10 21:34:34 2007
@@ -107,20 +107,8 @@
         or Jifty->config->framework('DevelMode') ) {
         Jifty->log->debug("Generating JS...");
 
-        my @roots = (
-            Jifty::Util->absolute_path(
-                File::Spec->catdir(
-                    Jifty->config->framework('Web')->{'StaticRoot'}, 'js'
-                )
-            ),
-
-            Jifty::Util->absolute_path(
-                File::Spec->catdir(
-                    Jifty->config->framework('Web')->{'DefaultStaticRoot'},
-                    'js'
-                )
-            ),
-        );
+        my @roots = map { Jifty::Util->absolute_path( File::Spec->catdir( $_, 'js' ) ) }
+                        Jifty->handler->view('Jifty::View::Static::Handler')->roots;
 
         my $js = "";
 

Modified: jifty/trunk/lib/Jifty/Util.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Util.pm	(original)
+++ jifty/trunk/lib/Jifty/Util.pm	Tue Jul 10 21:34:34 2007
@@ -94,7 +94,8 @@
 =head2 share_root
 
 Returns the 'share' directory of the installed Jifty module.  This is
-currently only used to store the common Mason components.
+currently only used to store the common Mason components, CSS, and JS
+of Jifty and it's plugins.
 
 =cut
 

Modified: jifty/trunk/lib/Jifty/View/Static/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Static/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Static/Handler.pm	Tue Jul 10 21:34:34 2007
@@ -24,7 +24,7 @@
 
 * Static files are served out of a separate root
 * If static files go through apache:
-    * How do we merge together the two static roots?
+    * How do we merge together the N static roots?
 * If static files go through Jifty::Handler
     * We need a flag to allow them to go through the dispatcher, too
     * return "True" (304) for if-modified-since
@@ -61,12 +61,19 @@
     }
     push @roots, (Jifty->config->framework('Web')->{DefaultStaticRoot});
 
-    my $self = {
-        roots => \@roots
-    };
-    bless $self, $class;
+    return bless { roots => \@roots }, $class;
 }
 
+=head2 roots
+
+Returns all the static roots the handler will search
+
+=cut
+
+sub roots {
+    my $self = shift;
+    return wantarray ? @{$self->{roots}} : $self->{roots};
+}
 
 =head2 show $path
 
@@ -155,7 +162,7 @@
     # Chomp a leading "/static" - should this be configurable?
     $file =~ s/^\/*?static//; 
 
-    foreach my $path ( @{$self->{'roots'}} ) {
+    foreach my $path ( $self->roots ) {
         my $abspath = Jifty::Util->absolute_path( File::Spec->catdir($path,$file ));
         # If the user is trying to request something outside our static root, 
         # decline the request

Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm	(original)
+++ jifty/trunk/lib/Jifty/Web.pm	Tue Jul 10 21:34:34 2007
@@ -26,8 +26,10 @@
 );
 
 __PACKAGE__->mk_classdata($_)
-    for qw(cached_css        cached_css_digest        cached_css_time
-           javascript_libs   external_javascript_libs);
+    for qw(cached_css cached_css_digest cached_css_time
+           css_files  javascript_libs   external_javascript_libs);
+
+__PACKAGE__->css_files([qw( main.css )]);
 
 __PACKAGE__->external_javascript_libs([]);
 
@@ -1089,6 +1091,20 @@
     return '';
 }
 
+=head3 add_css FILE1, FILE2, ...
+
+Pushes files onto C<Jifty->web->css_files>
+
+=cut
+
+sub add_css {
+    my $self = shift;
+    Jifty->web->css_files([
+        @{ Jifty->web->css_files },
+        @_
+    ]);
+}
+
 =head3 generate_css
 
 Checks if the compressed CSS is generated, and if it isn't, generates
@@ -1104,29 +1120,15 @@
     {
         Jifty->log->debug("Generating CSS...");
         
-        my $app   = File::Spec->catdir(
-                        Jifty->config->framework('Web')->{'StaticRoot'},
-                        'css'
-                    );
-
-        my $jifty = File::Spec->catdir(
-                        Jifty->config->framework('Web')->{'DefaultStaticRoot'},
-                        'css'
-                    );
-
-        my $file = Jifty::Util->absolute_path(
-                        File::Spec->catpath( '', $app, 'main.css' )
-                   );
-
-        if ( not -e $file ) {
-            $file = Jifty::Util->absolute_path(
-                         File::Spec->catpath( '', $jifty, 'main.css' )
-                    );
-        }
+        my @roots = map { Jifty::Util->absolute_path( File::Spec->catdir( $_, 'css' ) ) }
+                        Jifty->handler->view('Jifty::View::Static::Handler')->roots;
 
-        CSS::Squish->roots( Jifty::Util->absolute_path( $app ), $jifty );
+        CSS::Squish->roots( @roots );
         
-        my $css = CSS::Squish->concatenate( $file );
+        my $css = CSS::Squish->concatenate(
+            map { CSS::Squish->_resolve_file( $_, @roots ) }
+                @{ $self->css_files }
+        );
 
         __PACKAGE__->cached_css( $css );
         __PACKAGE__->cached_css_digest( md5_hex( $css ) );
@@ -1163,7 +1165,7 @@
 directly.
 
 Jifty will look for javascript libraries under share/web/static/js/ by
-default.
+default as well as any plugin static roots.
 
 =cut
 


More information about the Jifty-commit mailing list