GithubHelp home page GithubHelp logo

assetla's Introduction

Assetla

A wrapper for Assetic.

Code Climate Travis CI

Configuration File

Make modules for your CSS and JavaScript files. These files can be *.css, *.sass, *.coffee, and *.js.

array(
    'output_path' => 'assets',
    'modules' => array(
        'admin_core' => array(
            'css' => array(
                'media/css/admin/reset.css',
                'media/css/admin/text.css',
                'media/css/admin/fluid.css',
                'media/css/admin/core/button.scss', // SCSS
            ),
            'js' => array(
                'media/js/admin/jquery-1.8.1.min.js',
                'media/js/admin/jquery.mousewheel-min.js',
                'media/js/admin/event.coffee', // COFFEE
            ),
        ),
    ),
);
```


## Usage

### General Usage

```php
<?php $assetla = new Assetla('config.php'); ?>
<?php echo $assetla->stylesheet_tags('admin_core'); ?>
<?php echo $assetla->javascript_tags('admin_core'); ?>
```

It will output the following HTML.

```html
<!-- admin_core.css (start) -->
<link type="stylesheet" href="media/css/admin/reset.css"/>
<link type="stylesheet" href="media/css/admin/text.css"/>
<link type="stylesheet" href="media/css/admin/fluid.css"/>
<link type="stylesheet" href="assets/button.css "/> <!-- button.scss -->
<!-- admin_core.css (end) -->
<!-- admin_core.js (end) -->
<script src="media/js/admin/jquery-1.8.1.min.js"></script>
<script src="media/js/admin/jquery.mousewheel-min.js"></script>
<script src="assets/event.js"></script> <!-- event.coffee -->
<!-- admin_core.js (end) -->
```

### Concatenate

Or you can concatenate to single file for less requests.

```php
<?php echo Assetla::stylesheet_tags('admin_core', true); ?>
<?php echo Assetla::javascript_tags('admin_core', true); ?>
```

It will output the following HTML.

```html
<!-- admin_core.css (start) -->
<link type="stylesheet" href="assets/admin_core.css"/>
<!-- admin_core.css (end) -->
<!-- admin_core.js (end) -->
<script src="assets/admin_core.js"></script>
<!-- admin_core.js (end) -->
```

### For Precompiliation

Execute the following command.

```
vendor/assetla/bin/assetla precompile config.php
```

It will do minification, concatenation, and overwriting the configuration tasks.

```php
array(
    'modules' => array(
        'admin_core' => array(
            'css' => 'media/css/admin_core_31a85b.min.css',
            'js' => 'media/js/admin_core_6f5a8a.min.js'
        ),
    ),
);
```

### For Deployment

Currently it only supports S3. You need to provide some information in `config.php`.

```php
return array(
    'deploy' => array( // For S3 deployment
        'key' => '<api-public-key>',
        'secret' => '<api-secret-key>',
        'acl' => '<public-read>',
        'bucket' => '<bucket-name>',
        'path' => '<save-path>'
    ),
    // other settings        
),
```

Similar to precompilation, but it saves file to S3 instead.

````php
array(
    'modules' => array(
        'admin_core' => array(
            'css' => 'https://<bucket-name>.s3.amazonaws.com/<path>/admin_core_31a85b.min.css',
            'js' => 'https://<bucket-name>.s3.amazonaws.com/<path>/admin_core_6f5a8a.min.js'
        ),
    ),
);

Installation

  1. Grab the code [email protected]:josephj/assetla.git

  2. You need to install several different packages from different package management systems. These steps make sure you could get required compilers (ex. SASS, CoffeeScript, and UglifyJS) installed in local directory.

  3. composer install

  4. bundle install --path vendor/bundler

  5. npm install .

  6. Create a writable folder for outputing the compiled files.

    mkdir assets/out
    chmod 777 assets/out
    
  7. Set config

    return array(
        'output_path' => 'assets/out',
        'modules' => array(
            'welcome' => array(
                'css' => array(
                    'assets/css/foo.sass',
                ),
                'js' => array(
                    'assets/js/bar.coffee',
                ),
            ),
        ),
    );
  8. Sample PHP view file using Assetla:

    <?php
    require 'vendor/autoload.php';
    $assetla = new Assetla('config.php');
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="created" content="2014-09-02">
    <title>Welcome</title>
    <?php echo $assetla->stylesheet_tags('welcome'); ?>
    </head>
    <body>
        <h1>Welcome</h1>
        <div>
           <p>Hello World!</p>
        </div>
        <?php echo $assetla->javascript_tags('welcome'); ?>
    </body>
    </html>

assetla's People

Contributors

josephj avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

assetla's Issues

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.