Skip to content

Instantly share code, notes, and snippets.

@laras126
Last active March 14, 2018 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laras126/d0237862058e5e89dc71d5f46fdb37ed to your computer and use it in GitHub Desktop.
Save laras126/d0237862058e5e89dc71d5f46fdb37ed to your computer and use it in GitHub Desktop.
A Gentle Introduction to Gutenberg Development: WordPress Meetup, Pittsburgh; March 13, 2018

A Gentle Introduction to Gutenberg Development

WordPress Meetup, Pittsburgh; March 13, 2018

Hello!

I'm Lara, not Laura.

@laras126 on Twitter // notlaura.com


"Learn JavaScript Deeply"

https://www.youtube.com/watch?v=KrZx4IY1IgU&

Did you? I didn't...


But this is very exciting for both us, and WordPress itself. https://twitter.com/rachsmithtweets/status/966081017764196352?ref_src=twsrc%5Etfw&ref_url=https%3A%2F%2Fcss-tricks.com%2F%3Fp%3D267715

And there's still time! Gutenberg won't be released for another couple of months, probably.


Things to know about today

  • Sometimes I go off on tangents – feel free to correct me.
  • This is informal and conversational – ask questions!
    • And there are no dumb questions...really! This is a safe space.
  • Try to remember concepts not code.

A quick look at the Gutenberg Interface

  • Local development environment
  • Plugin installed
  • Relatively simple theme activated
  • Make some blocks!

Notice these things...

  • Blocks can have data from other parts of the site
  • Blocks have options in the sidebar "Inspector"
  • Blocks can be nested...sort of
  • Don't forget to view it on the frontend

Deactivate Gutenberg

  • Now look at the editor...what do you see?

  • Now look at the frontend...what do you see?

  • Blocks are defined by HTML comments in the database, like this:

      <!-- wp:paragraph -->
      	<p>Stuff</p>
      <!-- /wp:paragraph -->
    

"React-driven SPA editing experience"

  • "editing experience"
    • Translation: Gutenberg is a redesign of the WYSIWYG editor (but so much more!).
  • "SPA"
    • Gutenberg is a Single Page Application within WordPress. Modern, fancy, no page reloads.
  • "React-driven"
    • Yes, Gutenberg is built in React. That’s probably not going to change anytime soon, if ever. But there was drama.

At the end of the day...

Tech-wise, it's just a fancy way of putting things in post_content. It's the user experience of making that happen that's undergoing an overhaul.


👆 Follow the instructions in the Readme of that link.


Let's set up our text editor

  • Integrated terminal
  • Gutenberg source for reference
  • Block plugin folder added to our sidebar

The plugin files

The most important ones are inside our block plugin, then inside the src directory:

└── src
	├── block
	|  ├── block.js
	|  ├── editor.scss
	|  └── style.scss
	|
	├── blocks.js
	├── common.scss
	└── init.php

Challenge time!

Start in block.js. See if you can figure out, by reading the code, how to:

  1. Change the name of your block, that is, the one that shows in the block selector
  2. Change the icon of your block (❤ Dashicons)
  3. Change the text that displays on the front end i.e. when you “View Post”
  4. Change the text that displays on the back end i.e. editor view
  5. Give the front end view a border radius of 30px
  6. Give the editor view a gradient background
  7. Make the text in first paragraph tag editable.

Did you get #7?

I hope not!


Skeleton of a Block

  • Settings
  • edit
  • save
  • editor.scss and style.scss

About number 7...

React!


Key Links


Stay tuned!

  • CSS-Tricks Series (probably end of this month)
  • I may try to organize a Gutenberg learning Hangout at some point – let me know if you would be interested!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment