Giter Site home page Giter Site logo

asset's Introduction

/*
 * Asset Packer CakePHP Plugin
 * Copyright (c) 2010 Matt Curry
 * www.PseudoCoder.com
 * http://github.com/mcurry/asset
 *
 * @author      Matt Curry <[email protected]>
 * @license     MIT
 *
 */

/* Notes */
    * JavaScript packing only works with PHP5. If you're using PHP4 the scripts will still be merged into one file, but not packed.
    * A sample .htaccess file is included in the zip. Rename it and drop it in output dirs for improved performance.

/* Instructions */
   1. You'll need a working version of CakePHP installed. This is running on 1.3.4 stable.
   2. Download jsmin 1.1.0 or later and put it in vendors/jsmin.
   3. Download CSSTidy 1.3 or later and put the contents in vendors/csstidy.
   4. Download the plugin to /app/plugins/asset.
   5. Include the helper in any controller that will need it. Most likely you will put it in AppController so that it's available to all your controllers:
      var $helpers = array('Asset.asset');

   6. In your layout and views include Javascript files as you normally would when using the $scripts_for_layout approach:
      $javascript->link('jquery', false);

   7. Similarly include your css with the inline option set to false:
      $html->css('style', null, null, false);

   8. Then in your layout file, in the head section, instead of using $scripts_for_layout call the helper:
      echo $asset->scripts_for_layout();

/* Options */
   Options are set when including the helper.
   var $helpers = array('Asset.asset' => array('optionName' => 'optionValue'));
   
	 * debug, default: false
     Cake debug = 0  packed js/css returned.  $this->options['md5FileName']options['debug'] doesn't do anything.
     Cake debug > 0, $this->options['md5FileName']options['debug'] = false    essentially turns the helper off.  js/css not packed.  Good for debugging your js/css files.
     Cake debug > 0, $this->options['md5FileName']options['debug'] = true     packed js/css returned.  Good for debugging this helper.
		
	 * checkTs, default: false
     there is a *minimal* perfomance hit associated with looking up the filemtimes
     if you clean out your cached dir (as set below) on builds then you don't need this.

	 * md5FileName, default: false
     the packed files are named by stringing together all the individual file names
     this can generate really long names, so by setting this option to true
     the long name is md5'd, producing a resonable length file name.

	 * searchPaths, default: array()
     Additional paths for searching for css/js
     
	 * cachePaths, default: array('css' => 'ccss', 'js' => 'cjs')
     Paths for storing the compressed files, relative to your webroot
		
	 * cssCompression, default: high_compression
     default, low_compression, high_compression, highest_compression
		
	 * fixCssImg, default: false
     replace relative img paths in css files with full http://...
    
/* Tips */
   * Remember to set the inline option to false for JS and CSS in your layout if you want them to be packed with the view scripts.
   * Setting DEBUG on will cause this helper to output the scripts the same way $scripts_for_layout would, effectifly turning it off while testing.
   * If you get a JavaScript error with a packed version of a file it's most likely missing a semi-colon somewhere.
   * Order is important. If you include script1 then script2 on one view and script2 then script1 on another, they will generate separate packed versions and will be treated by the browser as separate scripts.

asset's People

Contributors

lecterror avatar mcurry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

asset's Issues

Warning

This warning appears when no parameter is not passed in the variable helper.

var $helpers = array('Asset.asset');

Warning (2): array_merge() [http://php.net/function.array-merge]: Argument #2 is not an array [APP/plugins/asset/views/helpers/asset.php, line 66]

create new methods for css and js

Can you create new methods in the helper that will allow one to echo out css and js individually? I'd like to be able to move my minimized/combined JS to the bottom of my html and keep the css minimized/combined in the . Currently you can only echo them out together.

I'd be willing to take a shot at writing the code if you like.

csstidy and localization

csstidy convert attribute values with php floatval function
if the current locale uses comma as decimal separator (or any other character instead of period) the resulting css file gets broken.

codeblock isn't printing

I'm using default installation of the plugin. Layout has

echo $asset->scripts_for_layout(array('js','codeblock'));

An elment is using

echo $this->Javascript->codeBlock($jsCode, array('inline' => 'false'));

But the code isn't echoed out to the layout.

When I tried with debug 0, the scripts that are included using $this->Javascript->link() also doesn't get printed out..

Am I doing something wrong?

minifying files in theme folders

the plugin seems to not be able to pick up assets that are in a theme folder (located at /app/views/themed/nameOfTheme/webroot/css) when used with cakePHP 1.3

can't add script after init

If I try to add script after calling $asset->scripts_for_layout()
the script won't be added.

ie.
in my layout I echo the css file inside head tag and I add scripts later in body page.
<html>
<head>
<?php echo $asset->scripts_for_layout('css');?>
</head>
<body>
this element add scriptblocks to view
<?php $this->element('banner');?>

<?php echo $asset->scripts_for_layout('codeblock');?>
</body>
</html>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.