added option to organize views in subfolders
it was became messy
This commit is contained in:
parent
3a80a96571
commit
361ba4a516
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Crunchbutton_Util extends Cana_Model {
|
class Crunchbutton_Util extends Cana_Model {
|
||||||
public function frontendTemplates($export = false) {
|
public function frontendTemplates($export = false, $subFolders = false) {
|
||||||
$files = [];
|
$files = [];
|
||||||
|
|
||||||
$themes = c::view()->theme();
|
$themes = c::view()->theme();
|
||||||
@ -15,9 +15,14 @@ class Crunchbutton_Util extends Cana_Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (new DirectoryIterator(c::config()->dirs->view.$frontendDir.'/frontend') as $fileInfo) {
|
if( $subFolders ){
|
||||||
if (!$fileInfo->isDot() && $fileInfo->getBasename() != '.DS_Store' ) {
|
$path = c::config()->dirs->view.$theme.'/frontend';
|
||||||
$files[] = $fileInfo->getBasename('.phtml');
|
$files = array_merge( $files, Crunchbutton_Util::directoryReader( $path ) );
|
||||||
|
} else {
|
||||||
|
foreach (new DirectoryIterator(c::config()->dirs->view.$frontendDir.'/frontend') as $fileInfo) {
|
||||||
|
if (!$fileInfo->isDot() && $fileInfo->getBasename() != '.DS_Store' ) {
|
||||||
|
$files[] = $fileInfo->getBasename('.phtml');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($export) {
|
if ($export) {
|
||||||
@ -26,6 +31,25 @@ class Crunchbutton_Util extends Cana_Model {
|
|||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function directoryReader( $path, $subFolder = '' ){
|
||||||
|
$files = [];
|
||||||
|
foreach ( new DirectoryIterator( $path ) as $fileInfo ) {
|
||||||
|
if( !$fileInfo->isDot() && $fileInfo->isDir() ){
|
||||||
|
// echo '<pre>';var_dump( $fileInfo->getPath() );exit();
|
||||||
|
|
||||||
|
if( $fileInfo->getPathname() != $path ){
|
||||||
|
$subPath = $fileInfo->getPathname();
|
||||||
|
$subFolder = $fileInfo->getBasename();
|
||||||
|
$files = array_merge( $files, Crunchbutton_Util::directoryReader( $subPath, $subFolder ) );
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if ( !$fileInfo->isDot() && $fileInfo->getBasename() != '.DS_Store' ) {
|
||||||
|
$files[] = [ 'basename' => $fileInfo->getBasename( '.phtml' ), 'subFolder' => $subFolder ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
|
|
||||||
public static function stringToColorCode( $str ) {
|
public static function stringToColorCode( $str ) {
|
||||||
$code = dechex( crc32( $str ) );
|
$code = dechex( crc32( $str ) );
|
||||||
$code = substr( $code, 0, 6 );
|
$code = substr( $code, 0, 6 );
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
<? foreach (Crunchbutton_Util::frontendTemplates(false) as $file) : ?>
|
<?php
|
||||||
<script type="text/ng-template" id="assets/view/<?=$file?>.html">
|
foreach ( Crunchbutton_Util::frontendTemplates( false, true ) as $file ) {
|
||||||
<?=$this->render('frontend/'.$file, ['filter' => false])?>
|
$basename = $file[ 'basename' ];
|
||||||
</script>
|
$pathname = 'frontend/' . ( $file[ 'subFolder' ] ? ( $file[ 'subFolder' ] . '/' ) : '' ) . $basename;
|
||||||
<? endforeach; ?>
|
echo '<script type="text/ng-template" id="assets/view/' . $basename . '.html">';
|
||||||
|
echo $this->render( $pathname, [ 'filter' => false ] );
|
||||||
|
echo '</script>';
|
||||||
|
}
|
||||||
@ -1,5 +1,8 @@
|
|||||||
<? foreach (Crunchbutton_Util::frontendTemplates(false) as $file) : ?>
|
<?php
|
||||||
<script type="text/ng-template" id="assets/view/<?=$file?>.html">
|
foreach ( Crunchbutton_Util::frontendTemplates( false, true ) as $file ) {
|
||||||
<?=$this->render('frontend/'.$file, ['filter' => false])?>
|
$basename = $file[ 'basename' ];
|
||||||
</script>
|
$pathname = 'frontend/' . ( $file[ 'subFolder' ] ? ( $file[ 'subFolder' ] . '/' ) : '' ) . $basename;
|
||||||
<? endforeach; ?>
|
echo '<script type="text/ng-template" id="assets/view/' . $basename . '.html">';
|
||||||
|
echo $this->render( $pathname, [ 'filter' => false ] );
|
||||||
|
echo '</script>';
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user