All Projects → pixelcollective → tiny-blocks

pixelcollective / tiny-blocks

Licence: other
WordPress block editor framework

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to tiny-blocks

visual-portfolio
Portfolio layouts visual editor with Gutenberg support
Stars: ✭ 31 (+0%)
Mutual labels:  gutenberg
gutenberg-i18n-block
Gutenberg block to demo internationalization functionality.
Stars: ✭ 35 (+12.9%)
Mutual labels:  gutenberg
caxton
Gutenberg pro
Stars: ✭ 22 (-29.03%)
Mutual labels:  gutenberg
eightshift-docs
A documentation website for Eightshift open source projects
Stars: ✭ 44 (+41.94%)
Mutual labels:  gutenberg
graphql-gutenblock-example
Example Gutenberg Block using WPGraphQL to populate the data
Stars: ✭ 17 (-45.16%)
Mutual labels:  gutenberg
Gutenberg
The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
Stars: ✭ 7,409 (+23800%)
Mutual labels:  gutenberg
averroes
A Gutenberg compatible markdown editor. Write in Markdown, edit in Markdown and preview in HTML.
Stars: ✭ 15 (-51.61%)
Mutual labels:  gutenberg
acorn-db
Provides Acorn projects with Eloquent Models for WordPress data.
Stars: ✭ 30 (-3.23%)
Mutual labels:  roots
editor-blocks
A unique collection of Gutenberg blocks for the new WordPress editor.
Stars: ✭ 28 (-9.68%)
Mutual labels:  gutenberg
fullsiteediting
fullsiteediting.com/
Stars: ✭ 187 (+503.23%)
Mutual labels:  gutenberg
getwid-style-kit
This boilerplate is designed for WordPress theme developers who are interested in developing themes with the new WordPress 5.x Block Editor - Gutenberg.
Stars: ✭ 33 (+6.45%)
Mutual labels:  gutenberg
ultimate-addons-for-gutenberg
Power-up the Gutenberg editor with advanced and powerful blocks that help you build websites in minutes!
Stars: ✭ 166 (+435.48%)
Mutual labels:  gutenberg
StrapPress
Bootstrap 4 WordPress Starter Theme that is Gutenberg Compatible
Stars: ✭ 55 (+77.42%)
Mutual labels:  gutenberg
block-options
EditorsKit — a toolkit for the Gutenberg block editor.
Stars: ✭ 248 (+700%)
Mutual labels:  gutenberg
ACF-Auto-Blocks
Auto-register ACF field groups as blocks in the new editor (Gutenberg).
Stars: ✭ 28 (-9.68%)
Mutual labels:  gutenberg
qubely
Qubely Blocks – Full-fledged Gutenberg Toolkit
Stars: ✭ 76 (+145.16%)
Mutual labels:  gutenberg
Create Guten Block
📦 A zero-configuration #0CJS developer toolkit for building WordPress Gutenberg block plugins.
Stars: ✭ 3,040 (+9706.45%)
Mutual labels:  gutenberg
Guty-Blocks-2
A minimal, fast development environment for WordPress Gutenberg blocks
Stars: ✭ 52 (+67.74%)
Mutual labels:  gutenberg
Root-Finder
Root-Finder is a header-only univariate polynomial solver, which finds/counts all real roots of any polynomial within any interval.
Stars: ✭ 30 (-3.23%)
Mutual labels:  roots
skeleton-plugin-blocks-gutenberg
No description or website provided.
Stars: ✭ 15 (-51.61%)
Mutual labels:  gutenberg

tiny-pixel/blocks

Provides a backbone for building modular blocks with Blade templating support.

This framework is under active development.

What this is

  • A way to streamline and structure the registration of blocks
  • A way to streamline and structure the registration of block assets
  • A provider of Blade functionality and templating utilities for server-rendered, dynamic blocks.

What this is not

  • A way of writing editor blocks without javascript

Getting started

Use composer to install the package to your project:

composer require tiny-pixel/blocks

Usage

See the demo directory in the repo for an example implementation.

File structure:

demo
├── config
│   └── app.php # Plugin config
├── index.php # Plugin entrypoint
├── resources
│   ├── assets # JS and CSS assets
│   │   # Implementation is up to you
│   │
│   └── views # Place blade templates here
│       └── Demo # Should match block name
│           └── block.blade.php # Entry template
│      
└── src # Block classes
    └── Demo.php # Match name of views & class

Somewhere in your plugin, hook into the tinypixel/blocks/loaded action.

It passes you an instance of the library. Call main to kick everything off. You must pass the path to your config directory to main.

add_action('tinypixel/blocks/loaded', function ($app) {
    $configPath = realpath(__DIR__ . '/config');
    $app->main($configPath);
});

In config/app.php, you only really need to do two things:

  1. Add your blocks to the classes in the blocks key:
   'blocks' => [
      \Foo\Demo::class,
   ],
  1. Change the project.domain key to match the namespace of your blocks. Not the PHP namespace, but the block namespace used in register_block_type.
   'project' => [
        'domain' => 'foo',
        'base_path' => realpath(__DIR__ . '/../'),
        'base_url' => plugins_url('/', __DIR__),
        'dist' => 'dist',
   ],

You can modify the other settings as you see fit. They are largely self explanatory and control where caches are stored, where compiled assets are being stored, etc. One day this might even be documented!

Block definitions

By default, the library will look for block classes in src/.

This classname should match the name of the block without the block namespace. For example, for a foo/demo namespace we will register the class as Demo. The namespace is set in config.project.domain, as mentioned above.

Use the setupAssets method to register your block scripts and styles.

In addition to the ones below you can use $this->addPublicScript and $this->addPublicStyle to register frontend scripts and styles.

<?php

namespace Foo;

use TinyPixel\Blocks\Block;

class Demo extends Block
{
    public function setupAssets(): void
    {
        $this->addEditorStyle(
            $this->makeAsset('editor/css')
                ->setUrl('dist/styles/editor.css')
        );

        $this->addEditorScript(
            $this->makeAsset('editor/js')
                ->setUrl('dist/scripts/editor.js')
        );
    }
}

Last step (other than actually writing the block JS, good luck!) is to implement the template. The default template path is resources/views. The block template should be named block.blade.php. It should be located in a directory named after the block name.

Any block attributes are available in the template as $attr. These attributes are passed to the block as an object.

In addition to the $attr object, you also have access to $content, which is a string of the block content. You also have access to a $id and $className variable, for convenience.

The $id is a unique identifier for the block. You can use it for dynamically applying styles to the block, or calling JS functions.

The $className is the class name of the block. This is based on the block name and follows the following naming convetion: wp-block-{namespace}-{name}.

Author notes

© 2019 Tiny Pixel Collective

Licensed MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].