Skip to content

Commit

Permalink
Removed model controller and init the classes in main plugin file
Browse files Browse the repository at this point in the history
Added some comments to code
  • Loading branch information
Andreas Ek committed Jan 5, 2016
1 parent af2c105 commit 39ef57c
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 54 deletions.
9 changes: 6 additions & 3 deletions bladerunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Bladerunner
Plugin URI: https://github.com/ekandreas/bladerunner
Description: Blade template engine for WordPress
Version: 0.5.7
Version: 0.6
Author: Andreas Ek
Author URI: http://www.aekab.se/
Expand All @@ -16,6 +16,9 @@
require_once __DIR__ . '/vendor/autoload.php';
}

require_once __DIR__ . '/src/model.php';
require_once __DIR__ . '/src/controller.php';
require_once __DIR__ . '/src/init.php';
require_once __DIR__ . '/src/template.php';
require_once __DIR__ . '/src/blade.php';

new Bladerunner\Init();
new Bladerunner\Template();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ekandreas/bladerunner",
"type": "wordpress-plugin",
"version": "0.5.7",
"version": "0.6",
"description": "WordPress Blade L5 template engine",
"keywords": ["laravel", "blade", "wordpress"],
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Bladerunner
WordPress plugin for Blade L5 templating

*** WORK IN PROGRESS ***

To install it to your Composer based WordPress installation:

```
Expand All @@ -26,6 +24,9 @@ Hello World Page rendered at {{ date('Y-m-d H:i:s') }}

http://laravel.com/docs/master/blade

## Cache
* It's a really good idea to empty the .cache folder inside "uploads" when develop templates. Eg, create a "del" command inside your gulp-file.

## Directories
* Your cached views will always be stored in your wp upload folder, .cache.
* Your views must be placed within your theme folder.
Expand Down
40 changes: 0 additions & 40 deletions src/controller.php

This file was deleted.

60 changes: 60 additions & 0 deletions src/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
namespace Bladerunner;

/**
* Initialize the plugin inside WordPress wp-admin to check for errors
*/
class Init {

protected $cache;

function __construct() {
$this->cache = Template::cache();
add_action( 'admin_init', [ $this, 'check_writeable_upload' ] );
}

/**
* Check if the cache folder exists and is writable and assigns admin notice if not
* @return void
*/
static function check_writeable_upload() {

if( !file_exists( $this->cache ) ) {
add_action( 'admin_notices', [ $this, 'notice_create_cache' ] );
}
else {

$is_writable = @file_put_contents( $this->cache . '/.folder_writable', "true" );
if( !$is_writable ) {
add_action( 'admin_notices', [ $this, 'notice_writable_cache' ] );
}

}

}

/**
* Echo admin notice inside wp-admin if cache folder doesnt exist.
* @return void
*/
static function notice_create_cache() {
echo '<div class="error"> ';
echo '<p><strong>Cache folder missing</strong></p>';
echo '<p>Bladerunner needs a .cache -folder in uploads. Please create the folder and make it writable!</p>';
echo '<p>Eg, <i>mkdir ' . $this->cache . '</i></p>';
echo '</div>';
}

/**
* Echo admin notice inside wp-admin if cache folder not writable.
* @return void
*/
static function notice_writable_cache() {
echo '<div class="error"> ';
echo '<p><strong>Cache not writable</strong></p>';
echo '<p>Bladerunner cache folder .cache in uploads not writable. Please make the folder writable for your web server!</p>';
echo '<p>Eg, <i>chmod -R 777 ' . $this->cache . '</i></p>';
echo '</div>';
}

}
40 changes: 34 additions & 6 deletions src/model.php → src/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,35 @@
namespace Bladerunner;
use Bladerunner\Blade;

class Model {

/**
* Handles the template include for blade templates
*/
class Template {

/**
* Saves the path in case of double object instance
* @var [type]
*/
protected $path;

function getPath( $template ) {
/**
* [__construct description]
*/
function __construct() {

add_action( 'template_include', [ $this, 'path' ], 999 );
add_filter( 'index_template', function() { return 'index.blade.php'; } );
//add_filter( 'page_template', [ $model, 'getPath' ] );
//add_filter( 'bp_template_include', [ $model, 'getPath' ] );

}

/**
* The hook for template_include to override blade templating
* @param [type] $template [description]
* @return [type] [description]
*/
function path( $template ) {

if( $this->path )
return $this->path;
Expand All @@ -18,7 +42,7 @@ function getPath( $template ) {

$views = get_stylesheet_directory();

$cache = Model::get_cache_dir();
$cache = Template::cache();
if( !file_exists($cache) ) {
return $template;
}
Expand Down Expand Up @@ -61,10 +85,14 @@ function getPath( $template ) {

}

static function get_cache_dir() {
/**
* Gets the cache folder for Bladerunner
* @return [type] [description]
*/
static function cache() {
$result = wp_upload_dir()['basedir'];
$result .= '/.cache';
return $result;
return apply_filters('bladerunner/cache', $result);
}

}
Expand Down

0 comments on commit 39ef57c

Please sign in to comment.