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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
2f526521
Commit
2f526521
authored
Aug 30, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new asset WIP
parent
f6e1d572
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
134 additions
and
64 deletions
+134
-64
.bowerrc
apps/advanced/.bowerrc
+2
-3
.gitkeep
apps/advanced/assets/.gitkeep
+0
-0
bower.json
apps/advanced/bower.json
+1
-1
index.php
apps/advanced/environments/index.php
+11
-0
.bowerrc
apps/advanced/frontend/.bowerrc
+0
-4
bower.json
apps/advanced/frontend/bower.json
+0
-8
.gitkeep
apps/advanced/frontend/web/assets/.gitkeep
+0
-1
init
apps/advanced/init
+10
-0
DatePicker.php
extensions/jui/DatePicker.php
+13
-8
DatePickerLanguageAsset.php
extensions/jui/DatePickerLanguageAsset.php
+9
-3
AssetBundle.php
framework/web/AssetBundle.php
+58
-0
AssetManager.php
framework/web/AssetManager.php
+27
-33
View.php
framework/web/View.php
+3
-3
No files found.
apps/advanced/
backend/
.bowerrc
→
apps/advanced/.bowerrc
View file @
2f526521
{
"directory" : "web/assets"
}
\ No newline at end of file
"directory" : "assets"
}
apps/advanced/
backend/web/
assets/.gitkeep
→
apps/advanced/assets/.gitkeep
View file @
2f526521
File moved
apps/advanced/b
ackend/b
ower.json
→
apps/advanced/bower.json
View file @
2f526521
{
"name"
:
"yii2-advanced
-backend
"
,
"name"
:
"yii2-advanced"
,
"version"
:
"1.0.0"
,
"dependencies"
:
{
},
...
...
apps/advanced/environments/index.php
View file @
2f526521
...
...
@@ -18,6 +18,9 @@
* 'setCookieValidationKey' => [
* // list of config files that need to be inserted with automatically generated cookie validation keys
* ],
* 'createSymlink' => [
* // list of symlinks to be created. Keys are symlinks, and values are the targets.
* ],
* ],
* ];
* ```
...
...
@@ -38,6 +41,10 @@ return [
'backend/config/main-local.php'
,
'frontend/config/main-local.php'
,
],
'createSymlink'
=>
[
'frontend/web/assets'
=>
'assets'
,
'backend/web/assets'
=>
'assets'
,
],
],
'Production'
=>
[
'path'
=>
'prod'
,
...
...
@@ -54,5 +61,9 @@ return [
'backend/config/main-local.php'
,
'frontend/config/main-local.php'
,
],
'createSymlink'
=>
[
'frontend/web/assets'
=>
'assets'
,
'backend/web/assets'
=>
'assets'
,
],
],
];
apps/advanced/frontend/.bowerrc
deleted
100644 → 0
View file @
f6e1d572
{
"directory" : "web/assets"
}
\ No newline at end of file
apps/advanced/frontend/bower.json
deleted
100644 → 0
View file @
f6e1d572
{
"name"
:
"yii2-advanced-frontend"
,
"version"
:
"1.0.0"
,
"dependencies"
:
{
},
"devDependencies"
:
{
}
}
apps/advanced/frontend/web/assets/.gitkeep
deleted
100644 → 0
View file @
f6e1d572
*
apps/advanced/init
View file @
2f526521
...
...
@@ -193,3 +193,13 @@ function setCookieValidationKey($root, $paths)
file_put_contents
(
$file
,
$content
);
}
}
function
createSymlink
(
$links
)
{
foreach
(
$links
as
$link
=>
$target
)
{
echo
" symlink
$target
as
$link
\n
"
;
if
(
!
is_link
(
$link
))
{
symlink
(
$target
,
$link
);
}
}
}
extensions/jui/DatePicker.php
View file @
2f526521
...
...
@@ -78,22 +78,27 @@ class DatePicker extends InputWidget
public
function
run
()
{
echo
$this
->
renderWidget
()
.
"
\n
"
;
$containerID
=
$this
->
inline
?
$this
->
containerOptions
[
'id'
]
:
$this
->
options
[
'id'
];
$language
=
$this
->
language
?
$this
->
language
:
Yii
::
$app
->
language
;
if
(
$language
!=
'en-US'
)
{
$view
=
$this
->
getView
();
DatePickerLanguageAsset
::
register
(
$view
);
$bundle
=
DatePickerLanguageAsset
::
register
(
$view
);
if
(
$bundle
->
autoGenerate
)
{
$am
=
$view
->
getAssetManager
();
$view
->
registerJsFile
(
$am
->
getAssetUrl
(
"jquery-ui/ui/i18n/datepicker-
$language
.js"
),
[
'depends'
=>
[
JuiAsset
::
className
()],
]);
}
$options
=
Json
::
encode
(
$this
->
clientOptions
);
$view
->
registerJs
(
"$('#
{
$containerID
}
').datepicker($.extend({}, $.datepicker.regional['
{
$language
}
'],
$options
));"
);
$options
=
$this
->
clientOptions
;
$this
->
clientOptions
=
false
;
// the datepicker js widget is already registered
$this
->
registerWidget
(
'datepicker'
,
$containerID
);
$this
->
clientOptions
=
$options
;
}
else
{
$this
->
register
Widget
(
'datepicker'
,
$containerID
);
$this
->
register
ClientOptions
(
'datepicker'
,
$containerID
);
}
$this
->
registerClientEvents
(
'datepicker'
,
$containerID
);
JuiAsset
::
register
(
$this
->
getView
());
}
/**
...
...
extensions/jui/DatePickerLanguageAsset.php
View file @
2f526521
...
...
@@ -15,9 +15,15 @@ use yii\web\AssetBundle;
*/
class
DatePickerLanguageAsset
extends
AssetBundle
{
public
$js
=
[
'jquery.ui.datepicker-i18n.js'
,
];
/**
* @var boolean whether to automatically generate the needed language js files.
* If this is true, the language js files will be determined based on the actual usage of [[DatePicker]]
* and its language settings. If this is false, you should explicitly specify the language js files via [[js]].
*/
public
$autoGenerate
=
true
;
/**
* @inheritdoc
*/
public
$depends
=
[
'yii\jui\JuiAsset'
,
];
...
...
framework/web/AssetBundle.php
View file @
2f526521
...
...
@@ -9,6 +9,7 @@ namespace yii\web;
use
Yii
;
use
yii\base\Object
;
use
yii\helpers\Url
;
/**
* AssetBundle represents a collection of asset files, such as CSS, JS, images.
...
...
@@ -115,4 +116,61 @@ class AssetBundle extends Object
$this
->
baseUrl
=
rtrim
(
Yii
::
getAlias
(
$this
->
baseUrl
),
'/'
);
}
}
/**
* @param View $view
*/
public
function
registerAssetFiles
(
$view
)
{
$manager
=
$view
->
getAssetManager
();
foreach
(
$this
->
js
as
$js
)
{
$view
->
registerJsFile
(
$this
->
getAssetUrl
(
$js
,
$manager
),
$this
->
jsOptions
);
}
foreach
(
$this
->
css
as
$css
)
{
$view
->
registerCssFile
(
$this
->
getAssetUrl
(
$css
,
$manager
),
$this
->
cssOptions
);
}
}
/**
* Returns the actual URL for the specified asset.
* The actual URL is obtained by prepending either [[baseUrl]] or [[AssetManager::baseUrl]] to the given asset path.
* @param string $asset the asset path. This should be one of the assets listed in [[js]] or [[css]].
* @param AssetManager $manager the asset manager
* @return string the actual URL for the specified asset.
*/
protected
function
getAssetUrl
(
$asset
,
$manager
)
{
if
((
$actualAsset
=
$manager
->
resolveAsset
(
$asset
))
!==
false
)
{
return
Url
::
isRelative
(
$actualAsset
)
?
$manager
->
baseUrl
.
'/'
.
$actualAsset
:
$actualAsset
;
}
if
(
strncmp
(
$asset
,
'@/'
,
2
)
===
0
)
{
return
$manager
->
baseUrl
.
substr
(
$asset
,
1
);
}
elseif
(
Url
::
isRelative
(
$asset
))
{
return
$this
->
baseUrl
.
'/'
.
$asset
;
}
else
{
return
$asset
;
}
}
/**
* Returns the actual file path for the specified asset.
* @param string $asset the asset path. This should be one of the assets listed in [[js]] or [[css]].
* @param AssetManager $manager the asset manager
* @return string|boolean the actual file path, or false if the asset is specified as an absolute URL
*/
public
function
getAssetPath
(
$asset
,
$manager
)
{
if
((
$actualAsset
=
$manager
->
resolveAsset
(
$asset
))
!==
false
)
{
return
Url
::
isRelative
(
$actualAsset
)
?
$manager
->
basePath
.
'/'
.
$actualAsset
:
false
;
}
if
(
strncmp
(
$asset
,
'@/'
,
2
)
===
0
)
{
return
$manager
->
basePath
.
substr
(
$asset
,
1
);
}
elseif
(
Url
::
isRelative
(
$asset
))
{
return
$this
->
basePath
.
'/'
.
$asset
;
}
else
{
return
false
;
}
}
}
framework/web/AssetManager.php
View file @
2f526521
...
...
@@ -10,7 +10,6 @@ namespace yii\web;
use
Yii
;
use
yii\base\Component
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\Url
;
/**
* AssetManager manages asset bundle configuration and loading.
...
...
@@ -84,6 +83,8 @@ class AssetManager extends Component
*/
public
$assetMap
=
[];
private
$_dummyBundles
=
[];
/**
* Initializes the component.
...
...
@@ -114,7 +115,7 @@ class AssetManager extends Component
public
function
getBundle
(
$name
)
{
if
(
$this
->
bundles
===
false
)
{
return
null
;
return
$this
->
loadDummyBundle
(
$name
)
;
}
elseif
(
!
isset
(
$this
->
bundles
[
$name
]))
{
return
$this
->
bundles
[
$name
]
=
$this
->
loadBundle
(
$name
);
}
elseif
(
$this
->
bundles
[
$name
]
instanceof
AssetBundle
)
{
...
...
@@ -122,7 +123,7 @@ class AssetManager extends Component
}
elseif
(
is_array
(
$this
->
bundles
[
$name
]))
{
return
$this
->
bundles
[
$name
]
=
$this
->
loadBundle
(
$name
,
$this
->
bundles
[
$name
]);
}
elseif
(
$this
->
bundles
[
$name
]
===
false
)
{
return
null
;
return
$this
->
loadDummyBundle
(
$name
)
;
}
else
{
throw
new
InvalidConfigException
(
"Invalid asset bundle configuration:
$name
"
);
}
...
...
@@ -143,49 +144,42 @@ class AssetManager extends Component
return
$bundle
;
}
/**
* @param View $view
* @param AssetBundle $bundle
*/
public
function
registerAssetFiles
(
$view
,
$bundle
)
protected
function
loadDummyBundle
(
$name
)
{
foreach
(
$bundle
->
js
as
$js
)
{
$view
->
registerJsFile
(
$this
->
getAssetUrl
(
$bundle
,
$js
),
$bundle
->
jsOptions
);
}
foreach
(
$bundle
->
css
as
$css
)
{
$view
->
registerCssFile
(
$this
->
getAssetUrl
(
$bundle
,
$css
),
$bundle
->
cssOptions
);
if
(
!
isset
(
$this
->
_dummyBundles
[
$name
]))
{
$this
->
_dummyBundles
[
$name
]
=
$this
->
loadBundle
(
$name
,
[
'js'
=>
[],
'css'
=>
[],
'depends'
=>
[],
]);
}
return
$this
->
_dummyBundles
[
$name
];
}
p
rotected
function
getAssetUrl
(
$bundle
,
$file
)
p
ublic
function
resolveAsset
(
$asset
)
{
if
(
(
$mappedFile
=
$this
->
mapAsset
(
$file
))
!==
false
)
{
return
Url
::
isRelative
(
$mappedFile
)
?
$this
->
baseUrl
.
'/'
.
$mappedFile
:
$mappedFile
;
if
(
isset
(
$this
->
assetMap
[
$asset
])
)
{
return
$this
->
assetMap
[
$asset
]
;
}
if
(
strncmp
(
$file
,
'@/'
,
2
)
===
0
)
{
$file
=
$this
->
baseUrl
.
substr
(
$file
,
1
);
}
elseif
(
Url
::
isRelative
(
$file
))
{
$file
=
$bundle
->
baseUrl
.
'/'
.
$file
;
}
return
$file
;
}
protected
function
mapAsset
(
$file
)
{
if
(
isset
(
$this
->
assetMap
[
$file
]))
{
return
$this
->
assetMap
[
$file
];
}
$n
=
strlen
(
$file
);
$n
=
strlen
(
$asset
);
foreach
(
$this
->
assetMap
as
$from
=>
$to
)
{
$n2
=
strlen
(
$from
);
if
(
$n2
<=
$n
&&
substr_compare
(
$
file
,
$from
,
$n
-
$n2
,
$n2
)
===
0
)
{
if
(
$n2
<=
$n
&&
substr_compare
(
$
asset
,
$from
,
$n
-
$n2
,
$n2
)
===
0
)
{
return
$to
;
}
}
return
false
;
}
public
function
getAssetUrl
(
$asset
)
{
return
$this
->
baseUrl
.
'/'
.
ltrim
(
$asset
,
'/'
);
}
public
function
getAssetPath
(
$asset
)
{
return
$this
->
basePath
.
'/'
.
ltrim
(
$asset
,
'/'
);
}
}
framework/web/View.php
View file @
2f526521
...
...
@@ -261,7 +261,7 @@ class View extends \yii\base\View
foreach
(
$bundle
->
depends
as
$dep
)
{
$this
->
registerAssetFiles
(
$dep
);
}
$
this
->
getAssetManager
()
->
registerAssetFiles
(
$this
,
$bundle
);
$
bundle
->
registerAssetFiles
(
$this
);
}
unset
(
$this
->
assetBundles
[
$name
]);
}
...
...
@@ -380,7 +380,7 @@ class View extends \yii\base\View
}
else
{
$this
->
getAssetManager
()
->
bundles
[
$key
]
=
new
AssetBundle
([
'baseUrl'
=>
''
,
'css'
=>
[
$url
],
'css'
=>
[
ltrim
(
$url
,
'/'
)
],
'cssOptions'
=>
$options
,
'depends'
=>
(
array
)
$depends
,
]);
...
...
@@ -445,7 +445,7 @@ class View extends \yii\base\View
}
else
{
$this
->
getAssetManager
()
->
bundles
[
$key
]
=
new
AssetBundle
([
'baseUrl'
=>
''
,
'js'
=>
[
$url
],
'js'
=>
[
ltrim
(
$url
,
'/'
)
],
'jsOptions'
=>
$options
,
'depends'
=>
(
array
)
$depends
,
]);
...
...
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