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

Conversation

@jessynd
Copy link
Contributor

@jessynd jessynd commented Dec 23, 2020

Description

This is a package to be used with @wordpress/create-block. It is a template to generate the completed Gutenpride block plugin based on the Gutenpride Tutorial.

How has this been tested?

This package was tested using an npm package published privately at https://www.npmjs.com/package/jsa_gutenpride_template. This is how to reproduce the testing with this template in the published version currently on npm, which is identical to the one in this PR.

  1. Inside the gutenberg repository run npx wp-create-block --template jsa_gutenpride_template
  2. Go through the terminal prompts to create your plugin from the template.
  3. Take the generated plugin out of Gutenberg into the Plugins folder of a WP installation.
  4. Activate the plugin in WP
  5. Open the edit screen of a page or post and add the new block to the page.
  6. You should now see an input box that you can type text into and it will be saved and shown on the front end of the page. You will not however see the font displaying. This is because the font has been removed by the create-block plugin.
  7. To make the template work, download a fresh otf file and add it to the plugin folder.
  8. Reload your page and you should see the font reflected now.

In order to fix the issue of the create-block template removing the otf font when it creates the plugin, I published an additional version of the template which has the .mustache extension added to the otf font. In this version of the template the font is there in the plugin but create-block modifies it and it doesn't work either. To test this one, follow the instructions above but run npx wp-create-block --template jsa_gutenpride_template_otf_with_mustache instead. Compare the otf font included in the plugin with the original font downloaded above from https://www.typewithpride.com in a code editor. You will see that the font is modified by create-block.

Screenshots

Types of changes

This is a new feature to work with the @wordpress/create-block

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.
fabiankaegy and others added 10 commits Apr 29, 2020
Merge Master back into fork
Merge Master back into fork
Merge Master back into fork
Merge master back into fork
Merge main back into fork
Merge master into fork
Merge main into fork
Merge main into fork
merge master back into fork
@jessynd
Copy link
Contributor Author

@jessynd jessynd commented Dec 23, 2020

@gziolo The original intent of this package was to create a final version of the gutenpride template that would help showcase how third-party templates can be used with create-block. However, as you can see above, we encountered the issue of the otf font being either deleted or modified:

  1. The font is deleted by create-block if it doesn't have the .mustache extension.
  2. The font is modified by create-block if does have the .mustache extension, making it unusable.

I hope this draft PR might help troubleshoot this issue. Ideally it would be great for third-party templates, if developers could include files without a .mustache extension. This was a good experiment to help us figure that out.

@gziolo
Copy link
Member

@gziolo gziolo commented Dec 29, 2020

@jessynd thank you for all the fantastic work done so far! ❤️

You are 100% correct that assets like images or fonts don't quite fit to how it all currently works. It feels like we should either add another option in the block template package that defines the path to the folder with assets or use the convention where assets subfolder next to .mustache templates is copied over without processing. Option one seems to be less magic but it might create some friction when referencing those Can you think of any alternative?
Besides, it still isn't clear where we would need to move those assets in both cases.

@mkaz
Copy link
Member

@mkaz mkaz commented Jan 5, 2021

With regards to assets, I like the first option of having an asset folder that gets copied over. This seems quite straight-forward for some one implementing or using.

it still isn't clear where we would need to move those assets in both cases.

The assets would just get copied to the top level of the plugin that is created, right?

@gziolo
Copy link
Member

@gziolo gziolo commented Jan 5, 2021

Thanks @mkaz for sharing feedback. @leoloso and @fabiankaegy, do you have something to share as well?

I plan to look at adding support for assets in the template later this week. In addition to that, it would be great to add better support for assets in the default webpack config shipped with @wordpress/scripts.

@gziolo
Copy link
Member

@gziolo gziolo commented Jan 6, 2021

@jessynd, is the final goal of this PR to publish this template as part of WordPress npm packages? Assuming that all the listed issues are resolved.

@jessynd
Copy link
Contributor Author

@jessynd jessynd commented Jan 6, 2021

@gziolo and @mkaz thank you for your feedback! I agree that having an assets folder would be good.

The final goal of the PR is to publish it as part of WordPress as an example that can be referred to by developers wanting to develop their own third-party templates for the create-block package. It doesn't necessarily need to be this example, but since this is the block being used as an example in the create-block tutorial, it made sense that the third-party template could also match the create-block tutorial. I'm not sure if the tutorial will change given the ongoing discussion in #27565. If it does, the sample third-party template here could be adjusted to match that.

This template could also be referenced as an example in the tutorial on how to create third-party templates for the create-block package.

As a separate but related discussion: Have any decisions been made around how developers will be able to share third-party templates for create-block? Will there be an official naming convention for those wanting to share their templates to use when publishing to npm? If there will be, it will be good to replicate that in this example third-party template.

@gziolo gziolo mentioned this pull request Jan 7, 2021
6 of 6 tasks complete
@gziolo
Copy link
Member

@gziolo gziolo commented Jan 7, 2021

I opened #28038 with an initial proposal for assets handling.

It can be tested with jsa_gutenpride_template_otf_with_mustache package withe the following modifications:

  1. gilbert-color.otf.mustache -> assets/gilbert-color.otf
  2. In index.js, there needs to be assetsPath added:
    },
    templatesPath: __dirname,
    assetsPath: require( 'path' ).join( __dirname, 'assets' ),
};

With those changes published to npm, you can try to run the script with the branch from PR:

npx wp-create-block --template jsa_gutenpride_template_otf_with_mustache

It might be still buggy as my first attempt reads the content of the file and writes it to the new file. I don't know if it will work with fonts since it was causing when using mustache, but I hope that this issue was coming from the mustache processing. Otherwise, I will have to rework the processing of the downloaded template package to be able to copy files instead.

@gziolo
Copy link
Member

@gziolo gziolo commented Jan 7, 2021

@jessynd, thank you for all clarifications. I agree that it makes sense to include the proposed template as another WordPress package published to npm from the Gutenberg repository. As long as we keep it in sync with the tutorial it would be an amazing way to make it easier to follow it along. The other benefit you mentioned is also nice, the ability to showcase how to create custom templates by the community 👍🏻

As a separate but related discussion: Have any decisions been made around how developers will be able to share third-party templates for create-block? Will there be an official naming convention for those wanting to share their templates to use when publishing to npm? If there will be, it will be good to replicate that in this example third-party template.

I don't think we should enforce any conventions but we could give a good example by picking the proper pattern ourselves. I personally always look at this from the perspective of how would I name the package to have a bunch of them colocated in the folder director. Some existing examples:

Screen Shot 2021-01-07 at 13 43 39

Screen Shot 2021-01-07 at 13 43 45

I don't think that there is a well-established pattern in the JavaScript community:

Screen Shot 2021-01-07 at 13 45 01

Screen Shot 2021-01-07 at 13 48 56

Screen Shot 2021-01-07 at 13 45 45

For our purpose it could be: @wordpress/create-block-template-tutorial or @wordpress/create-block-tutorial-template.

@jessynd
Copy link
Contributor Author

@jessynd jessynd commented Jan 8, 2021

Thanks @gziolo! Tested it here #28038 (comment)

@jessynd
Copy link
Contributor Author

@jessynd jessynd commented Jan 14, 2021

@gziolo I think the suggestion you made above for the block to be named either @wordpress/create-block-template-tutorial OR @wordpress/create-block-tutorial-template is great. My preference is @wordpress/create-block-tutorial-template

Should I change the folder name to create-block-tutorial-template and all the files gutenpride is referenced?

@gziolo
Copy link
Member

@gziolo gziolo commented Jan 14, 2021

Should I change the folder name to create-block-tutorial-template and all the files gutenpride is referenced?

Yes, that's it and we can look at merging this PR 🎉

@gziolo gziolo marked this pull request as ready for review Jan 14, 2021
@gziolo gziolo requested review from ajitbohra and chrisvanpatten as code owners Jan 14, 2021
@gziolo
Copy link
Member

@gziolo gziolo commented Jan 14, 2021

@jessynd, how about you rename the package and we merge it so I could open PR with some janitorial changes? Otherwise, it might be difficult to explain what to tweak. It's mostly coding style related, the structure of the template might require some changes. Anyway, it's something that we could divide easier once we merge this PR.

@jessynd
Copy link
Contributor Author

@jessynd jessynd commented Jan 14, 2021

@gziolo I have pushed the name change. Now the package is at create-block-tutorial-template and I've swapped out the name everywhere gutenpride was referenced.

@jessynd
Copy link
Contributor Author

@jessynd jessynd commented Jan 14, 2021

Thank you for all your help and support @gziolo, @mkaz, @fabiankaegy, @brezocordero, @rbest!! I learned so much working through this first PR. It's been a really eye-opening and exciting process for me. 🥳🙏❤️

@gziolo gziolo changed the title Gutenpride Template Package New Package: Gutenpride Template Package for use with tutorial Jan 14, 2021
@gziolo gziolo changed the title New Package: Gutenpride Template Package for use with tutorial New Package: Gutenpride Template to use with the tutorial Jan 14, 2021
@gziolo
gziolo approved these changes Jan 15, 2021
Copy link
Member

@gziolo gziolo left a comment

Let's merge it as is. I plan to apply some follow-up enhancements in a follow-up PR.

Major kudos to @jessynd for taking us thus far 🎉

@gziolo gziolo merged commit 89b45fd into WordPress:master Jan 15, 2021
15 of 16 checks passed
15 of 16 checks passed
test (gutenberg-editor-gallery) test (gutenberg-editor-gallery)
Details
Build Release Artifact
Details
Cancel Previous Runs
Details
Check
Details
build
Details
Admin - 1 Admin - 1
Details
Run performance tests
Details
test (gutenberg-editor-gallery)
Details
All
Details
JavaScript
Details
Admin - 2 Admin - 2
Details
Admin - 3 Admin - 3
Details
Admin - 4 Admin - 4
Details
Create Release Draft and Attach Asset
Details
PHP
Details
Mobile
Details
@github-actions github-actions bot added this to the Gutenberg 9.9 milestone Jan 15, 2021
@gziolo
Copy link
Member

@gziolo gziolo commented Jan 15, 2021

I have just opened a follow-up PR with mostly janitorial changes: #28215.

gziolo added a commit that referenced this pull request Jan 15, 2021
* gutenpride template package created

* Create block: Add support for static assets

* Create Block: Add implementation for output assets

* Create block: Add support for static assets

* Create Block: Add implementation for output assets

* Stop using utf-8 encoding when reading static assets

* edited template to include assets

* gutenpride template package created

* edited template to include assets

* applying @gziolo's suggestions

* integrating feedback from @gziolo

* fixed the paths to built css files

* removing spaces

* fixed tested up to

* adding useblockProps to edit.js

* fixed urls to docs

* changed name of package from gutenpride-template to create-block-tutorial-template

* manifest

* changed slug and title of index.js file to match tutorial

* added @WordPress to read me terminal command

Co-authored-by: Fabian Kägy <[email protected]>
Co-authored-by: brezocordero <[email protected]>
Co-authored-by: Grzegorz Ziolkowski <[email protected]>
@gziolo gziolo modified the milestones: Gutenberg 9.9, Gutenberg 9.8 Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.