Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
304122eb
Commit
304122eb
authored
Apr 19, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug in yiic.php.
Refactoring AssetConverter.
parent
c7cf1026
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
9 deletions
+64
-9
Application.php
framework/console/Application.php
+1
-0
ScriptController.php
framework/console/controllers/ScriptController.php
+27
-0
AssetConverter.php
framework/web/AssetConverter.php
+22
-5
IAssetConverter.php
framework/web/IAssetConverter.php
+11
-0
yiic.php
framework/yiic.php
+3
-4
No files found.
framework/console/Application.php
View file @
304122eb
...
...
@@ -129,6 +129,7 @@ class Application extends \yii\base\Application
'migrate'
=>
'yii\console\controllers\MigrateController'
,
'app'
=>
'yii\console\controllers\AppController'
,
'cache'
=>
'yii\console\controllers\CacheController'
,
'script'
=>
'yii\console\controllers\ScriptController'
,
);
}
...
...
framework/console/controllers/ScriptController.php
0 → 100644
View file @
304122eb
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\console\controllers
;
use
Yii
;
use
yii\console\Exception
;
use
yii\console\Controller
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
ScriptController
extends
Controller
{
public
$defaultAction
=
'combo'
;
public
function
actionCombo
(
$configFile
)
{
}
}
\ No newline at end of file
framework/web/AssetConverter.php
View file @
304122eb
...
...
@@ -11,18 +11,32 @@ use Yii;
use
yii\base\Component
;
/**
* AssetConverter supports conversion of several popular script formats into JS or CSS scripts.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
AssetConverter
extends
Component
implements
IAssetConverter
{
/**
* @var array the commands that are used to perform the asset conversion.
* The keys are the asset file extension names, and the values are the corresponding
* target script types (either "css" or "js") and the commands used for the conversion.
*/
public
$commands
=
array
(
'less'
=>
array
(
'css'
,
'lessc
%s %s
'
),
'scss'
=>
array
(
'css'
,
'sass
%s %s
'
),
'sass'
=>
array
(
'css'
,
'sass
%s %s
'
),
'styl'
=>
array
(
'js'
,
'stylus <
%s > %s
'
),
'less'
=>
array
(
'css'
,
'lessc
{from} {to}
'
),
'scss'
=>
array
(
'css'
,
'sass
{from} {to}
'
),
'sass'
=>
array
(
'css'
,
'sass
{from} {to}
'
),
'styl'
=>
array
(
'js'
,
'stylus <
{from} > {to}
'
),
);
/**
* Converts a given asset file into a CSS or JS file.
* @param string $asset the asset file path, relative to $basePath
* @param string $basePath the directory the $asset is relative to.
* @param string $baseUrl the URL corresponding to $basePath
* @return string the URL to the converted asset file.
*/
public
function
convert
(
$asset
,
$basePath
,
$baseUrl
)
{
$pos
=
strrpos
(
$asset
,
'.'
);
...
...
@@ -33,7 +47,10 @@ class AssetConverter extends Component implements IAssetConverter
$result
=
substr
(
$asset
,
0
,
$pos
+
1
)
.
$ext
;
if
(
@
filemtime
(
"
$basePath
/
$result
"
)
<
filemtime
(
"
$basePath
/
$asset
"
))
{
$output
=
array
();
$command
=
sprintf
(
$command
,
"
$basePath
/
$asset
"
,
"
$basePath
/
$result
"
);
$command
=
strtr
(
$command
,
array
(
'{from}'
=>
"
$basePath
/
$asset
"
,
'{to}'
=>
"
$basePath
/
$result
"
,
));
exec
(
$command
,
$output
);
Yii
::
info
(
"Converted
$asset
into
$result
: "
.
implode
(
"
\n
"
,
$output
),
__METHOD__
);
return
"
$baseUrl
/
$result
"
;
...
...
framework/web/IAssetConverter.php
View file @
304122eb
...
...
@@ -8,10 +8,20 @@
namespace
yii\web
;
/**
* The IAssetConverter interface must be implemented by asset converter classes.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
interface
IAssetConverter
{
/**
* Converts a given asset file into a CSS or JS file.
* @param string $asset the asset file path, relative to $basePath
* @param string $basePath the directory the $asset is relative to.
* @param string $baseUrl the URL corresponding to $basePath
* @return string the URL to the converted asset file. If the given asset does not
* need conversion, "$baseUrl/$asset" should be returned.
*/
public
function
convert
(
$asset
,
$basePath
,
$baseUrl
);
}
\ No newline at end of file
framework/yiic.php
View file @
304122eb
...
...
@@ -14,10 +14,9 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require
(
__DIR__
.
'/yii.php'
);
$id
=
'yiic'
;
$basePath
=
__DIR__
.
'/console'
;
$application
=
new
yii\console\Application
(
$id
,
$basePath
,
array
(
$application
=
new
yii\console\Application
(
array
(
'id'
=>
'yiic'
,
'basePath'
=>
__DIR__
.
'/console'
,
'controllerPath'
=>
'@yii/console/controllers'
,
));
$application
->
run
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment