Part of the EllisLab Network
   
6 of 6
6
AssetLibPro - An advanced CI Asset Library
Posted: 06 March 2009 05:02 PM   [ Ignore ]   [ # 51 ]  
Summer Student
Avatar
Total Posts:  12
Joined  07-08-2008

Ok, this is kind of what I was thinking about.

In the config file - assetlibpro.php

// add an array with the assets to autoload
$config['alp_autoload_css'= array();
$config['alp_autoload_js'= array(); 

In the Library file - Assetlibpro.php

// add these class variables
    
var $autoload_css = array();
    var 
$autoload_js = array();


    
// add this to the constructor
    
$this->autoload_css $this->CI->config->item('alp_autoload_css');
    
$this->autoload_js $this->CI->config->item('alp_autoload_js');
    if ( 
count($this->autoload_css) > 
    
{
        
foreach( $this->autoload_css as $key => $value 
        
{
            $this
->add_css($value);
        
}
    }
    
if ( count($this->autoload_js) > 
    
{
        
foreach( $this->autoload_js as $key => $value 
        
{
            $this
->add_js($value);
        
}
    } 
Profile
 
 
Posted: 11 June 2009 05:28 PM   [ Ignore ]   [ # 52 ]  
Summer Student
Total Posts:  12
Joined  05-31-2009

I must be doing something wrong here.

The page loads OK, but no CSS or JS works - it generates the output, it caches the file, all is apparently working, but it’s the same as if the page had no CSS at all. I even checked the compressed file - it looks OK. I turned GZIP compression off, as my host does not have it on. Could that be it? Apparently it *is* generating the files as it should, but Safari and Firefox don’t seem to recognize it.

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* AssetLibPro - A CodeIgniter Asset Class
*
* @version of AssetLibPro:    1.0.5
*/

/*
|--------------------------------------------------------------------------
| Asset storage
|--------------------------------------------------------------------------
|
| The path to where to storage the joined assets.
| alp_cache_dir_css = "/assets/compressed/" (as example)
|
*/
$config['alp_asset_dir''/';//TRAILING SLASH!
$config['alp_cache_dir_css''/compressed/';//TRAILING SLASH!
$config['alp_cache_dir_js''/compressed/';//TRAILING SLASH!

...

/*
|--------------------------------------------------------------------------
| Toggle CSSTidy/JSMin Compression
|--------------------------------------------------------------------------
|
| Whether to run compression using csstidy or jsmin
|
*/
$config['alp_enable_csstidy'TRUE;
$config['alp_enable_jsmin'TRUE;

/*
|--------------------------------------------------------------------------
| Toggle GZip Compression
|--------------------------------------------------------------------------
|
| Whether to compression the output using gzip
|
*/
$config['alp_gzip_compress_css'FALSE;
$config['alp_gzip_compress_js'FALSE;

/*
|--------------------------------------------------------------------------
| Toggle Browser Caching
|--------------------------------------------------------------------------
|
| Whether to force the browser to cache the files
| (Even with caching enabled web browsers will still detect changes automatically!)
|
*/
$config['alp_force_cache_css'TRUE;
$config['alp_force_cache_js'TRUE;

...

$config['alp_csstidy_basepath']    "/plugins/csstidy/";

$config['alp_csstidy_config'= array(
                                  
'remove_bslash' => TRUE,
                                  
'compress_colors' => TRUE,
                                  
'compress_font-weight' => TRUE,
                                  
'lowercase_s' => FALSE,
                                  
'optimise_shorthands' => 1,
                                  
'remove_last_,' => TRUE,
                                  
'case_properties' => 1,
                                  
'sort_properties' => FALSE,
                                  
'sort_selectors' => FALSE,
                                  
'merge_selectors' => 2,
                                  
'discard_invalid_properties' => FALSE,
                                  
'css_level' => 'CSS2.1',
                                  
'preserve_css' => FALSE,
                                  
'timestamp' => FALSE
                                 
);
$config['alp_csstidy_template'"highest_compression";

/*
|--------------------------------------------------------------------------
| JSmin Config
|--------------------------------------------------------------------------
|
| Enter the path to your jsmin.php file. (relative from BASEPATH)
|
| jsmin = "/system/plugins/jsmin1.1.1.php" (as example)
|
*/
$config['alp_jsmin']    "/plugins/jsmin.php";
?> 
In the controller's constructor:

$this->load->config('
assetlibpro');
$this->load->library('
assetlibpro');

In the controller'
s index (which is the one function that uses itcurrently):

$this->assetlibpro->add_css('css/e3.css');
$this->assetlibpro->add_css('css/lightwindow.css');
$this->assetlibpro->add_js('scripts/scriptaculous.js');
$this->assetlibpro->add_js('scripts/prototype.js');
$this->assetlibpro->add_js('scripts/lightwindow.js'); 
<?php
    
echo $this->assetlibpro->output('all');
?> 
View >> Source code of the view:

<
link rel="stylesheet" href="http://mybaseurl/compressed/css_screen_829ee1f3_287bcf01_09d4b6a4.php" type="text/css" media="screen" /> 
 Signature 


“Give me your mud and I will turn it to gold. ”- Baudelaire

Profile
 
 
Posted: 23 July 2009 04:51 AM   [ Ignore ]   [ # 53 ]  
Grad Student
Avatar
Rank
Total Posts:  45
Joined  09-01-2007

Does this library have any support that enables variables in css?

Profile
 
 
Posted: 23 July 2009 09:19 AM   [ Ignore ]   [ # 54 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  109
Joined  01-21-2009

@Andreia M.  If your still having trouble, you might check out my library called Carabiner.  It provides similar functionality, but without the overhead of PHP based GZIP.  The link to the library forum post is in my signature.

@Skinnpenal  I don’t know of a CI library that offers that functionality.  Carabiner certainly doesn’t, though that would be an interesting feature to implement.  Good luck on your search.

 Signature 

Do you use CSS or JavaScript? Carabiner makes your life easier.  I promise.

CI-Disqus makes playing with the Disqus API a snap.

Profile
 
 
Posted: 30 May 2010 06:23 PM   [ Ignore ]   [ # 55 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  123
Joined  08-21-2009

I published an application to a live server today and none of my stylesheets and javascript worked!

The problem was simple, in the end, and was that my live server has SuPHP installed on it. I wrapped the file-modification functions in the asset library with chmod 775 and chmod 755 for the ‘compressed’ directory. I did note that instead of the usual Apache complaint, CI also handled the error as a 404 (if I navigated to the CSS file) which would be great for the end-user but left me baffled!

This is here for anyone banging their heads on their desks, as an idea of what might cause the problem. I will suggest some ideas/code to the project author to help fix the problem.

Profile
 
 
   
6 of 6
6