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

New Package: Gutenpride Template to use with the tutorial #27881

Merged
merged 35 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e324e8e
Merge pull request #1 from WordPress/master
fabiankaegy Apr 29, 2020
52be5aa
Merge pull request #2 from WordPress/master
fabiankaegy May 15, 2020
4b7b40e
Merge pull request #3 from WordPress/master
fabiankaegy May 21, 2020
4d9d2e0
Merge pull request #9 from WordPress/master
fabiankaegy May 29, 2020
4993875
Merge pull request #13 from WordPress/master
brezocordero Jun 20, 2020
4881f09
Merge pull request #14 from WordPress/master
brezocordero Jun 26, 2020
a1e92a6
Merge pull request #16 from WordPress/master
brezocordero Aug 15, 2020
7f41065
Merge pull request #17 from WordPress/master
brezocordero Nov 23, 2020
f7cae04
Merge pull request #18 from WordPress/master
fabiankaegy Nov 28, 2020
7945d75
gutenpride template package created
jessynd Dec 23, 2020
3c50043
Create block: Add support for static assets
gziolo Jan 7, 2021
e720a6d
Create Block: Add implementation for output assets
gziolo Jan 7, 2021
3d42782
Create block: Add support for static assets
gziolo Jan 7, 2021
45a8aec
Create Block: Add implementation for output assets
gziolo Jan 7, 2021
1e8d29a
Stop using utf-8 encoding when reading static assets
gziolo Jan 8, 2021
c06b22f
fixed utf-8
jessynd Jan 8, 2021
b975aec
edited template to include assets
jessynd Jan 8, 2021
64cc123
gutenpride template package created
jessynd Dec 23, 2020
734a5a2
edited template to include assets
jessynd Jan 8, 2021
66b307a
applying @gziolo's suggestions
jessynd Jan 12, 2021
dacc299
integrating feedback from @gziolo
jessynd Jan 12, 2021
242aecc
moved scss files to src
jessynd Jan 12, 2021
bbc5409
fixed the paths to built css files
jessynd Jan 12, 2021
48678a5
merge conflicts
jessynd Jan 12, 2021
25fd165
Merge branch 'master' into gutenpride-template-package-b
jessynd Jan 12, 2021
e3888fa
removing spaces
jessynd Jan 12, 2021
bb6eab4
fixed tested up to
jessynd Jan 12, 2021
7c73995
Merge branch 'master' into gutenpride-template-package-b
jessynd Jan 14, 2021
61f0c34
adding useblockProps to edit.js
jessynd Jan 14, 2021
4305b13
fixed urls to docs
jessynd Jan 14, 2021
a47601a
Merge branch 'master' into gutenpride-template-package-b
jessynd Jan 14, 2021
065fa3c
changed name of package from gutenpride-template to create-block-tuto…
jessynd Jan 14, 2021
3b99aff
manifest
jessynd Jan 14, 2021
4bf4309
changed slug and title of index.js file to match tutorial
jessynd Jan 14, 2021
e70284d
added @wordpress to read me terminal command
jessynd Jan 14, 2021
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
1 change: 1 addition & 0 deletions packages/gutenpride-template/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 5 additions & 0 deletions packages/gutenpride-template/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/master/packages#maintaining-changelogs. -->

## Unreleased

Initial release.
13 changes: 13 additions & 0 deletions packages/gutenpride-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Gutenpride Template

A package containing a block template to use with @wordpress/create-block.
gziolo marked this conversation as resolved.
Show resolved Hide resolved

## Usage

This block template can be used by running the following command:

```bash
npm @wordpress/create-block --template gutenpride-template
gziolo marked this conversation as resolved.
Show resolved Hide resolved
```

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
20 changes: 20 additions & 0 deletions packages/gutenpride-template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@wordpress/gutenpride-template",
"version": "1.0.0-prerelease",
"description": "A package containing a block template to use with @wordpress/create-block.",
gziolo marked this conversation as resolved.
Show resolved Hide resolved
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"keywords": [ "wordpress", "create block", "gutenpride", "block template" ],
"homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/gutenpride-template/README.md",
gziolo marked this conversation as resolved.
Show resolved Hide resolved
"repository": {
"type": "git",
"url": "https://github.com/WordPress/gutenberg.git",
"directory": "packages/gutenpride-template"
},
"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"publishConfig": {
"access": "public"
}
}
69 changes: 69 additions & 0 deletions packages/gutenpride-template/src/$slug.php.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Plugin Name: {{title}}
{{#description}}
* Description: {{description}}
{{/description}}
* Version: {{version}}
{{#author}}
* Author: {{author}}
{{/author}}
{{#license}}
* License: {{license}}
{{/license}}
{{#licenseURI}}
* License URI: {{{licenseURI}}}
{{/licenseURI}}
* Text Domain: {{textdomain}}
*
* @package {{namespace}}
*/

/**
* Registers all block assets so that they can be enqueued through the block editor
* in the corresponding context.
*
* @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/
*/
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
$dir = dirname( __FILE__ );

$script_asset_path = "$dir/build/index.asset.php";
if ( ! file_exists( $script_asset_path ) ) {
throw new Error(
'You need to run `npm start` or `npm run build` for the "{{namespace}}/{{textdomain}}" block first.'
);
}
$index_js = 'build/index.js';
$script_asset = require( $script_asset_path );
wp_register_script(
'{{namespace}}-{{slug}}-block-editor',
plugins_url( $index_js, __FILE__ ),
$script_asset['dependencies'],
$script_asset['version']
);
wp_set_script_translations( '{{namespace}}-{{slug}}-block-editor', '{{textdomain}}' );

$editor_css = 'editor.css';
wp_register_style(
'{{namespace}}-{{slug}}-block-editor',
plugins_url( $editor_css, __FILE__ ),
array(),
filemtime( "$dir/$editor_css" )
);

$style_css = 'style.css';
wp_register_style(
'{{namespace}}-{{slug}}-block',
plugins_url( $style_css, __FILE__ ),
array(),
filemtime( "$dir/$style_css" )
);

register_block_type( '{{namespace}}/{{slug}}', array(
'editor_script' => '{{namespace}}-{{slug}}-block-editor',
'editor_style' => '{{namespace}}-{{slug}}-block-editor',
'style' => '{{namespace}}-{{slug}}-block',
) );
}
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
Binary file not shown.
14 changes: 14 additions & 0 deletions packages/gutenpride-template/src/editor.css.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* The following styles get applied inside the editor only.
*
* Replace them with your own styles or remove the file completely.
*/

.wp-block-{{namespace}}-{{slug}} {
border: 1px dotted #f00;
}

.wp-block-{{namespace}}-{{slug}} input[type='text'] {
font-family: Gilbert;
font-size: 64px;
}
13 changes: 13 additions & 0 deletions packages/gutenpride-template/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
defaultValues: {
slug: 'block-template-gutenpride',
namespace: 'gutenpride',
title: 'Gutenpride',
description:
'A Gutenberg block to show your pride! This block enables you to type text and style it with the color font Gilbert from Type with Pride',

dashicon: 'smiley',
},
templatesPath: __dirname,
assetsPath: require( 'path' ).join( __dirname, 'assets' ),
};
57 changes: 57 additions & 0 deletions packages/gutenpride-template/src/readme.txt.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
=== Gutenpride ===
gziolo marked this conversation as resolved.
Show resolved Hide resolved
Contributors: The WordPress Contributors
Tags: block
Requires at least: 5.5.0
Tested up to: 5.5.1
gziolo marked this conversation as resolved.
Show resolved Hide resolved
Stable tag: 0.1.0
Requires PHP: 7.0.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Example block written with ESNext standard and JSX support – build step required.

== Description ==

This is the long description. No limit, and you can use Markdown (as well as in the following sections).

For backwards compatibility, if this section is missing, the full length of the short description will be used, and
Markdown parsed.

== Installation ==

This section describes how to install the plugin and get it working.

e.g.

1. Upload the plugin files to the `/wp-content/plugins/gutenpride` directory, or install the plugin through the WordPress plugins screen directly.
1. Activate the plugin through the 'Plugins' screen in WordPress


== Frequently Asked Questions ==

= A question that someone might have =

An answer to that question.

= What about foo bar? =

Answer to foo bar dilemma.

== Screenshots ==

1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
(or jpg, jpeg, gif).
2. This is the second screen shot

== Changelog ==

= 0.1.0 =
* Release

== Arbitrary section ==

You may provide arbitrary sections, in the same format as the ones above. This may be of use for extremely complicated
plugins where more information needs to be conveyed that doesn't fit into the categories of "description" or
"installation." Arbitrary sections will be shown below the built-in sections outlined above.
29 changes: 29 additions & 0 deletions packages/gutenpride-template/src/src/edit.js.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-i18n/
*/
import { Placeholder, TextControl } from '@wordpress/components';
gziolo marked this conversation as resolved.
Show resolved Hide resolved
import { __ } from '@wordpress/i18n';


/**
* The edit function describes the structure of your block in the context of the
* editor. This represents what the editor will render when the block is used.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit
*
* @param {Object} [props] Properties passed from the editor.
* @param {string} [props.className] Class name generated for the block.
*
* @return {WPElement} Element to render.
*/
export default function Edit( { attributes, className, setAttributes } ) {
return (
<TextControl
className={ className }
gziolo marked this conversation as resolved.
Show resolved Hide resolved
value={ attributes.message }
onChange={ ( val ) => setAttributes( { message: val } ) }
/>
);
}
86 changes: 86 additions & 0 deletions packages/gutenpride-template/src/src/index.js.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
*/
import { registerBlockType } from '@wordpress/blocks';

/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-i18n/
*/
import { __ } from '@wordpress/i18n';


/**
* Internal dependencies
*/
import Edit from './edit';
import save from './save';

/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
*/
registerBlockType('{{namespace}}/{{slug}}', {
/**
* This is the display title for your block, which can be translated with `i18n` functions.
* The block inserter will show this name.
*/
title: __('{{title}}', '{{textdomain}}'),

{{#description}}
/**
* This is a short description for your block, can be translated with `i18n` functions.
* It will be shown in the Block Tab in the Settings Sidebar.
*/
description: __(
'{{description}}',
'{{textdomain}}'
),

{{/description}}

/**
* Blocks are grouped into categories to help users browse and discover them.
* The categories provided by core are `common`, `embed`, `formatting`, `layout` and `widgets`.
*/
category: '{{category}}',

{{#dashicon}}
/**
* An icon property should be specified to make it easier to identify a block.
* These can be any of WordPress’ Dashicons, or a custom svg element.
*/
icon: '{{dashicon}}',

{{/dashicon}}

attributes: {
gziolo marked this conversation as resolved.
Show resolved Hide resolved
message: {
type: 'string',
source: 'text',
selector: 'div',
},
},

/**
* Optional block extended support features.
*/
supports: {
// Removes support for an HTML mode.
html: false,
},

/**
* @see ./edit.js
*/
edit: Edit,

/**
* @see ./save.js
*/
save,
});
19 changes: 19 additions & 0 deletions packages/gutenpride-template/src/src/save.js.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-i18n/
*/
import { __ } from '@wordpress/i18n';

/**
* The save function defines the way in which the different attributes should
* be combined into the final markup, which is then serialized by the block
* editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
*
* @return {WPElement} Element to render.
*/
export default function Save( { attributes, className } ) {
return <div className={ className }>{ attributes.message }</div>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a fix for this in save.js.mustache. In edit.js.mustache, Should I wrap a <div { ...useBlockProps() }> around <TextControl>?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. In theorhy, it should work with Input as well, but I don't know that :)

}
10 changes: 10 additions & 0 deletions packages/gutenpride-template/src/style.css.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@font-face {
font-family: Gilbert;
src: url(./assets/gilbert-color.otf);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assets are copied to assets folder that is at the same level as src in the generated plugin:

Suggested change
src: url(./assets/gilbert-color.otf);
src: url(../assets/gilbert-color.otf);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jessynd This also answers your question regarding the assets folder. The folder won't actually show up after you have build the block from the template. It is only for the template itself :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough context but I can explain what happens here. There are two folders in the scaffolded block:

  • assets with the font
  • src with JS and CSS files

wp-scripts build or wp-scripts start they start processing through src/index.js, so they need to be able to find a relative path to the font, that's why it goes one level up.

In the build folder, there is fonts folder create by webpack, and the font is probably copied there (I don't know webpack code).

font-weight: bold;
}

.wp-block-{{namespace}}-{{slug}} {
font-family: Gilbert;
font-size: 64px;
}