Skip to content
This repository has been archived by the owner on Mar 19, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ceesvanegmond committed Apr 4, 2014
2 parents f4adaac + 7493011 commit 4d7ef9c
Show file tree
Hide file tree
Showing 22 changed files with 671 additions and 368 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
.DS_Store
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
language: php

php:
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev
- composer install --dev --prefer-source --no-interaction

script: phpunit
script: vendor/bin/phpspec run
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Cees van Egmond <cees@ceesvanegmond.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
203 changes: 139 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,139 @@
Laravel4 Minify Package
===============

A Laravel 4 package for minifying your .css and .js. It caches the file with an uniq fingerprint. When you adjust your CSS/JS, your old cached/minified files are deleted, and a new cachefile is placed.


<h3>Installation</h3>
Instal it via composer

Add the following line in your composer.json
<pre>
"ceesvanegmond/minify": "dev-master"
</pre>
Please add the following line in your config/app.php under 'providers'.
<pre>
'CeesVanEgmond\Minify\MinifyServiceProvider',
</pre>
Run command
<pre>
composer update
</pre>

<h3>Config</h3>
You can publish the config file via this command.
<pre>
php artisan config:publish ceesvanegmond/minify
</pre>

Info about the different configurations
<pre>
'ignore_min' => Environments to not minify
'css_path' => The CSS path (from your public) defaults to '/css/'
'css_build_path' => The build path where the minified + concatenate build files are (relative from above aption) defaults to 'builds/'
'js_path' => The JS path (from your public) defaults to '/js/'
'js_build_path' => The build path where the minified + concatenate build files are (relative from above aption) defaults to 'builds/'
</pre>

That's it, you can now start using the package<br>
<b>Notice that the builds dirs have to be writeable by the server</b>

<h3>Usage</h3>
There are two helpers available to use, the 'stylesheet' helper, and the 'javascript' helper
Example to minify your JavaScript (in .blade file)

<pre>
{{ javascript(array(
'jquery-1.9.1.min.js',
'hashchange.js',
'tracer.js',
'includes.js',
'lightbox.js',
'history.js',
'transforms.js',
'main.js',
'ga.js'
))
}}
</pre>

Or CSS

<pre>
{{ stylesheet('main.css') }}
</pre>
# Minify

[![Build Status](https://travis-ci.org/ceesvanegmond/minify.svg?branch=master)](https://travis-ci.org/ceesvanegmond/minify)

With this package you can minify your existing stylessheet and javascript files. This process can be a little tough, this package simplies this process and automates it.

## Installation

Begin by installing this package through Composer.

```js
{
"require": {
"ceesvanegmond/minify": "1.0.*"
}
}
```

### Laravel installation
```php

// app/config/app.php

'providers' => [
'...',
'CeesVanEgmond\Minify\MinifyServiceProvider',
];
```

When you've added the ```MinifyServiceProvider``` an extra ```Minify``` facade is available.
You can use this Facade anywhere in your application

#### Stylesheet
```php
// app/views/hello.blade.php

<html>
<head>
...
{{ Minify::stylesheet('/css/main.css') }}
//or by passing multiple files
{{ Minify::stylesheet(array('/css/main.css', '/css/bootstrap.css')) }}
</head>
...
</html>

```

#### Javascript
```php
// app/views/hello.blade.php

<html>
<body>
...
</body>
{{ Minify::javascript('/js/jquery.js') }}
//or by passing multiple files
{{ Minify::javascript(array('/js/jquery.js', '/js/jquery-ui.js')) }}
</html>

```

### Config
```php
<?php

return array(

/*
|--------------------------------------------------------------------------
| App environments to not minify
|--------------------------------------------------------------------------
|
| These environments will not be minified
|
*/

'ignore_envionments' => array(
'local',
),

/*
|--------------------------------------------------------------------------
| CSS path and CSS build path
|--------------------------------------------------------------------------
|
| Minify is an extention that can minify your css files into one build file.
| The css_path property is the location where your CSS files are located
| The css_builds_path property is the location where the builded files are
| stored. THis is relative to the css_path property.
|
*/

'css_build_path' => '/css/builds/',

/*
|--------------------------------------------------------------------------
| JS path and JS build path
|--------------------------------------------------------------------------
|
| Minify is an extention that can minify your JS files into one build file.
| The JS_path property is the location where your JS files are located
| The JS_builds_path property is the location where the builded files are
| stored. THis is relative to the css_path property.
|
*/

'js_build_path' => '/js/builds/',

);
```

### Without Laravel

```php
<?php
$config = array(
'ignore_envionments' => 'local',
'js_build_path' => '/js/builds/',
'css_builds_path' => '/css/builds',
)
$minify = new CeesVanEgmond\Minify\Providers\Javascript($public_path);
$minify->add($file)

if (in_array($environment, $config['ignore_envionments']))
{
return $provider->tags();
}

if ( ! $minify->make($config['css_build_path'] ) {
$filename = $provider->tag($config['css_build_path'] . $provider->getFilename());
}

$provider->minify();

$filename = $provider->tag($config['css_build_path'] . $provider->getFilename());

```
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"name": "ceesvanegmond/minify",
"keywords": ["minify", "laravel"],
"description": "A Laravel 4 package for minifying your .css and .js. It caches the file with an uniq fingerprint. When you adjust your CSS/JS, your old cached/minified files are deleted, and a new cachefile is placed.",
"description": "A package for minifying styles and javascript ",
"license": "MIT",
"authors": [
{
"name": "Cees van Egmond",
"email": "cees@ceesvanegmond.com"
}
],
"require": {
"php": ">=5.3.7",
"illuminate/support": "~4",
"natxet/cssmin": "3.*",
"linkorb/jsmin-php": "1.*"
"php": ">=5.3.2",
"linkorb/jsmin-php": "1.*",
"natxet/CssMin": "3.*"
},
"require-dev": {
"phpspec/phpspec": "2.0.0",
"mikey179/vfsStream": "1.2.*"
},
"autoload": {
"psr-0": {
"CeesVanEgmond\\Minify": "src/"
},
"files": [
"src/helpers.php"
]
}
},
"license": "MIT"
"minimum-stability": "stable"
}
18 changes: 0 additions & 18 deletions phpunit.xml

This file was deleted.

80 changes: 80 additions & 0 deletions spec/CeesVanEgmond/Minify/Providers/StyleSheetSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php namespace spec\CeesVanEgmond\Minify\Providers;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use org\bovigo\vfs\vfsStream;

class StyleSheetSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('CeesVanEgmond\Minify\Providers\StyleSheet');
}

function it_adds_one_file()
{
vfsStream::setup('css',null, array(
'1.css' => 'a',
));

$this->add(VfsStream::url('css'));
$this->shouldHaveCount(1);
}

function it_adds_multiple_files()
{
vfsStream::setup('root',null, array(
'1.css' => 'a',
'2.css' => 'b',
));

$this->add(array(
VfsStream::url('root/1.css'),
VfsStream::url('root/2.css')
));

$this->shouldHaveCount(2);
}

function it_throws_exception_when_file_not_exists()
{
$this->shouldThrow('CeesVanEgmond\Minify\Exceptions\FileNotExistException')
->duringAdd('foobar');
}

function it_should_throw_exception_when_buildpath_not_exist()
{
$this->shouldThrow('CeesVanEgmond\Minify\Exceptions\DirNotExistException')
->duringMake('bar');
}

function it_should_throw_exception_when_buildpath_not_writable()
{
vfsStream::setup('css',0555, array());

$this->shouldThrow('CeesVanEgmond\Minify\Exceptions\DirNotWritableException')
->duringMake(vfsStream::url('css'));
}

function it_minifies_multiple_files()
{
vfsStream::setup('root',null, array(
'output' => array(),
'1.css' => 'a',
'2.css' => 'b',
));

$this->add(vfsStream::url('root/1.css'));
$this->add(vfsStream::url('root/2.css'));

$this->make(vfsStream::url('root/output'));

$this->getAppended()->shouldBe('ab');

$output = md5('vfs://root/1.css-vfs://root/2.css');
$filemtime = filemtime(vfsStream::url('root/1.css')) + filemtime(vfsStream::url('root/2.css'));
$extension = '.css';

$this->getFilename()->shouldBe($output . $filemtime . $extension);
}
}

0 comments on commit 4d7ef9c

Please sign in to comment.