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
b1a1458d
Commit
b1a1458d
authored
Dec 26, 2013
by
dev-meghraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes code style.
parent
eabcf1c7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
13 deletions
+62
-13
CHANGELOG.md
extensions/yii/twig/CHANGELOG.md
+1
-1
TwigSimpleFileLoader.php
extensions/yii/twig/TwigSimpleFileLoader.php
+51
-10
ViewRenderer.php
extensions/yii/twig/ViewRenderer.php
+3
-2
ViewRendererStaticClassProxy.php
extensions/yii/twig/ViewRendererStaticClassProxy.php
+7
-0
No files found.
extensions/yii/twig/CHANGELOG.md
View file @
b1a1458d
...
@@ -5,9 +5,9 @@ Yii Framework 2 twig extension Change Log
...
@@ -5,9 +5,9 @@ Yii Framework 2 twig extension Change Log
----------------------------
----------------------------
-
no changes in this release.
-
no changes in this release.
-
Add File based Twig loader for better caching and usability of twig's file based function
2.
0.0 alpha, December 1, 2013
2.
0.0 alpha, December 1, 2013
-----------------------------
-----------------------------
-
Initial release.
-
Initial release.
-
Add more features like in old and file based loader for twig files
extensions/yii/twig/TwigSimpleFileLoader.php
View file @
b1a1458d
<?php
<?php
/**
* Simple file system wrapper for twig to process twig files
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\twig
;
namespace
yii\twig
;
/**
/**
* Twig view file loader class
* Twig view file loader class
.
*
*
* @author dev-mraj <dev.meghraj@gmail.com>
* @author dev-mraj <dev.meghraj@gmail.com>
* @version 1.0.0
* @version 1.0.0
...
@@ -11,26 +19,58 @@ namespace yii\twig;
...
@@ -11,26 +19,58 @@ namespace yii\twig;
class
TwigSimpleFileLoader
implements
\Twig_LoaderInterface
{
class
TwigSimpleFileLoader
implements
\Twig_LoaderInterface
{
/**
/**
* Path to directory where all file exists
* @var string Path to directory
* @var string
*/
*/
private
$
dir
;
private
$_
dir
;
public
function
__construct
(
$dir
){
/*
$this
->
dir
=
$dir
;
* @param @dir string path to directory
*/
public
function
__construct
(
$dir
)
{
$this
->
_dir
=
$dir
;
}
}
public
function
isFresh
(
$name
,
$time
){
/**
* Compare a file's freshness with previously stored timestamp
*
* @param $name string file name to check
* @param $time int timestamp to compare with
* @return bool true if file is still fresh and not changes, false otherwise
*/
public
function
isFresh
(
$name
,
$time
)
{
return
filemtime
(
$this
->
getFilePath
(
$name
))
<=
$time
;
return
filemtime
(
$this
->
getFilePath
(
$name
))
<=
$time
;
}
}
public
function
getSource
(
$name
){
/**
* get the source of given file name
*
* @param $name string file name
* @return string contents of given file name
*/
public
function
getSource
(
$name
)
{
return
file_get_contents
(
$this
->
getFilePath
(
$name
));
return
file_get_contents
(
$this
->
getFilePath
(
$name
));
}
}
public
function
getCacheKey
(
$name
){
/**
* get a unique key that can represent this file uniquely among other files.
* @param $name
* @return string
*/
public
function
getCacheKey
(
$name
)
{
return
$this
->
getFilePath
(
$name
);
return
$this
->
getFilePath
(
$name
);
}
}
/**
* internally used to get absolute path of given file name
* @param $name string file name
* @return string absolute path of file
*/
protected
function
getFilePath
(
$name
){
protected
function
getFilePath
(
$name
){
return
$this
->
dir
.
'/'
.
$name
;
return
$this
->
_
dir
.
'/'
.
$name
;
}
}
}
}
\ No newline at end of file
extensions/yii/twig/ViewRenderer.php
View file @
b1a1458d
...
@@ -13,6 +13,7 @@ use Yii;
...
@@ -13,6 +13,7 @@ use Yii;
use
yii\base\View
;
use
yii\base\View
;
use
yii\base\ViewRenderer
as
BaseViewRenderer
;
use
yii\base\ViewRenderer
as
BaseViewRenderer
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\twig\TwigSimpleFileLoader
;
/**
/**
* TwigViewRenderer allows you to use Twig templates in views.
* TwigViewRenderer allows you to use Twig templates in views.
...
@@ -76,7 +77,7 @@ class ViewRenderer extends BaseViewRenderer
...
@@ -76,7 +77,7 @@ class ViewRenderer extends BaseViewRenderer
public
$lexerOptions
=
[];
public
$lexerOptions
=
[];
/**
/**
* @var \Twig_Environment
* @var \Twig_Environment
twig environment object that do all rendering twig templates
*/
*/
public
$twig
;
public
$twig
;
...
@@ -85,7 +86,6 @@ class ViewRenderer extends BaseViewRenderer
...
@@ -85,7 +86,6 @@ class ViewRenderer extends BaseViewRenderer
$this
->
twig
=
new
\Twig_Environment
(
null
,
array_merge
([
$this
->
twig
=
new
\Twig_Environment
(
null
,
array_merge
([
'cache'
=>
Yii
::
getAlias
(
$this
->
cachePath
),
'cache'
=>
Yii
::
getAlias
(
$this
->
cachePath
),
'auto_reload'
=>
true
,
'charset'
=>
Yii
::
$app
->
charset
,
'charset'
=>
Yii
::
$app
->
charset
,
],
$this
->
options
));
],
$this
->
options
));
...
@@ -95,6 +95,7 @@ class ViewRenderer extends BaseViewRenderer
...
@@ -95,6 +95,7 @@ class ViewRenderer extends BaseViewRenderer
$this
->
twig
->
addExtension
(
new
$extension
());
$this
->
twig
->
addExtension
(
new
$extension
());
}
}
}
}
// Adding custom globals (objects or static classes)
// Adding custom globals (objects or static classes)
if
(
!
empty
(
$this
->
globals
))
{
if
(
!
empty
(
$this
->
globals
))
{
$this
->
addGlobals
(
$this
->
globals
);
$this
->
addGlobals
(
$this
->
globals
);
...
...
extensions/yii/twig/ViewRendererStaticClassProxy.php
View file @
b1a1458d
<?php
<?php
/**
* Twig view renderer class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\twig
;
namespace
yii\twig
;
...
...
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