EllisLab text mark
Advanced Search
     
Sprinkle - Asset Management Library
Posted: 17 December 2011 05:56 PM   [ Ignore ]
Avatar
Joined: 2007-07-22
69 posts

Greetings everyone,

I know there are some similar libraries (and very good ones, too!) out there but this was somewhat of a hobby of mine (actually, I was experimenting with this for a project and decided to release it publicly).

Here are the main features:

- Asset definitions
- Asset grouping
- Filters (cssmin, jsmin etc)
- Asset routes (for auto-loading assets depending on the route)
- Caching
- Combining assets
- Asset definitions & routes in YAML or pure PHP files
- Asset baking (process assets via cronjob or terminal/command prompt)

The library is available as a spark: http://getsparks.org/packages/Sprinkle/versions/HEAD/show
GitHub: https://github.com/edmundask/Sprinkle

There may be some bugs or limitations that I don’t know about although I tested it in various scenarios. smile

Let me know if you have any use for it. Also, don’t forget to read the wiki to get more information.

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 28 December 2011 09:19 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-22
69 posts

Some people tripped over YAML files due to using tabs instead of spaces in these files. Make sure you use spaces instead of tabs. smile

Also, here is a basic example how to use this library:

1. Load the library

$this->load->spark('sprinkle'); 

2. Define assets

jquery:
  
typejs
  minify
false
  combine
false
  src
http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js 

3. Set up asset routes or load assets from the controller

a) Asset routes

'welcome/(:any)':
  
assets:
    - 
jquery 

b) Load from the controller

$this->sprinkle->load('jquery'); 

4. Output!

echo $this->sprinkle->output(); 
 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 15 January 2012 02:11 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-11
758 posts

good library, will this library work with route defined as in routes.php file, some time we are not giving controller name in route just regular expression or just wildcard like (:any) or (:num) if it work with route please a good example need.

 Signature 

CI,JQuery,Google Maps | widget with CI loader | Thumbnail, Image Resize, Image Crop Helper | CI shortcode

 
Posted: 15 January 2012 10:55 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-22
69 posts

Asset routes work in pretty much the same way as regular CodeIgniter routing. Actually, Sprinkle uses the same code to parse the routes.

A few examples are provided here: https://github.com/edmundask/Sprinkle/wiki/Asset-routes

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 09 February 2012 09:45 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-27
169 posts

hi

is possible to define the order of assets ?

cssfile1,cssfile2 etc

 
Posted: 09 February 2012 10:02 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-22
69 posts

No, there’s no such feature in Sprinkle. Personally I never needed to change the order of assets to be loaded on specific pages. Could you provide with an example?

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 09 February 2012 11:02 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-27
169 posts

hi
thanks for responding

a example
in my project i have a css file for reset, one for forms, one for buttons etc
some files overwrite the properties defined in other files

or some javascript plugins depend on other files to be loaded first

 
Posted: 09 February 2012 12:16 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-27
169 posts

another problem i tried to output a group with

<?php echo $this->sprinkle->output('js-libs');?> 

and works only if i have defined the group also in asset_routes.php using (:any)

is possible to output some assets without defining in routes ?

 
Posted: 09 February 2012 03:15 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-22
69 posts

Yes, it is possible. See the example below.

$this->sprinkle->load('jquery');

$scripts $this->sprinkle->js(
array
(
 
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js'
));

$this->sprinkle->group('js-scripts'$scripts);
$this->sprinkle->group('js-scripts''jquery'); 

Alternatively, you can avoid calling group() method twice by adding the pre-defined asset name to the $scripts array or passing it in as the second parameter of the group() method.

$scripts[] 'jquery';

$this->sprinkle->group('js-scripts'$scripts);

// OR
$this->sprinkle->group('js-scripts'$scripts, array('jquery''some-other-pre-defined-asset-name')); 

Then you can output the group:

$this->sprinkle->output('js-scripts'); 
 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 13 March 2012 02:07 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Joined: 2012-03-13
3 posts

Hi,

First let me say, great library. Easy to use.
I have just ran into some problems though.
Before using the library, my pages were loading in about 60-80ms.
After using the library, they were taking about 5 secs to load.
(ex. By (un)commenting the echo $this->sprinkle->output(); i found this peculiarity)

I’m assuming that by “baking assets” this would fix the problem? However, i followed your baking
tutorial and i appear to get an error. Something to do with the loader, not sure what?

ex.
Unable to connect to your database server using the provided settings.
Filename: /Applications/XAMPP/xamppfiles/htdocs/470repo/projects/main/development/CodeIgniter/third_party/MX/Loader.php
Line Number: 98

Any ideas on this?

 
Posted: 13 March 2012 02:35 PM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-22
69 posts

Hi there,

as mentioned in the wiki, the loading times can significantly increase if assets are fetched from remote locations. That’s because Sprinkle checks HEADER information to see if the file has been renewed (updated).

This is where baking assets comes into play. In the config file you need to set disable_processing option to TRUE.

As for the error that you’re getting, I checked line 98 of that file it I don’t see how that’s related to Sprinkle. Maybe you have a different version of HMVC you the Loader.php file was modified?

Also, which version of PHP are you running? Make sure your setup meets the requirements.

 Signature 

Sprinkle - Asset Management Library | FlamingGrowl - GNTP library | Twiggy - Twig template engine implementation for CodeIgniter
You will have to excuse me for my sometimes poor English.

 
Posted: 14 March 2012 06:39 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2012-03-13
3 posts

I apologize i don’t think it’s a problem with your library. I’m running php 5.3.1 and the latest version of CI.
I think it’s a problem with the CLI controller. I followed this tutorial http://ellislab.com/codeigniter/user-guide/general/cli.html
and that doesn’t provide the proper result as well. Rather it gives the same error as mentioned above.

Could me running a mac make any difference? Sorry, this post might be a bit irrelevant, but i’m just posting
anyways in hopes that u have any idea of what’s going on.

Again, thank you for your help and the great library!