From 9d86ff12fce71ddadec901fa59f402907eeadd9e Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Tue, 10 Nov 2020 09:36:58 -0500 Subject: [PATCH 01/25] Add base files. --- blockbase/assets/alignments-front.css | 79 +++++++++++++++++++++++++++ blockbase/block-templates/index.html | 0 blockbase/experimental-theme.json | 28 ++++++++++ blockbase/functions.php | 34 ++++++++++++ blockbase/index.php | 0 blockbase/style.css | 15 +++++ 6 files changed, 156 insertions(+) create mode 100644 blockbase/assets/alignments-front.css create mode 100644 blockbase/block-templates/index.html create mode 100644 blockbase/experimental-theme.json create mode 100644 blockbase/functions.php create mode 100644 blockbase/index.php create mode 100644 blockbase/style.css diff --git a/blockbase/assets/alignments-front.css b/blockbase/assets/alignments-front.css new file mode 100644 index 00000000..7ce1aedc --- /dev/null +++ b/blockbase/assets/alignments-front.css @@ -0,0 +1,79 @@ +/* + * Alignments, loaded in the front-end only. + */ + +body { + margin: 0; +} + +* { + box-sizing: border-box; +} + +.wp-site-blocks, +.wp-block-template-part.alignfull { + padding: 0 var(--wp--custom--margin--horizontal); +} + +.wp-site-blocks > *:not(.wp-block-post-content), +.wp-site-blocks .wp-block-post-content > * { + max-width: var(--wp--custom--width--default); + margin-left: auto; + margin-right: auto; +} + +.wp-site-blocks .alignwide { + width: var(--wp--custom--width--wide); + max-width: 100%; + margin-left: auto; + margin-right: auto; +} + +.wp-site-blocks .alignfull { + transform: translateX(calc(0px - var(--wp--custom--width-horizontal))); + width: calc(100% + (2 * var(--wp--custom--width-horizontal))); + max-width: calc(100% + (2 * var(--wp--custom--width-horizontal))); + margin-left: 0; + margin-right: 0; + box-sizing: content-box; +} + +.wp-site-blocks .wp-block-template-part.alignfull { + width: 100%; + max-width: 100%; +} + +.wp-site-blocks .wp-block-columns.alignfull { + width: 100%; + max-width: 100%; +} + +.aligncenter { + text-align: center; +} + +.wp-site-blocks .alignleft { + float: left; + margin-right: 2em; + max-width: 360px; +} + +.wp-site-blocks .alignright { + float: right; + margin-left: 2em; + max-width: 360px; +} + +@media screen and (min-width: 1290px) { + + .wp-site-blocks, + .wp-block-template-part.alignfull { + padding: 0; + } + + .wp-site-blocks .alignfull { + transform: translateX(0px); + width: 100% + var(--wp--custom--width-horizontal)); + max-width: calc(100% + var(--wp--custom--width-horizontal)); + } +} \ No newline at end of file diff --git a/blockbase/block-templates/index.html b/blockbase/block-templates/index.html new file mode 100644 index 00000000..e69de29b diff --git a/blockbase/experimental-theme.json b/blockbase/experimental-theme.json new file mode 100644 index 00000000..887fa02f --- /dev/null +++ b/blockbase/experimental-theme.json @@ -0,0 +1,28 @@ +{ + "global": { + "settings": { + "color": { + "gradients": [ ], + "palette": [ ] + }, + "typography": { + "customFontSize": true, + "customLineHeight": true, + "fontSizes": [ ], + "spacing": { + "customPadding": true, + "units": [ "px", "em", "rem", "vh", "vw" ] + } + }, + "custom": { + "width": { + "default": "580px", + "wide": "1100px" + }, + "margin": { + "horizontal": "14px" + } + } + } + } +} diff --git a/blockbase/functions.php b/blockbase/functions.php new file mode 100644 index 00000000..480798e8 --- /dev/null +++ b/blockbase/functions.php @@ -0,0 +1,34 @@ + Date: Tue, 10 Nov 2020 09:44:04 -0500 Subject: [PATCH 02/25] Add editor alignments. --- blockbase/assets/alignments-editor.css | 15 +++++++++++++++ blockbase/functions.php | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 blockbase/assets/alignments-editor.css diff --git a/blockbase/assets/alignments-editor.css b/blockbase/assets/alignments-editor.css new file mode 100644 index 00000000..42e79eac --- /dev/null +++ b/blockbase/assets/alignments-editor.css @@ -0,0 +1,15 @@ +/* + * Alignments, loaded in the editor only. + */ + +.wp-block { + max-width: var(--wp--custom--width--default); +} + +.wp-block[data-align="wide"] { + max-width: var(--wp--custom--width--wide); +} + +.wp-block[data-align="full"] { + max-width: none; +} diff --git a/blockbase/functions.php b/blockbase/functions.php index 480798e8..66a165c3 100644 --- a/blockbase/functions.php +++ b/blockbase/functions.php @@ -19,7 +19,10 @@ function blockbase_support() { add_theme_support( 'editor-styles' ); // Enqueue editor styles. - add_editor_style( 'style.css' ); + add_editor_style( array( + 'style.css', + 'assets/alignments-editor.css' + ) ); } add_action( 'after_setup_theme', 'blockbase_support' ); endif; From eafbc73208814e1a9eb0d50b90aadcc9de63ecbf Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Tue, 10 Nov 2020 10:40:54 -0500 Subject: [PATCH 03/25] Remove editor alignments. --- blockbase/assets/alignments-editor.css | 15 --------------- blockbase/functions.php | 5 +---- 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 blockbase/assets/alignments-editor.css diff --git a/blockbase/assets/alignments-editor.css b/blockbase/assets/alignments-editor.css deleted file mode 100644 index 42e79eac..00000000 --- a/blockbase/assets/alignments-editor.css +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Alignments, loaded in the editor only. - */ - -.wp-block { - max-width: var(--wp--custom--width--default); -} - -.wp-block[data-align="wide"] { - max-width: var(--wp--custom--width--wide); -} - -.wp-block[data-align="full"] { - max-width: none; -} diff --git a/blockbase/functions.php b/blockbase/functions.php index 66a165c3..480798e8 100644 --- a/blockbase/functions.php +++ b/blockbase/functions.php @@ -19,10 +19,7 @@ function blockbase_support() { add_theme_support( 'editor-styles' ); // Enqueue editor styles. - add_editor_style( array( - 'style.css', - 'assets/alignments-editor.css' - ) ); + add_editor_style( 'style.css' ); } add_action( 'after_setup_theme', 'blockbase_support' ); endif; From c2e5a492b87ba39aaa0729dec5376a2acf72cf25 Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Tue, 10 Nov 2020 11:21:09 -0500 Subject: [PATCH 04/25] Update content width to match Gutenberg's default. --- blockbase/experimental-theme.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockbase/experimental-theme.json b/blockbase/experimental-theme.json index 887fa02f..93c63569 100644 --- a/blockbase/experimental-theme.json +++ b/blockbase/experimental-theme.json @@ -16,7 +16,7 @@ }, "custom": { "width": { - "default": "580px", + "default": "840px", "wide": "1100px" }, "margin": { From cb88cb0aa94b5f89431307d5dd89de3679e673a2 Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Thu, 12 Nov 2020 08:55:01 -0500 Subject: [PATCH 05/25] Add additional (empty) json values as examples. --- blockbase/experimental-theme.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/blockbase/experimental-theme.json b/blockbase/experimental-theme.json index 93c63569..d8895ce6 100644 --- a/blockbase/experimental-theme.json +++ b/blockbase/experimental-theme.json @@ -8,7 +8,12 @@ "typography": { "customFontSize": true, "customLineHeight": true, + "fontFamilies": [ ], "fontSizes": [ ], + "fontStyles": [ ], + "fontWeights": [ ], + "textDecorations": [ ], + "textTransforms": [ ], "spacing": { "customPadding": true, "units": [ "px", "em", "rem", "vh", "vw" ] @@ -23,6 +28,10 @@ "horizontal": "14px" } } + }, + "styles": { + "color": { }, + "typography": {} } } } From ee0c5772d6a956e969ebe08264f4433f1e5e8044 Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Fri, 13 Nov 2020 11:14:14 -0500 Subject: [PATCH 06/25] Rename to emptytheme --- .../assets/alignments-front.css | 0 .../block-templates/index.html | 0 {blockbase => emptytheme}/experimental-theme.json | 0 {blockbase => emptytheme}/functions.php | 14 +++++++------- {blockbase => emptytheme}/index.php | 0 {blockbase => emptytheme}/style.css | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) rename {blockbase => emptytheme}/assets/alignments-front.css (100%) rename {blockbase => emptytheme}/block-templates/index.html (100%) rename {blockbase => emptytheme}/experimental-theme.json (100%) rename {blockbase => emptytheme}/functions.php (58%) rename {blockbase => emptytheme}/index.php (100%) rename {blockbase => emptytheme}/style.css (56%) diff --git a/blockbase/assets/alignments-front.css b/emptytheme/assets/alignments-front.css similarity index 100% rename from blockbase/assets/alignments-front.css rename to emptytheme/assets/alignments-front.css diff --git a/blockbase/block-templates/index.html b/emptytheme/block-templates/index.html similarity index 100% rename from blockbase/block-templates/index.html rename to emptytheme/block-templates/index.html diff --git a/blockbase/experimental-theme.json b/emptytheme/experimental-theme.json similarity index 100% rename from blockbase/experimental-theme.json rename to emptytheme/experimental-theme.json diff --git a/blockbase/functions.php b/emptytheme/functions.php similarity index 58% rename from blockbase/functions.php rename to emptytheme/functions.php index 480798e8..de1115ff 100644 --- a/blockbase/functions.php +++ b/emptytheme/functions.php @@ -1,7 +1,7 @@ Date: Fri, 13 Nov 2020 11:38:56 -0500 Subject: [PATCH 07/25] Small consistency fix. --- emptytheme/experimental-theme.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emptytheme/experimental-theme.json b/emptytheme/experimental-theme.json index d8895ce6..1e4a42ee 100644 --- a/emptytheme/experimental-theme.json +++ b/emptytheme/experimental-theme.json @@ -31,7 +31,7 @@ }, "styles": { "color": { }, - "typography": {} + "typography": { } } } } From 4b830f6bb824f9bcb78124e6451268d8d6a644fd Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Fri, 13 Nov 2020 11:39:15 -0500 Subject: [PATCH 08/25] Get front-end stylesheets loading again. --- emptytheme/functions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/emptytheme/functions.php b/emptytheme/functions.php index de1115ff..d4f99380 100644 --- a/emptytheme/functions.php +++ b/emptytheme/functions.php @@ -28,7 +28,11 @@ function emptytheme_support() { * Enqueue scripts and styles. */ function emptytheme_scripts() { - wp_enqueue_style( 'emptytheme-styles', get_stylesheet_uri() ); - wp_enqueue_style( 'emptytheme-block-styles', get_template_directory_uri() . '/assets/alignments-frontend.css' ); + + // Enqueue theme stylesheet. + wp_enqueue_style( 'emptytheme-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) ); + + // Enqueue alignments stylesheet. + wp_enqueue_style( 'emptytheme-alignments-style', get_template_directory_uri() . '/assets/alignments-front.css', array(), wp_get_theme()->get( 'Version' ) ); } add_action( 'wp_enqueue_scripts', 'emptytheme_scripts' ); From 0a32985b55e70d83ce73d211fd479a282943f112 Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Fri, 13 Nov 2020 15:41:52 -0500 Subject: [PATCH 09/25] Remove a few experimental or unnecessary theme.json settings. --- emptytheme/experimental-theme.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/emptytheme/experimental-theme.json b/emptytheme/experimental-theme.json index 1e4a42ee..1f1f874a 100644 --- a/emptytheme/experimental-theme.json +++ b/emptytheme/experimental-theme.json @@ -6,17 +6,11 @@ "palette": [ ] }, "typography": { - "customFontSize": true, "customLineHeight": true, "fontFamilies": [ ], "fontSizes": [ ], - "fontStyles": [ ], - "fontWeights": [ ], - "textDecorations": [ ], - "textTransforms": [ ], "spacing": { - "customPadding": true, - "units": [ "px", "em", "rem", "vh", "vw" ] + "customPadding": true } }, "custom": { From fae49bad8e8e2eb2b0810b28dc2791f1ccb9179c Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Mon, 16 Nov 2020 09:19:31 -0500 Subject: [PATCH 10/25] Add support for featured images. --- emptytheme/functions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/emptytheme/functions.php b/emptytheme/functions.php index d4f99380..5ccc5e83 100644 --- a/emptytheme/functions.php +++ b/emptytheme/functions.php @@ -3,7 +3,10 @@ if ( ! function_exists( 'emptytheme_support' ) ) : function emptytheme_support() { - // Alignwide and alignfull classes in the block editor + // Adding support for featured images. + add_theme_support( 'post-thumbnails' ); + + // Adding support for alignwide and alignfull classes in the block editor. add_theme_support( 'align-wide' ); // Adding support for core block visual styles. From 5a320279cfc3fd282306c464e262d25ad481a70b Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Wed, 18 Nov 2020 08:13:03 -0500 Subject: [PATCH 11/25] Fix variable name. --- emptytheme/assets/alignments-front.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/emptytheme/assets/alignments-front.css b/emptytheme/assets/alignments-front.css index 7ce1aedc..9867ab1f 100644 --- a/emptytheme/assets/alignments-front.css +++ b/emptytheme/assets/alignments-front.css @@ -30,9 +30,9 @@ body { } .wp-site-blocks .alignfull { - transform: translateX(calc(0px - var(--wp--custom--width-horizontal))); - width: calc(100% + (2 * var(--wp--custom--width-horizontal))); - max-width: calc(100% + (2 * var(--wp--custom--width-horizontal))); + transform: translateX(calc(0px - var(--wp--custom--margin--horizontal))); + width: calc(100% + (2 * var(--wp--custom--margin--horizontal))); + max-width: calc(100% + (2 * var(--wp--custom--margin--horizontal))); margin-left: 0; margin-right: 0; box-sizing: content-box; @@ -73,7 +73,7 @@ body { .wp-site-blocks .alignfull { transform: translateX(0px); - width: 100% + var(--wp--custom--width-horizontal)); - max-width: calc(100% + var(--wp--custom--width-horizontal)); + width: 100% + var(--wp--custom--margin--horizontal)); + max-width: calc(100% + var(--wp--custom--margin--horizontal)); } } \ No newline at end of file From c75159fe065cdf6344e2049d99c6ccbfe8934409 Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Mon, 23 Nov 2020 09:48:31 -0500 Subject: [PATCH 12/25] Move experimental link color opt-in to theme.json --- emptytheme/experimental-theme.json | 1 + emptytheme/functions.php | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/emptytheme/experimental-theme.json b/emptytheme/experimental-theme.json index 1f1f874a..eeeadfda 100644 --- a/emptytheme/experimental-theme.json +++ b/emptytheme/experimental-theme.json @@ -3,6 +3,7 @@ "settings": { "color": { "gradients": [ ], + "link": true, "palette": [ ] }, "typography": { diff --git a/emptytheme/functions.php b/emptytheme/functions.php index 5ccc5e83..d47a7c3b 100644 --- a/emptytheme/functions.php +++ b/emptytheme/functions.php @@ -15,9 +15,6 @@ function emptytheme_support() { // Adding support for responsive embedded content. add_theme_support( 'responsive-embeds' ); - // Add support for experimental link color control. - add_theme_support( 'experimental-link-color' ); - // Add support for editor styles. add_theme_support( 'editor-styles' ); From 2c6d4e15f35093f0531259c58471ab06e1d7fe79 Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Mon, 23 Nov 2020 09:58:14 -0500 Subject: [PATCH 13/25] Add some base templates. --- emptytheme/assets/block-template-parts | 0 emptytheme/block-template-parts/header.html | 3 +++ emptytheme/block-templates/index.html | 9 +++++++++ emptytheme/block-templates/singular.html | 5 +++++ 4 files changed, 17 insertions(+) create mode 100644 emptytheme/assets/block-template-parts create mode 100644 emptytheme/block-template-parts/header.html create mode 100644 emptytheme/block-templates/singular.html diff --git a/emptytheme/assets/block-template-parts b/emptytheme/assets/block-template-parts new file mode 100644 index 00000000..e69de29b diff --git a/emptytheme/block-template-parts/header.html b/emptytheme/block-template-parts/header.html new file mode 100644 index 00000000..388c2232 --- /dev/null +++ b/emptytheme/block-template-parts/header.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/emptytheme/block-templates/index.html b/emptytheme/block-templates/index.html index e69de29b..591f9012 100644 --- a/emptytheme/block-templates/index.html +++ b/emptytheme/block-templates/index.html @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/emptytheme/block-templates/singular.html b/emptytheme/block-templates/singular.html new file mode 100644 index 00000000..69eef0a7 --- /dev/null +++ b/emptytheme/block-templates/singular.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file From 6bcfc78e479afa6e5823113c6796c545ba9693b3 Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Wed, 25 Nov 2020 18:53:06 +0100 Subject: [PATCH 14/25] initial script that creates the zip and changes style.css --- new-empty-theme.php | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 new-empty-theme.php diff --git a/new-empty-theme.php b/new-empty-theme.php new file mode 100644 index 00000000..403e1ecf --- /dev/null +++ b/new-empty-theme.php @@ -0,0 +1,84 @@ +theme['name'] = trim(fgets($handle)); + $this->theme['slug'] = urlencode($this->theme['name']); + $this->create_zip(); + } + + function create_zip() { + + if($this->theme['name'] === ''){ + echo "ABORTING!\n"; + exit; + } + + $zip = new ZipArchive; + $zip_filename = sprintf( '%s.zip', md5( print_r( $this->theme['name'], true ) ) ); + $res = $zip->open( $zip_filename, ZipArchive::CREATE && ZipArchive::OVERWRITE ); + + $prototype_dir = 'emptytheme/'; + + $exclude_files = array( '.travis.yml', 'codesniffer.ruleset.xml', '.jscsrc', '.jshintignore', 'CONTRIBUTING.md', '.git', '.svn', '.DS_Store', '.gitignore', '.', '..' ); + $exclude_directories = array( '.git', '.svn', '.github', '.', '..' ); + + $iterator = new RecursiveDirectoryIterator( $prototype_dir ); + foreach ( new RecursiveIteratorIterator( $iterator ) as $filename ) { + + if ( in_array( basename( $filename ), $exclude_files ) ) + continue; + + foreach ( $exclude_directories as $directory ) + if ( strstr( $filename, "/{$directory}/" ) ) + continue 2; // continue the parent foreach loop + + $local_filename = str_replace( $prototype_dir, '', $filename ); + + $contents = file_get_contents( $filename ); + + $zip->addFromString( $this->theme['slug'] . '/' . $local_filename, $this->replace_theme_name($contents, $local_filename) ); + } + $zip->close(); + + echo "\n"; + echo "Your ZIP file is ready!\n"; + } + + function replace_theme_name($contents, $filename) { + // Replace only text files, skip png's and other stuff. + $valid_extensions = array( 'php', 'css', 'scss', 'js', 'txt' ); + $valid_extensions_regex = implode( '|', $valid_extensions ); + if ( ! preg_match( "/\.({$valid_extensions_regex})$/", $filename ) ) + return $contents; + + // Special treatment for style.css + if ( $filename === 'style.css' ) { + $theme_headers = array( + 'Theme Name' => $this->theme['name'], + 'Text Domain' => $this->theme['slug'], + ); + + foreach ( $theme_headers as $key => $value ) { + $contents = preg_replace( '/(' . preg_quote( $key ) . ':)\s?(.+)/', '\\1 ' . $value, $contents ); + } + + $contents = preg_replace( '/\b_s\b/', $this->theme['name'], $contents ); + + return $contents; + } + } +} + +new Generate_Theme; +?> \ No newline at end of file From bcb6f1fda1eb0b116a110560fb6f7a0aa983886f Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Wed, 25 Nov 2020 19:03:44 +0100 Subject: [PATCH 15/25] replace theme slug in functions.php --- new-empty-theme.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/new-empty-theme.php b/new-empty-theme.php index 403e1ecf..2079c0b5 100644 --- a/new-empty-theme.php +++ b/new-empty-theme.php @@ -63,7 +63,7 @@ function replace_theme_name($contents, $filename) { return $contents; // Special treatment for style.css - if ( $filename === 'style.css' ) { + if ( 'style.css' === $filename ) { $theme_headers = array( 'Theme Name' => $this->theme['name'], 'Text Domain' => $this->theme['slug'], @@ -74,7 +74,12 @@ function replace_theme_name($contents, $filename) { } $contents = preg_replace( '/\b_s\b/', $this->theme['name'], $contents ); + return $contents; + } + // Special treatment for functions.php + if ( 'functions.php' === $filename ) { + $contents = str_replace( 'emptytheme', $this->theme['slug'], $contents ); return $contents; } } From 722af89a162cfa93bf93a1b954795dd1ffc92fe4 Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Wed, 25 Nov 2020 19:08:48 +0100 Subject: [PATCH 16/25] better treatment of space in the theme name --- new-empty-theme.php | 84 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/new-empty-theme.php b/new-empty-theme.php index 2079c0b5..bbb2744a 100644 --- a/new-empty-theme.php +++ b/new-empty-theme.php @@ -13,7 +13,8 @@ function __construct() { $handle = fopen ("php://stdin","r"); $this->theme['name'] = trim(fgets($handle)); - $this->theme['slug'] = urlencode($this->theme['name']); + $this->theme['slug'] = $this->sanitize_title_with_dashes($this->theme['name']); + $this->theme['functions_slug'] = str_replace( '-', '_', $this->theme['slug'] ); $this->create_zip(); } @@ -79,10 +80,89 @@ function replace_theme_name($contents, $filename) { // Special treatment for functions.php if ( 'functions.php' === $filename ) { - $contents = str_replace( 'emptytheme', $this->theme['slug'], $contents ); + $contents = str_replace( 'emptytheme', $this->theme['functions_slug'], $contents ); return $contents; } } + + function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'display' ) { + $title = strip_tags( $title ); + // Preserve escaped octets. + $title = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title ); + // Remove percent signs that are not part of an octet. + $title = str_replace( '%', '', $title ); + // Restore octets. + $title = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title ); + + $title = strtolower( $title ); + + if ( 'save' === $context ) { + // Convert  , &ndash, and &mdash to hyphens. + $title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title ); + // Convert  , &ndash, and &mdash HTML entities to hyphens. + $title = str_replace( array( ' ', ' ', '–', '–', '—', '—' ), '-', $title ); + // Convert forward slash to hyphen. + $title = str_replace( '/', '-', $title ); + + // Strip these characters entirely. + $title = str_replace( + array( + // Soft hyphens. + '%c2%ad', + // ¡ and ¿. + '%c2%a1', + '%c2%bf', + // Angle quotes. + '%c2%ab', + '%c2%bb', + '%e2%80%b9', + '%e2%80%ba', + // Curly quotes. + '%e2%80%98', + '%e2%80%99', + '%e2%80%9c', + '%e2%80%9d', + '%e2%80%9a', + '%e2%80%9b', + '%e2%80%9e', + '%e2%80%9f', + // Bullet. + '%e2%80%a2', + // ©, ®, °, &hellip, and &trade. + '%c2%a9', + '%c2%ae', + '%c2%b0', + '%e2%80%a6', + '%e2%84%a2', + // Acute accents. + '%c2%b4', + '%cb%8a', + '%cc%81', + '%cd%81', + // Grave accent, macron, caron. + '%cc%80', + '%cc%84', + '%cc%8c', + ), + '', + $title + ); + + // Convert × to 'x'. + $title = str_replace( '%c3%97', 'x', $title ); + } + + // Kill entities. + $title = preg_replace( '/&.+?;/', '', $title ); + $title = str_replace( '.', '-', $title ); + + $title = preg_replace( '/[^%a-z0-9 _-]/', '', $title ); + $title = preg_replace( '/\s+/', '-', $title ); + $title = preg_replace( '|-+|', '-', $title ); + $title = trim( $title, '-' ); + + return $title; + } } new Generate_Theme; From 3ca3b16d9b69dc28092446fdf9682eb57f96aace Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Thu, 26 Nov 2020 11:35:23 +0100 Subject: [PATCH 17/25] copied files to a folder instead of creating a ZIP --- new-empty-theme.php | 56 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/new-empty-theme.php b/new-empty-theme.php index bbb2744a..570d12cf 100644 --- a/new-empty-theme.php +++ b/new-empty-theme.php @@ -25,35 +25,35 @@ function create_zip() { exit; } - $zip = new ZipArchive; - $zip_filename = sprintf( '%s.zip', md5( print_r( $this->theme['name'], true ) ) ); - $res = $zip->open( $zip_filename, ZipArchive::CREATE && ZipArchive::OVERWRITE ); - - $prototype_dir = 'emptytheme/'; - - $exclude_files = array( '.travis.yml', 'codesniffer.ruleset.xml', '.jscsrc', '.jshintignore', 'CONTRIBUTING.md', '.git', '.svn', '.DS_Store', '.gitignore', '.', '..' ); - $exclude_directories = array( '.git', '.svn', '.github', '.', '..' ); - - $iterator = new RecursiveDirectoryIterator( $prototype_dir ); - foreach ( new RecursiveIteratorIterator( $iterator ) as $filename ) { - - if ( in_array( basename( $filename ), $exclude_files ) ) - continue; - - foreach ( $exclude_directories as $directory ) - if ( strstr( $filename, "/{$directory}/" ) ) - continue 2; // continue the parent foreach loop - - $local_filename = str_replace( $prototype_dir, '', $filename ); - - $contents = file_get_contents( $filename ); - - $zip->addFromString( $this->theme['slug'] . '/' . $local_filename, $this->replace_theme_name($contents, $local_filename) ); + $dir = $this->theme['slug']; + + if( is_dir($dir) === false ) { + + mkdir($dir); + $prototype_dir = 'emptytheme/'; + $exclude_files = array( '.travis.yml', 'codesniffer.ruleset.xml', '.jscsrc', '.jshintignore', 'CONTRIBUTING.md', '.git', '.svn', '.DS_Store', '.gitignore', '.', '..' ); + $exclude_directories = array( '.git', '.svn', '.github', '.', '..' ); + + foreach ( $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($prototype_dir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item ) { + if ( in_array( $iterator->getSubPathName(), $exclude_files ) || in_array( $iterator->getSubPathName(), $exclude_directories ) ){ + continue; + } + + if ($item->isDir()) { + mkdir($dir . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); + } else { + $contents = file_get_contents( $prototype_dir . $iterator->getSubPathName() ); + $file = fopen( $dir . '/' . $iterator->getSubPathName(),"w" ); + fwrite( $file, $this->replace_theme_name($contents, $iterator->getSubPathName()) ); + fclose( $file ); + } + } + echo "\n"; + echo "Your new theme is ready!\n"; + } else { + echo "\n"; + echo "This theme already exists\n"; } - $zip->close(); - - echo "\n"; - echo "Your ZIP file is ready!\n"; } function replace_theme_name($contents, $filename) { From 2644130963dc648e80c8c67e49214a93bee33a11 Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Thu, 26 Nov 2020 16:13:34 +0100 Subject: [PATCH 18/25] ask for further information from user --- new-empty-theme.php | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/new-empty-theme.php b/new-empty-theme.php index 570d12cf..c69be7c1 100644 --- a/new-empty-theme.php +++ b/new-empty-theme.php @@ -9,21 +9,46 @@ class Generate_Theme { protected $theme; function __construct() { - echo "What is the name of your theme?: "; - $handle = fopen ("php://stdin","r"); - $this->theme['name'] = trim(fgets($handle)); - $this->theme['slug'] = $this->sanitize_title_with_dashes($this->theme['name']); - $this->theme['functions_slug'] = str_replace( '-', '_', $this->theme['slug'] ); + $this->theme = array( + 'name' => 'Empty Theme', + 'slug' => 'emptytheme', + 'uri' => 'https://github.com/wordpress/theme-experiments/', + 'author' => 'Kjell Reigstad', + 'description' => 'The base for a block-based theme.', + ); + $this->get_theme_info(); $this->create_zip(); } - function create_zip() { + function get_theme_info() { + echo "Please provide the following information: "; + echo "\n"; + echo "Theme name: "; + $input = fopen ("php://stdin","r"); + $this->theme['name'] = trim(fgets($input)); if($this->theme['name'] === ''){ echo "ABORTING!\n"; exit; } + $this->theme['slug'] = $this->sanitize_title_with_dashes($this->theme['name']); + $this->theme['functions_slug'] = str_replace( '-', '_', $this->theme['slug'] ); + + echo "Description: "; + $input = fopen ("php://stdin","r"); + $this->theme['description'] = trim(fgets($input)); + + echo "Author: "; + $input = fopen ("php://stdin","r"); + $this->theme['author'] = trim(fgets($input)); + + echo "Theme URI: "; + $input = fopen ("php://stdin","r"); + $this->theme['uri'] = trim(fgets($input)); + } + + function create_zip() { $dir = $this->theme['slug']; @@ -68,6 +93,9 @@ function replace_theme_name($contents, $filename) { $theme_headers = array( 'Theme Name' => $this->theme['name'], 'Text Domain' => $this->theme['slug'], + 'Theme URI' => $this->theme['uri'], + 'Description' => $this->theme['description'], + 'Author' => $this->theme['author'], ); foreach ( $theme_headers as $key => $value ) { From 54d238b926c69e41d69e6b48b79e00d228ee2072 Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Thu, 26 Nov 2020 16:25:25 +0100 Subject: [PATCH 19/25] updated README with instructions --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 04240463..e239a3ed 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,12 @@ Here are some resources that may be useful context for learning more about block - [Full site editing development in the Gutenberg repo](https://github.com/WordPress/gutenberg/labels/%5BFeature%5D%20Full%20Site%20Editing) - [Global styles development in the Gutenberg repo](https://github.com/WordPress/gutenberg/issues?q=is%3Aissue+is%3Aopen+label%3A%22Global+Styles%22) +## Generating your own starter theme + +We have included a script so you can generate a theme based on a starter boilerplate with the minimum necessary to build your own block-based theme. You will need to have php installed to run it using: + +`php new-empty-theme.php` + ## Questions or Improvements? If you'd like to propose improvements to this repository, feel free to open an [issue](https://github.com/WordPress/theme-experiments/issues) or [PR](https://github.com/WordPress/theme-experiments/pulls). From b742f921fde2dab34b7272cc852b00c61d2eff91 Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Fri, 27 Nov 2020 11:43:55 +0100 Subject: [PATCH 20/25] renamed create_zip function --- new-empty-theme.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/new-empty-theme.php b/new-empty-theme.php index c69be7c1..5d2031c6 100644 --- a/new-empty-theme.php +++ b/new-empty-theme.php @@ -18,7 +18,7 @@ function __construct() { 'description' => 'The base for a block-based theme.', ); $this->get_theme_info(); - $this->create_zip(); + $this->create_folder(); } function get_theme_info() { @@ -48,7 +48,7 @@ function get_theme_info() { $this->theme['uri'] = trim(fgets($input)); } - function create_zip() { + function create_folder() { $dir = $this->theme['slug']; From ce27254c1b729fc2b4d7cf150b0ede7d7a124a60 Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Fri, 27 Nov 2020 11:58:13 +0100 Subject: [PATCH 21/25] moved the old theme name to variable, missing replace --- new-empty-theme.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/new-empty-theme.php b/new-empty-theme.php index 5d2031c6..54a60682 100644 --- a/new-empty-theme.php +++ b/new-empty-theme.php @@ -7,12 +7,14 @@ class Generate_Theme { protected $theme; + protected $old_themename = 'Empty Theme'; + protected $old_themeslug = 'emptytheme'; function __construct() { $this->theme = array( - 'name' => 'Empty Theme', - 'slug' => 'emptytheme', + 'name' => $this->old_themename, + 'slug' => $this->old_themeslug, 'uri' => 'https://github.com/wordpress/theme-experiments/', 'author' => 'Kjell Reigstad', 'description' => 'The base for a block-based theme.', @@ -55,7 +57,7 @@ function create_folder() { if( is_dir($dir) === false ) { mkdir($dir); - $prototype_dir = 'emptytheme/'; + $prototype_dir = $this->old_themeslug . '/'; $exclude_files = array( '.travis.yml', 'codesniffer.ruleset.xml', '.jscsrc', '.jshintignore', 'CONTRIBUTING.md', '.git', '.svn', '.DS_Store', '.gitignore', '.', '..' ); $exclude_directories = array( '.git', '.svn', '.github', '.', '..' ); @@ -82,6 +84,7 @@ function create_folder() { } function replace_theme_name($contents, $filename) { + // Replace only text files, skip png's and other stuff. $valid_extensions = array( 'php', 'css', 'scss', 'js', 'txt' ); $valid_extensions_regex = implode( '|', $valid_extensions ); @@ -102,15 +105,17 @@ function replace_theme_name($contents, $filename) { $contents = preg_replace( '/(' . preg_quote( $key ) . ':)\s?(.+)/', '\\1 ' . $value, $contents ); } - $contents = preg_replace( '/\b_s\b/', $this->theme['name'], $contents ); + $contents = str_replace( $this->old_themename, $this->theme['name'], $contents ); return $contents; } // Special treatment for functions.php if ( 'functions.php' === $filename ) { - $contents = str_replace( 'emptytheme', $this->theme['functions_slug'], $contents ); + $contents = str_replace( $this->old_themeslug, $this->theme['functions_slug'], $contents ); return $contents; } + + return $contents; } function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'display' ) { From add855cb07845bdcbd7d0b49762e026cc675bdac Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Fri, 27 Nov 2020 15:36:18 +0100 Subject: [PATCH 22/25] removed heading rules in favor of having them in GB --- twentytwentyone-blocks/assets/css/style-shared.css | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/twentytwentyone-blocks/assets/css/style-shared.css b/twentytwentyone-blocks/assets/css/style-shared.css index bc5a57ac..5c8e06b5 100644 --- a/twentytwentyone-blocks/assets/css/style-shared.css +++ b/twentytwentyone-blocks/assets/css/style-shared.css @@ -8,16 +8,6 @@ body { -webkit-font-smoothing: antialiased; } -h1, -.has-huge-font-size, -.has-gigantic-font-size { - font-weight: var(--wp--custom--font-weight-light); -} - -h2, h3, h4, h5, h6 { - font-weight: normal; -} - /* * text-underline-offset doesn't work in Chrome at all 👎 * But looks nice in Safari/Firefox, so let's keep it and From adf88f7e1b2d08ce5344f2f738a02d0e404a8057 Mon Sep 17 00:00:00 2001 From: Maggie Cabrera Date: Fri, 27 Nov 2020 15:37:45 +0100 Subject: [PATCH 23/25] Revert "removed heading rules in favor of having them in GB" This reverts commit add855cb07845bdcbd7d0b49762e026cc675bdac. --- twentytwentyone-blocks/assets/css/style-shared.css | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/twentytwentyone-blocks/assets/css/style-shared.css b/twentytwentyone-blocks/assets/css/style-shared.css index 5c8e06b5..bc5a57ac 100644 --- a/twentytwentyone-blocks/assets/css/style-shared.css +++ b/twentytwentyone-blocks/assets/css/style-shared.css @@ -8,6 +8,16 @@ body { -webkit-font-smoothing: antialiased; } +h1, +.has-huge-font-size, +.has-gigantic-font-size { + font-weight: var(--wp--custom--font-weight-light); +} + +h2, h3, h4, h5, h6 { + font-weight: normal; +} + /* * text-underline-offset doesn't work in Chrome at all 👎 * But looks nice in Safari/Firefox, so let's keep it and From 929f249e53835d36e35a69f20111ca223a3f031c Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Mon, 30 Nov 2020 10:34:14 -0500 Subject: [PATCH 24/25] Delete empty file. --- emptytheme/assets/block-template-parts | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 emptytheme/assets/block-template-parts diff --git a/emptytheme/assets/block-template-parts b/emptytheme/assets/block-template-parts deleted file mode 100644 index e69de29b..00000000 From 7d8f6b9a43871f31b34cb77d1a379eb3ad901eff Mon Sep 17 00:00:00 2001 From: Kjell Reigstad Date: Wed, 2 Dec 2020 10:44:30 -0500 Subject: [PATCH 25/25] Add theme to the main README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e239a3ed..477a623d 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This repository is dedicated to exploring how WordPress themes can best leverage | Theme | Updated For | | --- | --- | | [Ambitious](https://github.com/WordPress/theme-experiments/tree/master/ambitious) | Gutenberg 7.6 | +| [Empty Theme](https://github.com/WordPress/theme-experiments/tree/master/emptytheme) | Gutenberg 9.5 | | [Gutenberg Starter Theme Blocks](https://github.com/WordPress/theme-experiments/tree/master/gutenberg-starter-theme-blocks) | Gutenberg 8.6 | | [Twenty Nineteen Blocks](https://github.com/WordPress/theme-experiments/tree/master/twentynineteen-blocks) | Gutenberg 8.6 | | [Twenty Twenty Blocks](https://github.com/WordPress/theme-experiments/tree/master/twentytwenty-blocks) | Gutenberg 8.6 |