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
c49222f7
Commit
c49222f7
authored
Apr 15, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
script WIP
parent
34c0794f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
40 deletions
+94
-40
View.php
framework/base/View.php
+1
-1
ViewContent.php
framework/base/ViewContent.php
+24
-39
AssetBundle.php
framework/web/AssetBundle.php
+69
-0
AssetManager.php
framework/web/AssetManager.php
+0
-0
No files found.
framework/base/View.php
View file @
c49222f7
...
...
@@ -241,7 +241,7 @@ class View extends Component
{
if
(
!
empty
(
$this
->
cacheStack
))
{
$n
=
count
(
$this
->
dynamicPlaceholders
);
$placeholder
=
"<![CDATA[Y
DP
-
$n
]]>"
;
$placeholder
=
"<![CDATA[Y
II-DYNAMIC
-
$n
]]>"
;
$this
->
addDynamicPlaceholder
(
$placeholder
,
$statements
);
return
$placeholder
;
}
else
{
...
...
framework/base/ViewContent.php
View file @
c49222f7
...
...
@@ -25,30 +25,9 @@ class ViewContent extends Component
const
TOKEN_BODY_END
=
'<![CDATA[YII-BLOCK-BODY-END]]>'
;
/**
* @var array
*
* Each asset bundle should be declared with the following structure:
*
* ~~~
* array(
* 'basePath' => '...',
* 'baseUrl' => '...', // if missing, the bundle will be published to the "www/assets" folder
* 'js' => array(
* 'js/main.js',
* 'js/menu.js',
* 'js/base.js' => self::POS_HEAD,
* 'css' => array(
* 'css/main.css',
* 'css/menu.css',
* ),
* 'depends' => array(
* 'jquery',
* 'yii',
* 'yii/treeview',
* ),
* )
* ~~~
* @var \yii\web\AssetManager
*/
public
$assetManager
;
public
$assetBundles
;
public
$title
;
public
$metaTags
;
...
...
@@ -62,6 +41,14 @@ class ViewContent extends Component
public
$jsInBody
;
public
$jsFilesInBody
;
public
function
init
()
{
parent
::
init
();
if
(
$this
->
assetManager
===
null
)
{
$this
->
assetManager
=
Yii
::
$app
->
getAssetManager
();
}
}
public
function
reset
()
{
$this
->
title
=
null
;
...
...
@@ -104,21 +91,22 @@ class ViewContent extends Component
echo
self
::
TOKEN_HEAD
;
}
public
function
re
quire
AssetBundle
(
$name
)
public
function
re
gister
AssetBundle
(
$name
)
{
if
(
!
isset
(
$this
->
assetBundles
[
$name
]))
{
$bundle
=
Yii
::
$app
->
assets
->
getBundle
(
$name
);
$bundle
=
$this
->
assetManager
->
getBundle
(
$name
);
if
(
$bundle
!==
null
)
{
$this
->
assetBundles
[
$name
]
=
$bundle
;
$this
->
assetBundles
[
$name
]
=
false
;
$bundle
->
registerWith
(
$this
);
$this
->
assetBundles
[
$name
]
=
true
;
}
else
{
throw
new
InvalidConfigException
(
"Unknown asset bundle:
$name
"
);
}
foreach
(
$bundle
->
depends
as
$d
)
{
$this
->
requireAssetBundle
(
$d
);
}
}
elseif
(
$this
->
assetBundles
[
$name
]
===
false
)
{
throw
new
InvalidConfigException
(
"A cyclic dependency is detected for bundle '
$name
'."
);
}
}
public
function
registerMetaTag
(
$options
,
$key
=
null
)
{
if
(
$key
===
null
)
{
...
...
@@ -149,8 +137,10 @@ class ViewContent extends Component
$this
->
cssFiles
[
$key
]
=
Html
::
cssFile
(
$url
,
$options
);
}
public
function
registerJs
(
$js
,
$
position
=
self
::
POS_END
,
$
options
=
array
(),
$key
=
null
)
public
function
registerJs
(
$js
,
$options
=
array
(),
$key
=
null
)
{
$position
=
isset
(
$options
[
'position'
])
?
$options
[
'position'
]
:
self
::
POS_END
;
unset
(
$options
[
'position'
]);
$key
=
$key
?:
$js
;
$html
=
Html
::
script
(
$js
,
$options
);
if
(
$position
==
self
::
POS_END
)
{
...
...
@@ -164,8 +154,10 @@ class ViewContent extends Component
}
}
public
function
registerJsFile
(
$url
,
$
position
=
self
::
POS_END
,
$
options
=
array
(),
$key
=
null
)
public
function
registerJsFile
(
$url
,
$options
=
array
(),
$key
=
null
)
{
$position
=
isset
(
$options
[
'position'
])
?
$options
[
'position'
]
:
self
::
POS_END
;
unset
(
$options
[
'position'
]);
$key
=
$key
?:
$url
;
$html
=
Html
::
jsFile
(
$url
,
$options
);
if
(
$position
==
self
::
POS_END
)
{
...
...
@@ -178,11 +170,9 @@ class ViewContent extends Component
throw
new
InvalidParamException
(
"Unknown position:
$position
"
);
}
}
protected
function
populate
(
$content
)
{
$this
->
expandAssetBundles
();
return
strtr
(
$content
,
array
(
self
::
TOKEN_HEAD
=>
$this
->
getHeadHtml
(),
self
::
TOKEN_BODY_BEGIN
=>
$this
->
getBodyBeginHtml
(),
...
...
@@ -190,11 +180,6 @@ class ViewContent extends Component
));
}
protected
function
expandAssetBundles
()
{
}
protected
function
getHeadHtml
()
{
$lines
=
array
();
...
...
framework/web/AssetBundle.php
0 → 100644
View file @
c49222f7
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\web
;
use
yii\base\Object
;
/**
* Each asset bundle should be declared with the following structure:
*
* ~~~
* array(
* 'basePath' => '...',
* 'baseUrl' => '...', // if missing, the bundle will be published to the "www/assets" folder
* 'js' => array(
* 'js/main.js',
* 'js/menu.js',
* 'js/base.js' => self::POS_HEAD,
* 'css' => array(
* 'css/main.css',
* 'css/menu.css',
* ),
* 'depends' => array(
* 'jquery',
* 'yii',
* 'yii/treeview',
* ),
* )
* ~~~
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
AssetBundle
extends
Object
{
public
$basePath
;
public
$baseUrl
;
// if missing, the bundle will be published to the "www/assets" folder
public
$js
=
array
();
public
$css
=
array
();
public
$depends
=
array
();
/**
* @param \yii\base\ViewContent $content
*/
public
function
registerWith
(
$content
)
{
foreach
(
$this
->
depends
as
$name
)
{
$content
->
registerAssetBundle
(
$name
);
}
foreach
(
$this
->
js
as
$js
=>
$options
)
{
if
(
is_array
(
$options
))
{
$content
->
registerJsFile
(
$js
,
$options
);
}
else
{
$content
->
registerJsFile
(
$options
);
}
}
foreach
(
$this
->
css
as
$css
=>
$options
)
{
if
(
is_array
(
$options
))
{
$content
->
registerCssFile
(
$css
,
$options
);
}
else
{
$content
->
registerCssFile
(
$options
);
}
}
}
}
\ No newline at end of file
framework/web/AssetManager.php
View file @
c49222f7
This diff is collapsed.
Click to expand it.
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