Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework 2.0 #29

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.{php,md,twig,html}]
[*.{php,md}]
indent_style = space
indent_size = 4

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public/wp/
cache
.cache
.vagrant
npm-debug.log
__init__.py
*.log

# Credentials
s3.json
Expand Down
10 changes: 7 additions & 3 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Vagrant.configure("2") do |config|
database = YAML.load_file("./config/secrets/database.yml")

# Network
config.vm.box = "ubuntu/trusty64"
config.vm.box = "ubuntu/bionic64"

# Do some network configuration
config.vm.network "private_network", ip: project['stage']['dev']['ip']
Expand All @@ -20,8 +20,12 @@ Vagrant.configure("2") do |config|

# VirtualBox config
config.vm.provider :virtualbox do |v|
# Give our box enough memory
v.memory = 1024
# Give our box enough memory
v.memory = 1024

# Experimental fixes for slow VM network speeds
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]

# Linked clone support
v.linked_clone = true if Vagrant::VERSION =~ /^1.8/
Expand Down
File renamed without changes.
Empty file removed app/assets/javascripts/script.js
Empty file.
2 changes: 2 additions & 0 deletions app/assets/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import $ from 'jquery'
import _ from 'lodash'
4 changes: 2 additions & 2 deletions app/assets/sass/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Externals
*/
@import "sanitize-css/lib/sanitize.scss";
@import "breakpoint";
@import "sanitize.css/sanitize.css";
@import "breakpoint";
9 changes: 5 additions & 4 deletions app/themes/base/composer.json → app/bootstrap/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tomodomo/theme",
"description": "Base theme",
"name": "tomodomo/bootstrap",
"description": "The default Kaiso bootstrap",
"type": "wordpress-theme",
"license": "MIT",
"authors": [
Expand All @@ -15,9 +15,10 @@
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"installer-name": "base"
"installer-name": "bootstrap"
},
"require": {
"php": "^7.0"
"php": "^7.1",
"tomodomo/kaiso": "*@dev"
}
}
6 changes: 6 additions & 0 deletions app/bootstrap/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

/**
* Load the real functions.php file, which lives at `app/functions.php`.
*/
require_once ABSPATH . '/../../app/functions.php';
12 changes: 4 additions & 8 deletions app/themes/base/index.php → app/bootstrap/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tomodomo\Theme;
namespace Tomodomo;

use Tomodomo\Kaiso as App;
use Timber as Timber;
Expand All @@ -17,17 +17,13 @@
ABSPATH . '/../../app/views',
];

// App settings. So far you only need to provide a controllerPath
$settings = [
'controllerPath' => '\\Tomodomo\\Controllers\\',
'customTemplates' => [],
];

// Instantiate the app with our settings
require_once ABSPATH . '/../../app/settings.php';

$app = new App($settings);

// Load up the container
require_once 'container.php';
require_once ABSPATH . '/../../app/container.php';

// Run the app!
$app->run();
2 changes: 1 addition & 1 deletion app/themes/base/style.css → app/bootstrap/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Theme Name: Tomodomo
* Theme Name: Kaiso Bootstrap
* Theme URI: https://tomodomo.co/
* Author: Tomodomo
* Author URI: https://tomodomo.co/
Expand Down
3 changes: 2 additions & 1 deletion app/themes/base/container.php → app/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
return $context;
};

// Allow accessing the current user
$app->container['user'] = function ($container) {
return $container['context']['user'] ?? null;
};

// Add an instance of Twig
$app->container['twig'] = function ($container) {
// Cheating a bit, wrapping Timber
return new Twig($container);
};
10 changes: 6 additions & 4 deletions app/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

namespace Tomodomo\Controllers;

use Pimple\Container;

class BaseController
{
/**
* @var \Pimple\Container
* @var Container
*/
public $container;

/**
* @param \Pimple\Container $container
* @param Container $container
*
* @return void
*/
public function __construct($container)
public function __construct(Container $container)
{
// Grab the Pimple container
$this->container = $container;

// Twig!
// Make Twig available for convenience
$this->twig = $this->container['twig'];

return;
Expand Down
23 changes: 15 additions & 8 deletions app/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

namespace Tomodomo\Controllers;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Timber\PostQuery as Query;

class IndexController extends BaseController
{
/**
* Handle GET requests to this route
* Respond to a GET request on the index.
*
* @path /
* @param RequestInterface $request
* @param ResponseInterface $response
* @param array $args
*
* @param \GuzzleHttp\Psr7\Request $request
* @param null $response
* @param array $args
* @return string
* @return ResponseInterface
*/
public function get($request, $response, $args)
public function get(RequestInterface $request, ResponseInterface $response, array $args) : ResponseInterface
{
return $this->twig->compile('index.twig');
$context = [
'posts' => new Query(false, '\Tomodomo\Models\Post'),
];

return $this->twig->render($response, 'index.twig', $context);
}
}
19 changes: 16 additions & 3 deletions app/themes/base/functions.php → app/functions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<?php
/**
* Kaiso brings a number of modern PHP best practices to WordPress,
* but also brings along some core WordPress functionality —
* including a functions.php file, which can run functionality
* automatically in your site.
*
* While you can put any code here, we recommend using this file to
* configure "environment" settings: defining theme supports,
* registering nav menus, adding to Timber's global context, etc.
*/

namespace Tomodomo\Theme;

Expand All @@ -9,7 +19,7 @@
*
* @return void
*/
function themeSupports()
function themeSupports() : void
{
// Featured images
add_theme_support('post-thumbnails');
Expand All @@ -20,6 +30,9 @@ function themeSupports()
// Disable Gutenberg colors
add_theme_support('disable-custom-colors');

// Disable Gutenberg custom font sizes
add_theme_support('disable-custom-font-sizes');

// Auto-generate the title tag
add_theme_support('title-tag');

Expand All @@ -33,7 +46,7 @@ function themeSupports()
*
* @return void
*/
function registerMenus()
function registerMenus() : void
{
register_nav_menus([
'primary' => 'Primary Menu',
Expand All @@ -52,7 +65,7 @@ function registerMenus()
*
* @return array
*/
function context($context)
function context(array $context) : array
{
// Load in menus
$context['menu']['primary'] = new Menu('primary');
Expand Down
30 changes: 25 additions & 5 deletions app/helpers/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@

namespace Tomodomo\Helpers;

use Pimple\Container;
use Psr\Http\Message\ResponseInterface;
use Timber;

class Twig
{
/**
* @param \Pimple\Container
* @param Container
*
* @return void
*/
public function __construct($container)
public function __construct(Container $container)
{
$this->container = $container;

return;
}

/**
* Compile a template
* Compile a template to a string.
*
* @param string|array $template
* @param array $context
* @param array $context
*
* @return string
*/
public function compile($template, $context = [])
public function compile($template, array $context = []) : string
{
// Build the context settings
$settings = array_merge(
Expand All @@ -39,4 +41,22 @@ public function compile($template, $context = [])

return Timber::compile($template, $settings);
}

/**
* Compiles a template, adds it to the PSR7 response body stream,
* and returns the response. Inspired by Slim Framework's Twig
* integration: https://github.com/slimphp/Twig-View
*
* @param ResponseInterface $response
* @param string|array $template
* @param array $context
*
* @return ResponseInterface
*/
public function render(ResponseInterface $response, $template, array $context = []) : ResponseInterface
{
$response->getBody()->write($this->compile($template, $context));

return $response;
}
}
8 changes: 8 additions & 0 deletions app/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

// App settings
$settings = [
'controllerPath' => '\\Tomodomo\\Controllers\\',
'customTemplates' => [],
'displayErrors' => defined('WP_DEBUG_DISPLAY') ? WP_DEBUG_DISPLAY : false,
];
16 changes: 16 additions & 0 deletions app/views/index.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'layouts/base.twig' %}

{% block content %}

{% for post in posts %}
<article class="post">
<header>
<h1>{{post.title}}</h1>
</header>
<div class="post__content">
{{post.content}}
</div>
</article>
{% endfor %}

{% endblock %}
14 changes: 14 additions & 0 deletions app/views/layouts/base.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
{{wp_head}}
</head>
<body>
<main>
{% block content %}{% endblock %}
</main>

{{wp_footer}}
</body>
</html>
23 changes: 0 additions & 23 deletions bower.json

This file was deleted.

Loading