Skip to content

Commit

Permalink
Merge pull request #1 from firestar300/release/1.0.0
Browse files Browse the repository at this point in the history
Release/1.0.0
  • Loading branch information
Milan Ricoul authored Dec 8, 2021
2 parents 25f7bba + 7a6cd14 commit 252eeb3
Show file tree
Hide file tree
Showing 125 changed files with 6,622 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
33 changes: 33 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error",
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
]
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"tabWidth": 2,
"singleQuote": true
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 1.0.0
- Initial commit
- Add required WordPress files theme
- Add Vite and configuration
- Load assets for prodution / development environments
- Add Eslint
- Preloaded fonts
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
# vite-wordpress
A simple and quick WordPress starter theme
# Vite ⚡️ WordPress

Vite WordPress is a simple and quick WordPress starter theme using the fastest build tool: [Vite](https://vitejs.dev/).

## Get started 🚀

### Set WP_ENV constant

In your `wp-config.php` file, you have to define a `WP_ENV` constant according to your environment so that Vite WordPress can determine which assets need to be loaded.
In case you are in development mode, set the constant to `development`.

```php
define( 'WP_ENV', 'development' );
```

In production, set the constant to `production`.
```php
define( 'WP_ENV', 'production' );
```

### Install dependencies

Inside the starter theme, run :
```bash
$ yarn

# OR

$ npm install
```

### Development 🛠

Run your local backend server, then in your theme run :
```bash
$ yarn dev
```

### Build 📦

```bash
$ yarn build
```

## Known issues 🪲

### HTTPS

The theme currently doesn't work in dev environment with a https server. There is an infinite HMR reloading loop.

## [Change logs](CHANGELOG.md)
5 changes: 5 additions & 0 deletions footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
</main>
<footer id="footer" class="footer" role="contentinfo" aria-label="Pied de page"></footer>
<?php wp_footer(); ?>
</body>
</html>
6 changes: 6 additions & 0 deletions front-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
get_header();
?>
<div id="app"></div>
<?php
get_footer();
11 changes: 11 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* Load all services
*/
add_action(
'after_setup_theme',
function () {
// Boot the service, at after_setup_theme.
\ViteWP\Theme\Framework::get_container()->boot_services();
}
);
35 changes: 35 additions & 0 deletions header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html class="no-js" <?php language_attributes(); ?>>
<head>
<script type="text/javascript">
//<![CDATA[
(function(){
var c = document.documentElement.className;
c = c.replace(/no-js/, 'js');
document.documentElement.className = c;
})();
//]]>
</script>

<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="x-ua-compatible" content="ie=edge">

<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<ul class="skip-links skip-links--hidden" aria-label="Liens d'évitement">
<li>
<a href="#content">Contenu principal</a>
</li>
<li>
<a href="#footer">Pied de page</a>
</li>
</ul>

<header id="header" class="header" role="banner" aria-label="Entête de page"></header>

<main id="content" role="main" tabindex="-1" aria-label="Zone de contenus">
<?php
wp_body_open();
67 changes: 67 additions & 0 deletions inc/Framework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace ViteWP\Theme;

use ViteWP\Theme\Services\Assets;
use ViteWP\Theme\Services\Assets_JS_Async;
use ViteWP\Theme\Services\Fonts;
use ViteWP\Theme\Services\Editor;
use ViteWP\Theme\Services\Editor_Patterns;
use ViteWP\Theme\Services\Menu;
use ViteWP\Theme\Services\Sidebar;
use ViteWP\Theme\Services\Svg;
use ViteWP\Theme\Services\Theme;
use ViteWP\Theme\Tools\Body_Class;
use ViteWP\Theme\Tools\Template_Parts;

/**
* Class Framework
* @author Milan Ricoul
* @package ViteWP\Theme
*/
class Framework {
/**
* @var Service_Container
*/
protected static $container;

/**
* @var array $services
*/
protected static $services = [
// Services
Theme::class,
Assets::class,
Assets_JS_Async::class,
Fonts::class,
Editor::class,
Editor_Patterns::class,
Svg::class,
Menu::class,

// Services as Tools
Body_Class::class,
Template_Parts::class,
];

/**
* @return Service_Container
*/
public static function get_container(): Service_Container {
if ( is_null( self::$container ) ) {
self::$container = new Service_Container();
array_map( [ __CLASS__, 'register_service' ], self::$services );
}

return self::$container;
}

/**
* Register Service
*
* @param $name
*/
public static function register_service( $name ): void {
self::get_container()->register_service( $name );
}
}
17 changes: 17 additions & 0 deletions inc/Interface_Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
namespace ViteWP\Theme;

/**
* Interface Interface_Module
*
* @package ViteWP\Theme
*/
interface Interface_Module {

/**
* Register the module
*
* @param Service_Container $container
*/
public function register( Service_Container $container );
}
31 changes: 31 additions & 0 deletions inc/Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace ViteWP\Theme;

/**
* Interface Service
*
* @package ViteWP\Theme
*/
interface Service extends Interface_Module {

/**
* Register the service
*
* @param Service_Container $container
*/
public function register( Service_Container $container ): void;

/**
* Boot the service
*
* @param Service_Container $container
*/
public function boot( Service_Container $container ): void;

/**
* Get the service's name
*
* @return string
*/
public function get_service_name(): string;
}
92 changes: 92 additions & 0 deletions inc/Service_Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace ViteWP\Theme;

/**
* Class Service_Container
*
* @package ViteWP\Theme
*/
class Service_Container {

/**
* The registered services.
*
* @var array
*/
private $services = [];

/**
* Load all services.
*/
public function boot_services(): void {
$services = array_unique( $this->get_services() );
$services = array_map( [ $this, 'instantiate_service' ], $services );

array_walk(
$services,
function ( Service $service ) {
$service->boot( $this );
$this->services[ $service->get_service_name() ] = $service;
}
);
}

/**
* Get the list of services to register.
*
* @since 0.1.0
*
* @return array[string] Array of fully qualified class names.
*/
private function get_services(): array {
return $this->services;
}

/**
* Get a service's instance
*
* @param string $name the service name
*
* @return Service|bool The service instance or false if service not found
*/
public function get_service( string $name ) {
return $this->services[ $name ] ?? false;
}

/**
* Register a service
*
* @param string $service
*
* @return bool
* @author Clément Boirie
*/
public function register_service( string $service ): bool {
if ( ! class_exists( $service ) || ! in_array( Service::class, class_implements( $service ), true ) ) {
return false;
}

$this->services[ $service ] = $service;

return true;
}

/**
* Instantiate a single service.
*
* @param string $class Service class to instantiate.
*
* @return Service
*/
private function instantiate_service( string $class ): Service {
/**
* @var Service $service
*/
$service = new $class();
$service->register( $this );
$this->services[ $service->get_service_name() ] = $service;

return $this->services[ $service->get_service_name() ];
}
}
Loading

0 comments on commit 252eeb3

Please sign in to comment.