Giter VIP home page Giter VIP logo

assetor's Introduction

#Assetor ##Manage CSS, LESS and JS files with this Codeigniter library by Adrian Voicu - Avenirer

###Installation Just copy the files from this package to the corresponding folder in your application folder. For example, copy Assetor/config/assetor.php to application/config/assetor.php.

###Usage In the package you will find example usage code in the Testlib controller. The example code will show you how to use the library.

Set the configuration of the library

$config['version'] = '1';

Set version of css/js to force browser reload assets by adding "?ver=..." at the end of the file call.

$config['css_folder'] = 'assets/css/';

CSS folder relative to the main index.php;

$config['less_folder'] = '';

LESS folder relative to the main index.php. Leave blank if the folder is the same as the css folder

$config['lessphp_folder'] = 'third_party/lessphp/';

LESS compiler folder location relative to the application folder. To compile the LESS files, I use leafo/lessphp

$config['css_min_folder'] = 'assets/css/min/';

Compressed CSS folder relative to the main index.php. Leave blank if the folder is the same as $config['css_folder']

$config['gcc'] = FALSE;

Use Google's Closure Compiler for js compression/minify.

$config['gcc_level'] = 'WHITESPACE_ONLY';

If $config['gcc'] is set to TRUE, choose the level of compilation:

$config['js_folder'] = 'assets/js/';

JS folder relative to the main index.php

$config['js_min_folder'] = 'assets/css/min/';

Compressed/minified JS folder relative to the main index.php. Leave blank if the folder is the same as $config['js_folder']

Load the library

Now we load the library: I would rather load it in a MY_Controller if possible, but it's up to you where you load it

$this->load->library('assetor');

Load the assets

Then we load the assets, be it css, less or js. If we only mention the files, they will all be loaded inside a "main group" of assets. We can load them like this: $this->assetor->load('test.css');

But usually we want to load some files in header and some other files in footer of a file...

$this->assetor->load('style_one.css','header'); $this->assetor->load('style_two.less','header'); $this->assetor->load('script_one.js','header'); $this->assetor->load('script_two.js','header'); $this->assetor->load('style_three.less','footer'); $this->assetor->load('style_four.css','footer'); $this->assetor->load('script_two.js','footer');

Set a version number

If we are working on the styles or scripts and we want to force the browser to reload the files while we work on them we can write: $this->assetor->version(); // only leave without parameter if you know what you're doing... Otherwise you can put a string as parameter: '2.0';

Also, if we are too lazy to work with with the assetor config file, we can set here a version, so that all browsers that will load the site again will be forced to reload the styles/scripts $this->assetor->version('1.2');

Merge the files or Merge and minify them

From here on we have two options: We can choose to merge all the files inside groups with: $this->assetor->merge(). If you are still working on CSS/JS you must write $this->assetor->merge(TRUE); which will force overwriting of the old merged files. This will result in:

  • style_one.css, style_two.less will become one file: header.css
  • script_one.js, script_two.js will become one file: header.js
  • style_three.less, style_four.css will become one file: footer.css
  • script_two.js will become one file: footer.js The files will have no compression applied.

We can choose to minify all the files inside groups with: $this->assetor->minify(). If you are still working on CSS/JS you must write $this->assetor->minify(TRUE); which will force overwriting of the old minified files. This will result in:

  • style_one.css, style_two.less will become one compressed file: header.css
  • script_one.js, script_two.js will become one compressed file: header.js
  • style_three.less, style_four.css will become one compressed file: footer.css
  • script_two.js will become one compressed file: footer.js The files will be compressed (minified).

Generate the html code to call the resulting file(s) and pass the code to variables

After we merged/minified the files, we can generate the html code to call the files

$header_assets = $this->assetor->generate('header'); $footer_assets = $this->assetor->generate('footer');

If we loaded assets without mentioning a group (which defaults to 'main' group), we can simply call $this->assetor->generate()

Send parameters to the view and echo them inside the viewA

After we send $header_assets and $footer_assets to the view in there we do:

echo $header_assets; echo $footer_assets;

Reset library

We can also reset the library with... $this->assetor->clear();

###Copyright

Copyright (C) 2014 @avenirer [[email protected]] Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

DON'T BE A DICK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

Do whatever you like with the original work, just don't be a dick. Being a dick includes - but is not limited to - the following instances: 1a. Outright copyright infringement - Don't just copy this and change the name. 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick. 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick. If you become rich through modifications, related works/services, or supporting the original work, share the love. Only a dick would make loads off this work and not buy the original works creator(s) a pint. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back. License info: http://www.dbad-license.org/

assetor's People

Contributors

avenirer avatar d3rd4v1d avatar

Watchers

James Cloos avatar Nikolya avatar

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.