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
|
||||
|
||||
class Crunchbutton_Util extends Cana_Model {
|
||||
public function frontendTemplates($export = false) {
|
||||
public function frontendTemplates($export = false, $subFolders = false) {
|
||||
$files = [];
|
||||
|
||||
$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 (!$fileInfo->isDot() && $fileInfo->getBasename() != '.DS_Store' ) {
|
||||
$files[] = $fileInfo->getBasename('.phtml');
|
||||
if( $subFolders ){
|
||||
$path = c::config()->dirs->view.$theme.'/frontend';
|
||||
$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) {
|
||||
@ -26,6 +31,25 @@ class Crunchbutton_Util extends Cana_Model {
|
||||
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 ) {
|
||||
$code = dechex( crc32( $str ) );
|
||||
$code = substr( $code, 0, 6 );
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
<? foreach (Crunchbutton_Util::frontendTemplates(false) as $file) : ?>
|
||||
<script type="text/ng-template" id="assets/view/<?=$file?>.html">
|
||||
<?=$this->render('frontend/'.$file, ['filter' => false])?>
|
||||
</script>
|
||||
<? endforeach; ?>
|
||||
<?php
|
||||
foreach ( Crunchbutton_Util::frontendTemplates( false, true ) as $file ) {
|
||||
$basename = $file[ 'basename' ];
|
||||
$pathname = 'frontend/' . ( $file[ 'subFolder' ] ? ( $file[ 'subFolder' ] . '/' ) : '' ) . $basename;
|
||||
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) : ?>
|
||||
<script type="text/ng-template" id="assets/view/<?=$file?>.html">
|
||||
<?=$this->render('frontend/'.$file, ['filter' => false])?>
|
||||
</script>
|
||||
<? endforeach; ?>
|
||||
<?php
|
||||
foreach ( Crunchbutton_Util::frontendTemplates( false, true ) as $file ) {
|
||||
$basename = $file[ 'basename' ];
|
||||
$pathname = 'frontend/' . ( $file[ 'subFolder' ] ? ( $file[ 'subFolder' ] . '/' ) : '' ) . $basename;
|
||||
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