Code Monkey home page Code Monkey logo

sb-debug-block's Introduction

Debug block

Single block server side rendered Debug block.

Description

The Debug block displays debugging information for WordPress Full Site Editing (FSE) themes. Depending on where it's used and attributes the debug block will display useful information when you're developing an FSE theme.

  • Template information
  • Template part information
  • Post content information

The debug block only produces output when the WP_DEBUG constant is true. It doesn't check WP_DEBUG_DISPLAY not SCRIPT_DEBUG.

There is no need to remove the debug blocks from the source. When the Debug block plugin isn't activated or WP_DEBUG isn't true the block will not be rendered.

In its simplest form the debug block is

<!-- wp:oik-sb/sb-debug-block /-->

Attributes (will) allow you to provide additional information

  • debug - any text you want included in the debug block's output
  • showTemplate - true/false - to include the escaped HTML for the template
  • showTemplatePart - true/false - to include the escaped HTML for the template part
  • showContents - true/false - to include the escaped HTML for the post content

Installation

  1. Edit wp-config.php to set WP_DEBUG to true.
  2. Install and activate the plugin.
  3. Use the Debug block in your templates, template parts or content.

Screenshots

  1. Debug block - rendered
  2. Debug block - settings

Upgrade Notice

0.0.0

Prototype version to support the Gutenberg feature request for two new action hooks

Changelog

0.0.0

  • Added: First version of the server side rendered block,#1
  • Added: Implement debugging for templates and template parts,#2
  • Tested: With WordPress 5.7.2 and WordPress Multi Site
  • Tested: With Gutenberg 10.6.0
  • Tested: With PHP 8.0

sb-debug-block's People

Contributors

bobbingwide avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

sb-debug-block's Issues

Implement oik-sb/sb-debug-block for debugging FSE templates and template parts

Background

In Fizzie, SB and ThisIs... I've used some custom HTML to add debug information to each template, and some template parts.
It appears at the top of each template enabling me to know which template I'm viewing.
eg In 404.html

<!-- wp:html -->
<div class="WP_DEBUG">404.html</div>
<!-- /wp:html -->

If I change the text in the .html file I can tell whether or not the template has been loaded from the file or the database.
It doesn't let me know which language version is being used though.

Similarly, it's nice to know where a template part starts, and possibly where it ends.
eg in the 404.html template part

<!-- wp:html -->
<div class="WP_DEBUG">404 template-part</div>
<!-- /wp:html -->

The first <div> with class WP_DEBUG is styled with CSS in the theme's style.css stylesheet to appear in the wp-admin top bar.
Others have a dotted red border and appear when hovered over.

In order to turn off debugging it's necessary to either remove the custom HTML or change the CSS.

Finally, the output-input.html template uses a template part called contents-shortcode.html which uses the [contents] shortcode to display the raw HTML of the post content - escaped to make it visible in the browser.
This can be used to check that what we see in the front end was produced from the blocks in the post's content

Requirements

  • Use the sb-debug-block to implement a similar solution to the hardcoded solution above
  • Dynamically adjust the output based on the value of certain constants
  • Provide a simple block UI to enable the user to indicate what they want the block to do

Proposed solution

  • Server Side Rendered block
  • Automatically determines the template name / template part name and where it was sourced.
  • If that's not possible display the value defined in the block's debug attribute
  • Generates the required CSS based on WP_DEBUG and/or SCRIPT_DEBUG and/or a block setting -eg Additional CSS class(es)
  • Displays the equivalent of the [contents] if the showContents block setting is toggled on. Default: false.
  • Display the HTML source for a particular block or group of blocks - to assist documentation.

Create sb-debug-block from sb-starting-block template

I want to be able to create single block plugins easily. It appears that a simple solution was to make the sb-starting-block repository a template and to generate a new repository from the template.
Then it just needs a little refactoring:

  • rename a couple of files / folders
  • Refactor: eg Change Starting to Block and starting to block across ALL files

And building

  • Install npm
  • npm run dev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.