Giter Club home page Giter Club logo

assets-ci's Introduction

Simple Assets Library

A simple assets library that has the ability to combine, minify and obfuscate your JavaScript and CSS assets. Additionally there's a LessPHP compiler, a PHPSass compiler and a CoffeeScript compiler.

Third Party Libraries

The libraries JSMin, CSSMin, LessPHP, PHPSass, JS Packer and CoffeeScript-PHP are all created by third parties, but they're included in this package for convenience.

Requirements

  1. PHP 5.3+
  2. CodeIgniter 2.1
  3. Directory structure for the assets files, with a writeable cache directory

Documentation

Set all your preferences in the config file (assets directories, options to minify and combine). Now you can use the helper methods in your views like this:

<?php Assets::css(array('bootstrap.less', 'init.css', 'style.css')); ?>
<?php Assets::js(array('libs/jquery.js', 'script.js', 'bean.coffee')); ?>

You can load the javascript files from the CDN using:

<?php Assets::cdn(array('jquery','jquery-validate','jqueryui'));?>

There's also a method for clearing all cached files:

<?php Assets::clear_cache(); ?>

The default configuration assumes your assets directory is in the root of your project. Be sure to set the permissions for the cache directory so it can be writeable.

Note about "freeze" option: This basicly tells the lib not to scan the files and folders for new and changed files, but to pull all the info from the info.cache file. This speeds up the whole process a little bit. Useful for apps with a bigger load in production.

LESS / SASS / CoffeeScript

Files with extensions .less, .sass, .scss and .coffee will automatically be processed through appropriate libraries.

Groups

There's also a possibility to define groups of assets. This can be useful when for e.g. you want separate scripts in you page header, and others in the footer. This can be accomplished like this:

<?php Assets::js_group('head',   array('libs/modernizr.js')); ?>
<?php Assets::js_group('footer', array('plugins.js', 'script.js')); ?>

For JS groups you can specify a third parameter to apply JavaScript packer regardless of configured option:

<?php Assets::js_group('packed', array('plugins.js', 'script.js'), true); ?> 

The same thing will work with CSS files. You can use this to show groups of CSS files for specific pages:

<?php Assets::css_group('global', array('style.css')); ?>
<?php Assets::css_group('login',  array('login.css')); ?>

Importing CSS files (@import)

Including files via @import should work just fine, just be sure to use proper paths. Example of a stylesheet would be something like this:

@import "bootstrap/bootstrap.less";
@import "libs/fancybox.css";

body { background: #f2f2f2; }

…

Just keep in mind when using @import that those files are not scanned for changes and the cache wont be cleared in case you change a file that is included via @import.

Images

A helper is also provided to display images from the directory setup in the config.

<?php echo Assets::img('logo.png'); ?>

You can also generate the img tag directly using a similar syntax as in the CodeIgniter HTML helper.

<?php echo Assets::img('logo.png', true, array('title' => 'Logo')); ?>

Overriding CI base_url

By default Assets uses codeIgniter's $config['base_url'] config to determine the URL for your assets. However this can be overwritten by defining the following configuration item:

$config['assets']['base_url'] = 'https://example.com';

This will allow you to define your assets on a seperate static domain, or specify https for assets seperately from your CI application.

Frameworks / Libraries

The library has been tested with Twitter Bootstrap 2.0.1 and HTML5 Boilerplate 3.0. It wont work with the latest Bootstrap 2.0.2 because of a problem in LessPHP. I hope this will be fixed soon. And if you happen to use the library with a different framework (bootstrap), give me a shout and I'll put it on this list. So here it is:

  • Twitter Bootstrap 2.0.1 (2.0.2 not working yet) LESS
  • HTML5 Boilerplate 3.0

Directory structure example

/application
/assets
	/cache
	/css
	/images
	/js
/sparks
/system

Bitdeli Badge

assets-ci's People

Contributors

bstrahija avatar francesco-carrella avatar matbeard avatar mikedevita avatar stevenwoodson avatar zaherg 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

assets-ci's Issues

New version of lessc.php fixes Bootstrap issues

I don't know if this is the correct place for this, but I've just updated to the latest version of the LESS compiler (0.3.9) from leafo.net/lessphp and it now works fine with the latest version of Bootstrap (2.3.1).

bootstrap.less and responsive.less now compile correctly.

background image path 404

Hi, i am using assets library but css background image path is not comming proper, my css image path is css/theme/default/d.png

see how it is coming


http://localhost/qahtan/application/themes/admin/assets/css/themes/default///localhost/qahtan/application/themes/admin/assets/css/themes/default///localhost/qahtan/application/themes/admin/assets/css/themes/default///localhost/qahtan/application/themes/admin/assets/css/themes/default/d.png

actual path is this
localhost/qahtan/application/themes/admin/assets/css/themes/default/d.png

Parsing LESS files

This is the first time I have ever used github, so apologies if this is not the correct place for asking questions (if so, perhaps you could point me in the right direction).

I've just setup assets in my CI project and it's great. However, I can't work out how to make use of the LESSPHP facility. I've use it outside of CI in the past, but I'm new to CI also.

Where would I put the .less files and what's the command to compile the .less to .css?

Any pointers would be much appreciated.

Thanks.

Line 988

Shoudnt line 988 be

"if (self::$minify_css and ! self::$freeze and ! self::$_cssmin_loaded)"

instead of

"if (self::$minify_js and ! self::$freeze and ! self::$_cssmin_loaded)"

?

auto clear bug

Hi,

I think there is a bug/possible design flaw:

Scenario: "auto_clear_cache = true"

Page 1:
css_group ("page1", "page1.css")

Page 2:
css_group ("page 2", "page2.css")

When you visit page 1, Page 2 CSS is deleted (because it created a new cache). When you visit Page 2, Page 1 cache is deleted (since you made a new cache). This continues on forever, unless you notice!!!!

This is poorly designed - perhaps it should be only delete Page 1 css file and vice versa?

Angular question

Hi,

I just started using your code and my first impress is very good. Thank you so much!
I have a question.
If I want to merge the angular js code and my script.js, how can I do that?
I tried this way

but after that had been merged and packed, the code didn't work.

I can use this way

<script src="assets/js/vendor/angular-1.2.26/angular.min.js"></script>

but I will get 2 js file with this.

Any idea, suggestion?

Thank you,
L

Update lessc.php to latest version

The less compiler used has been updated to version 0.3.8 which supposedly fixes the Bootstrap problem.

If you replace the assets (0.3.7) version with the new one, CodeIgniter bombs.

Any chance of incorporating it? Thanks

CSSMin Config

CSSMin has a number of config options -see here: http://code.google.com/p/cssmin/wiki/MinifierConfiguration.

Do you think we could have them included in the "assets" config file somehow - so we can set them there?

I'm forced to alter the library with my cssmin config - because the default config breaks my css during minification.

Either way - great library - thanks!

Absolute paths in complied CSS

When CSS is called like this is a view:

<? Assets::css_group('application', array('application.css', 'vendor.css')); ?>

Image URLs are given absolute paths, so if an image path is specified in the CSS as:

.selector {
  background-image: url('/assets/img/ui/header-logo.png');
}

it becomes something like this:

.selector {
  background-image: url('http://10.0.0.43/assets/img/ui/header-logo.png');
}

So when developing and testing the site on different machines and devices, some with localhost some with an IP address, these links break on one or the other... depending on which visited first and created a the CSS in the cache.

Is there a way to turn this off?

Fatal error with coffeescript

Hello, I'm getting this error when attempting to minify my css

Fatal error: Class 'CoffeeScript\yy_Base' not found in /Applications/MAMP/mysite/application/third_party/assets/CoffeeScript/yy/While.php on line 6

Any suggestions?

CSS Minify problem with twitter bootstrap pull-right

Hi i am using this library its great but facing one problem while minify twitter bootstrap css its not showing pull-right css at all in minified css, i have used this library in my two projects with twitter bootstrap facing same problem.

problem when using Assets::js and Assets::js_group

A PHP Error was encountered
Severity: Notice

Message: Undefined property: stdClass::$js

Filename: libraries/assets.php

Line Number: 833

Backtrace:

File: app\libraries\assets.php
Line: 833
Function: _exception_handler

File: app\libraries\assets.php
Line: 189
Function: _generate_tags

i tried everything but i got this all the time

ps : am using CI 3.0-dev

Error HMVC and assets

I did everything OK to load the assets into codeigniter but i cant seem to let the thing work.

If i do an var_dump on the thing it says OK and the boolean returnetd is true.

The current error i get is: Fatal error: Class 'Assets' not found in /home/lemondev/public_html/lemoncms/application/views/welcome_message.php on line 8

What to do now? :(

I also work with HMVC and set every right.. help me please!

cache auto cleared every time i go to a new page

hi:
i have just downloaded your latest code ..
for some reason the cache was auto cleared whenever i go to a new page
here is my cache config options :

<?php
$config['assets']['auto_clear_cache']     = false;
$config['assets']['auto_clear_css_cache'] = false;
$config['assets']['auto_clear_js_cache']  = false;

Enable dynamic URLs in link/script tags

I use SSL a lot on my apps and it'd be great if you could either provide a flag to use // instead of http:// or a flag to force SSL on all.

<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false&amp;callback=init"></script>

useless if statement i think on line 294 [libraries/assets.php]

is there any need for [ if statement ] on line [294]
// Combine
if ($type == 'css' and $this->less_css)
{
//$data .= $contents;
$data .= $this->_process($contents, $type, 'minify', $base_url);
}
else
{
$data .= $this->_process($contents, $type, 'minify', $base_url);
}
i still think its the same with or without the if

Old Version (0.6.1) in assets.php

Version in spark.info says "0.6.2" and in assets.php it still says "0.6.1" which results in errors like:

Severity: Warning
Message: include(sparks/assets/0.6.1/libraries/jsmin.php) [function.include]: failed to open stream: No such file or directory
Filename: libraries/Assets.php
Line Number: 68

first time execution produce this error

hi,
am using version 1.5.0. and the first time i execute the page i got this error

A PHP Error was encountered
Severity: Runtime Notice

Message: Creating default object from empty value

Filename: libraries/assets.php

Line Number: 771

and it will goes away once the info.cache was created ..

Assets:: calls in nested templates generate incorrect paths

Environment

  • PHP 5.3
  • CI 2.1.0
  • Assets 1.5.0 (installed with sparks)

I am using the following template library:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template {
        var $template_data = array();

        function set($name, $value)
        {
            $this->template_data[$name] = $value;
        }

        function view($view, $view_data = array(), $return = FALSE)
        {
            $this->CI =& get_instance();
            $this->load('template', $view, $view_data, $return);
        }

        function load($template = '', $view = '' , $view_data = array(), $return = FALSE)
        {
            $this->CI =& get_instance();
            $this->set('contents', $this->CI->load->view($view, $view_data, TRUE));

            return $this->CI->load->view($template, $this->template_data, $return);
        }
}

Issue

When I render a template with a call to $this->template->view(), the images loaded in the partial get root paths (i.e. /image.png) causing them to be inaccessible, whereas images in the template get rendered with the full and appropriate path/url (i.e. http://sub.domain.tld/assets/img/image.png).

Any idea as to why this would be occuring?

Update

After source-diving a bit in assets.php, it appears as though _set_path() does not get called when rendering the partial but waits until the template gets rendered. However, the Assets::img function gets called when rendering the partial and returns a root path because self::$img_url is null. Thus, after this line $img_path = reduce_double_slashes(self::$img_url.'/'.$path);, $img_path is just '/img_name.ext'.

Update 2

I found that changing Assets::img to call self::init(); at the top of its scope fixes the issue.

Assets::img now looks like this:

<?php

/**
* Return url to image, or event an entire tag
* @param  string $path
*/
public static function img($path = null, $tag = false, $properties = null)
{
    self::init();  // ADDED THIS LINE

    $img_path = reduce_double_slashes(self::$img_url.'/'.$path);

    // Properties
    if ($properties) $properties['src'] = $img_path;

    log_message('error', $img_path);

    // Tag?
    if ($tag) return img($properties);
    else      return $img_path;
}

?>

feature request, option to load / not load the coffee library

adding an option to load or not to load the coffee library files ..
for example am using a pure css and js files so i dont need it to load the coffee library ( and its a huge number of files to be honest ) ..

so i think it will be nice if we have put an option to load it or not load it ..

adding a prefix to the cache files

i was wondering since you didnt push the version yet ..
why not to add an option which will help to add a prefix to the combined ( or the single ) cached files, instead of using the time stamp ..

i will try to do it if you like me to help ...

Autoloading Not working in 2.1.0

I am in the process of upgrading to 2.1.0 and after following the instructions in the CodeIgniter documentation I now get the following error:

Fatal error: Call to undefined function display_css()

Update

It would appear the problem is only when this spark is being autoloaded. So I believe it is something to do with the Sparks ci_autoloader and not an asset related issue.

Only a blank page

Hello!

Im trying to install and configure your library but app breaks on Assets:css function.
Only a blank page.
Im using HMVC and a template library.

Ty for your support.

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.