From 9b8832902cc1a51b5c6e2e0890c576372a60e5e1 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 10 Mar 2021 16:13:52 +0100 Subject: Initial commit --- .gitignore | 3 ++ Readme.md | 8 +++ app/Site.php | 87 +++++++++++++++++++++++++++++++ composer.json | 22 ++++++++ footer.php | 5 ++ functions.php | 5 ++ header.php | 4 ++ index.php | 8 +++ package.json | 11 ++++ resources/css/index.scss | 4 ++ resources/js/index.js | 1 + resources/views/base.twig | 21 ++++++++ resources/views/components/menu-item.twig | 10 ++++ resources/views/index.twig | 8 +++ resources/views/root.twig | 17 ++++++ style.css | 10 ++++ webpack.config.js | 12 +++++ 17 files changed, 236 insertions(+) create mode 100644 .gitignore create mode 100644 Readme.md create mode 100644 app/Site.php create mode 100644 composer.json create mode 100644 footer.php create mode 100644 functions.php create mode 100644 header.php create mode 100644 index.php create mode 100644 package.json create mode 100644 resources/css/index.scss create mode 100644 resources/js/index.js create mode 100644 resources/views/base.twig create mode 100644 resources/views/components/menu-item.twig create mode 100644 resources/views/index.twig create mode 100644 resources/views/root.twig create mode 100644 style.css create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..451f104 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor +/node_modules +/build diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..790c8a5 --- /dev/null +++ b/Readme.md @@ -0,0 +1,8 @@ +## Instructions + +``` +composer create-project dweipert/wp-theme-boilerplate yourthemename +cd yourthemename +npm i +npm start +``` diff --git a/app/Site.php b/app/Site.php new file mode 100644 index 0000000..5e45535 --- /dev/null +++ b/app/Site.php @@ -0,0 +1,87 @@ + 'Main', + 'footer' => 'Footer', + ]); + } + + /** + * wp_enqueue_scripts callback + */ + public function enqueueScripts() + { + $this->enqueueStyle('theme', 'index.css'); + $this->enqueueScript('theme', 'index.js', ['jquery'], true); + } + + /** + * @param array $context + * + * @return mixed + */ + public function addToContext($context) + { + $context['site'] = $this; + + $context['menu'] = []; + foreach (get_registered_nav_menus() as $location => $name) { + $context['menu'][$location] = new Menu($location); + } + + return $context; + } + + /** + * @param Environment $twig + * + * @return Environment + */ + public function addToTwig(Environment $twig) + { + $twig->addExtension(new StringLoaderExtension()); + $twig->addFunction(new TwigFunction('assets_url', [$this, 'assetsUrl'])); + + return $twig; + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9f68717 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "dweipert/wp-theme-boilerplate", + "type": "wordpress-theme", + "description": "WordPress Theme Boilerplate", + "license": "GPL-2.0-or-later", + "authors": [ + { + "name": "Daniel Weipert", + "email": "code@drogueronin.de" + } + ], + "require": { + "php": ">=7.4", + "dweipert/wp-enqueue-assets": "^1.0", + "timber/timber": "^1.18" + }, + "autoload": { + "psr-4": { + "Theme\\": "app/" + } + } +} diff --git a/footer.php b/footer.php new file mode 100644 index 0000000..aab3545 --- /dev/null +++ b/footer.php @@ -0,0 +1,5 @@ + + {% block header %} + + {% endblock %} + +
+ {% block main %}{% endblock %} +
+ +{% endblock %} diff --git a/resources/views/components/menu-item.twig b/resources/views/components/menu-item.twig new file mode 100644 index 0000000..5bc41fc --- /dev/null +++ b/resources/views/components/menu-item.twig @@ -0,0 +1,10 @@ +
  • + {{ item.title }} + {% if current_depth < depth and item.children %} + + {% endif %} +
  • diff --git a/resources/views/index.twig b/resources/views/index.twig new file mode 100644 index 0000000..48b345c --- /dev/null +++ b/resources/views/index.twig @@ -0,0 +1,8 @@ +{% extends 'base.twig' %} + +{% block main %} + {% for post in posts %} +

    {{ post.title }}

    +

    {{ post.content }}

    + {% endfor %} +{% endblock %} diff --git a/resources/views/root.twig b/resources/views/root.twig new file mode 100644 index 0000000..3075eba --- /dev/null +++ b/resources/views/root.twig @@ -0,0 +1,17 @@ + + + + + + + + {% block meta %}{% endblock %} + {{ function('wp_head') }} + {% block css %}{% endblock %} + + +{% block body %}{% endblock %} +{{ function('wp_footer') }} +{% block js %}{% endblock %} + + diff --git a/style.css b/style.css new file mode 100644 index 0000000..c9ffac5 --- /dev/null +++ b/style.css @@ -0,0 +1,10 @@ +/* +Theme Name: WP Theme Boilerplate +Text Domain: textdomain +Version: 1.0.0 +Author: dweipert +Author URI: https://dweipert.de +Theme URI: https://gitlab.com/dweipert.de/wordpress/wp-theme-boilerplate +License: GNU General Public License v2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html +*/ diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..61ed3f6 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,12 @@ +const defaultConfig = require('@wordpress/scripts/config/webpack.config'); + +module.exports = { + ...defaultConfig, + + entry: { + index: [ + './resources/js/index.js', + './resources/css/index.scss', + ], + }, +}; -- cgit v1.2.3