Skip to content

Commit

Permalink
Adding a very simple example theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisFrench committed May 30, 2014
1 parent 3f0aa0e commit a5dc88e
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/Theme/Assets/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
text-align: center;
}
Empty file.
Empty file added apps/Theme/Assets/js/script.js
Empty file.
Empty file added apps/Theme/Less/global.less.css
Empty file.
25 changes: 25 additions & 0 deletions apps/Theme/Listeners/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Theme\Listeners;

class Error extends \Dsc\Singleton
{
public function onError( $event )
{
$f3 = \Base::instance();

if ($f3->get('ERROR.code') == '404')
{
if ($f3->get('APP_NAME') == 'site')
{
$response = $event->getArgument('response');

$html = \Dsc\System::instance()->get('theme')->renderView('Theme\Views::404.php');

$response->action = 'html';
$response->html = $html;

$event->setArgument('response', $response);
}
}
}
}
7 changes: 7 additions & 0 deletions apps/Theme/Views/common/footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


<?php //echo \Dsc\Debug::dump( $this->app->hive(), false ); ?>

<!-- JAVASCRIPTS -->
<!-- Placed at the end of the document so the pages load faster -->

18 changes: 18 additions & 0 deletions apps/Theme/Views/common/head.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<base href="<?php echo $SCHEME . "://" . $HOST . $BASE . "/"; ?>" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="keywords" content="<?php echo $this->app->get('meta.keywords'); ?>" />
<meta name="description" content="<?php echo $this->app->get('meta.description'); ?>" />
<meta name="generator" content="<?php echo $this->app->get('meta.generator'); ?>" />
<meta name="author" content="">


<link href="/minify/css" rel="stylesheet">
<script src="/minify/js"></script>

<title><?php echo $this->app->get('meta.title'); ?></title>

</head>
1 change: 1 addition & 0 deletions apps/Theme/Views/system-messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php echo \Dsc\System::instance()->renderMessages(); ?>
83 changes: 83 additions & 0 deletions apps/Theme/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
class ThemeBootstrap extends \Dsc\Bootstrap
{
protected $dir = __DIR__;
protected $base = __DIR__;
protected $namespace = 'Theme';

/**
* Register this app's view files for all global_apps
* @param string $global_app
*/
protected function registerViewFiles($global_app)
{
\Dsc\System::instance()->get('theme')->registerViewPath($this->dir . '/' . $global_app . '/Views/', $this->namespace . '/' . $global_app . '/Views');
}

/**
* Triggered when the admin global_app is run
*/
protected function runAdmin()
{
parent::runAdmin();

$f3 = \Base::instance();

// Tell the admin that this is an available front-end theme
\Dsc\System::instance()->get('theme')->registerTheme('Theme', $f3->get('PATH_ROOT') . 'apps/Theme/' );

// register this theme's module positions with the admin
\Modules\Factory::registerPositions( array('theme-below-header', 'theme-above-footer', 'theme-below-footer', 'theme-above-content', 'theme-below-content', 'theme-left-content', 'theme-right-content') );
}

/**
* Triggered when the front-end global_app is run
*/
protected function runSite()
{
parent::runSite();
$f3 = \Base::instance();

if(!is_dir($f3->get('PATH_ROOT').'public/theme')) {
$publictheme = $f3->get('PATH_ROOT').'public/theme';
$admintheme = $f3->get('PATH_ROOT').'apps/theme/Assets';
$res = symlink( $admintheme, $publictheme );
}




\Dsc\System::instance()->get('theme')->setTheme('Theme', $f3->get('PATH_ROOT') . 'apps/Theme/' );
\Dsc\System::instance()->get('theme')->registerViewPath( $f3->get('PATH_ROOT') . 'apps/Theme/Views/', 'Theme/Views' );

// tell Minify where to find Media, CSS and JS files
\Minify\Factory::registerPath($f3->get('PATH_ROOT') . "public/theme/");
\Minify\Factory::registerPath($f3->get('PATH_ROOT') . "public/theme/css/");
\Minify\Factory::registerPath($f3->get('PATH_ROOT') . "public/");

// register the less css file
\Minify\Factory::registerLessCssSource( $f3->get('PATH_ROOT') . "apps/Theme/Less/global.less.css" );

// add the media assets to be minified
$files = array(
'css/style.css',
);

foreach ($files as $file)
{
\Minify\Factory::css($file);
}

$files = array(
'js/script.js',
);

foreach ($files as $file)
{
\Minify\Factory::js($file, array('priority' => 1));
}

\Dsc\System::instance()->getDispatcher()->addListener(\Theme\Listeners\Error::instance());
}
}
$app = new ThemeBootstrap();
17 changes: 17 additions & 0 deletions apps/Theme/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en" class="default <?php echo @$html_class; ?>" >
<head>
<?php echo $this->renderView('Theme/Views::common/head.php'); ?>
</head>
<body>

<!-- PAGE -->
<body>
<tmpl type="system.messages" />
<tmpl type="view" />
<!--/FOOTER -->
</div>
<!--/PAGE -->
<?php echo $this->renderView('Theme/Views::common/footer.php'); ?>
</body>
</html>

0 comments on commit a5dc88e

Please sign in to comment.