inthraonsap/carabiner

使用minify js和css文件(额外功能:您可以将php代码放入JavaScript文件中。)

dev-master 2017-10-21 11:08 UTC

This package is not auto-updated.

Last update: 2024-09-24 06:51:47 UTC


README

Carabiner是一个js/css压缩包。我修改了一些代码使其与Laravel4兼容,并添加了一些功能以使其能够编译php代码。当您在处理双语言网站或需要将一些php数据发送到JavaScript文件等情况时,这是一个很好的包。

安装

将"inthraonsap/carabiner": "dev-master"添加到composer.json文件中。

{
  "require": {
    "inthraonsap/carabiner": "dev-master"
  }
}

运行composer update CLI。

$ composer update

在app/config/目录下的app.php文件中,按照以下步骤操作。

'providers' => array(
  ...,
  'Inthraonsap\Carabiner\CarabinerServiceProvider',
  ...
),
'aliases' => array(
  ...,
  'Carabiner'   => 'Inthraonsap\Carabiner\Facades\Carabiner',
  ...
)

使用artisan CLI发布配置文件。

$ php artisan config:publish inthraonsap/carabiner

用法

配置

此包的配置文件。

return array(
    /*
    |--------------------------------------------------------------------------
    | Script Directory
    |--------------------------------------------------------------------------
    |
    | Path to the script directory.
    | Relative to the public-Folder
    |
    */
    'scriptDir' => '/',
/*
|--------------------------------------------------------------------------
| Style Directory
|--------------------------------------------------------------------------
|
| Path to the style directory.
| Relative to the public-Folder
|
*/
'styleDir' => '/',
/*
|--------------------------------------------------------------------------
| Cache Directory
|--------------------------------------------------------------------------
|
| Path to the cache directory. Must be writable.
| Relative to the public-Folder
|
*/
'cacheDir' => 'cache/',

/*
 * Base url for file location.
 */
'base_uri' => URL::to('/').'/',

/*
|--------------------------------------------------------------------------
| Combine
|--------------------------------------------------------------------------
|
| Flags whether files should be combined. Defaults to TRUE.
|
*/
'combine' => TRUE,


/*
|--------------------------------------------------------------------------
| Development Flag
|--------------------------------------------------------------------------
|
|  Flags whether your in a development environment or not. Defaults to FALSE.
|
*/
'dev' => FALSE,

/*
|--------------------------------------------------------------------------
| Minify Javascript
|--------------------------------------------------------------------------
|
| Global flag for whether JS should be minified. Defaults to TRUE.
|
*/
'minify_js' => TRUE,

/*
|--------------------------------------------------------------------------
| Minify CSS
|--------------------------------------------------------------------------
|
| Global flag for whether CSS should be minified. Defaults to TRUE.
|
*/

'minify_css' => TRUE,

/*
|--------------------------------------------------------------------------
| Force cURL
|--------------------------------------------------------------------------
|
| Global flag for whether to force the use of cURL instead of file_get_contents()
| Defaults to FALSE.
|
*/

'force_curl' => FALSE,

/*
|--------------------------------------------------------------------------
| Predifined Asset Groups
|--------------------------------------------------------------------------
|
| Any groups defined here will automatically be included.  Of course, they
| won't be displayed unless you explicity display them ( like this: Carabiner::display('jquery') )
| See docs for more.
|
*/
'groups' =>  array(),

/**
 * character encoding for javascript tag.
 * Default: UTF-8
 */
'charset' => 'UTF-8',

/**
 * Choose a compiler for javascript file.(It works once you use Carabiner::compileJs())
 * Options: php | blade
 * ex. php
 *      alert("<?php echo 'print some text'; ?>");
 * ex. blade
 *      alert("{{{ print some text }}}");
 * Default: php
 */
'compiler' => 'php'

);

方法

处理资源

/** 
* Add JS file to queue
* @param	String of the path to development version of the JS file.  Could also be an array, or array of arrays. (ex. "assets/js/jquery.js")
* @param	String of the path to production version of the JS file. NOT REQUIRED
* @param	Boolean flag whether the file is to be combined. NOT REQUIRED
* @param	String of the group name with which the asset is to be associated. NOT REQUIRED
* @return   Void
*/
Carabiner::js($dev_file, $prod_file = '', $combine = TRUE, $minify = TRUE, $group = 'main');

/**

  • Add CSS file to queue
  • @param String of the path to development version of the CSS file. Could also be an array, or array of arrays. (ex. "assets/css/layout.css")
  • @param String of the media type, usually one of (screen, print, handheld) for css. Defaults to screen.
  • @param String of the path to production version of the CSS file. NOT REQUIRED
  • @param Boolean flag whether the file is to be combined. NOT REQUIRED
  • @param Boolean flag whether the file is to be minified. NOT REQUIRED
  • @param String of the group name with which the asset is to be associated. NOT REQUIRED
  • @return Void */ Carabiner::css($dev_file, $media = 'screen', $prod_file = '', $combine = TRUE, $minify = TRUE, $group = 'main')

/**

  • Adding js file to queue with blade or php compiler.
  • @param string $dev_file is String of the path to development version of the JS file. Could also be an array, or array of arrays. (ex. "assets/js/jquery.js")
  • @param type $args is Array of variable that you want to send to js view. (ex. array("name"=>"Inthra Onsap")).
  • @param string $prod_file is String of the path to production version of the JS file. NOT REQUIRED
  • @param type $combine is Boolean flag whether the file is to be combined. NOT REQUIRED
  • @param type $minify is Boolean flag whether the file is to be minified. NOT REQUIRED
  • @param type $group is String of the group name with which the asset is to be associated. NOT REQUIRED
  • @return Void */ Carabiner::compileJs($dev_file, $args = array(), $prod_file = '', $combine = TRUE, $minify = TRUE, $group = 'main'){

// Display css Carabiner::display('css');

//display js Carabiner::display('js');

// display both Carabiner::display(); // OR Carabiner::display('both');

// display group Carabiner::display('jquery'); // group name defined as jquery

// display filterd group Carabiner::display('main', 'js'); // group name defined as main, only display JS

// return string of asset references $string = Carabiner::display_string('main');

// clear css cache Carabiner::empty_cache('css');

//clear js cache Carabiner::empty_cache('js');

// clear both Carabiner::empty_cache(); // OR Carabiner::empty_cache('both');

// clear before a certain date Carabiner::empty_cache('both', 'now'); // String denoting a time before which cache // files will be removed. Any string that // strtotime() can take is acceptable. // Defaults to 'now'.

致谢

所有致谢归功于原始开发者。 https://github.com/EllisLab/CodeIgniter/wiki/Carabinerhttps://github.com/weboAp/laravel4-carabiner

支持或联系

如果您发现任何问题,请通过inthra.onsap@gmail.com与我联系。