Skip to:
Content

bbPress.org

Ticket #3403: blocks.diff

File blocks.diff, 7.7 KB (added by georgestephanis, 13 months ago)

Very coarse first pass. Only adds the forum index shortcode. More to come.

  • package.json

     
    2727                "grunt-wp-i18n": "~1.0.3",
    2828                "matchdep": "~2.0.0",
    2929                "node-sass": "~4.14.1",
     30                "parcel-bundler": "^1.10.1",
    3031                "postcss-scss": "~1.0.2",
    3132                "stylelint": "~13.6.1",
    3233                "stylelint-config-wordpress": "~15.0.0"
     
    3536                "node": ">=12.0.0",
    3637                "npm": ">=6.9.0"
    3738        },
     39        "scripts": {
     40                "blocks": "parcel build src/includes/admin/assets/js/blocks.jsx --out-dir src/includes/admin/assets/js --public-url ."
     41        },
    3842        "keywords": [
    3943                "community",
    4044                "forums",
  • src/bbpress.php

     
    340340                require $this->includes_dir . 'common/template.php';
    341341                require $this->includes_dir . 'common/widgets.php';
    342342                require $this->includes_dir . 'common/shortcodes.php';
     343                require $this->includes_dir . 'common/blocks.php';
    343344
    344345                // Forums
    345346                require $this->includes_dir . 'forums/capabilities.php';
     
    734735        }
    735736
    736737        /**
    737          * Register the bbPress shortcodes
     738         * Register the bbPress shortcodes and blocks
    738739         *
    739740         * @since 2.0.0 bbPress (r3031)
    740741         */
    741742        public function register_shortcodes() {
    742743                $this->shortcodes = new BBP_Shortcodes();
     744                $this->blocks = new BBP_Blocks( $this->shortcodes );
    743745        }
    744746
    745747        /**
  • src/includes/admin/assets/css/blocks.css

     
     1
     2.bbpress-block {
     3        background: #fff;
     4        border: 1px solid #888;
     5        padding: 1em 2em;
     6}
     7
     8.bbpress-block h3 {
     9        color: #444;
     10        cursor: default;
     11}
  • src/includes/admin/assets/js/blocks.js

    Property changes on: src/includes/admin/assets/css/blocks.css
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"aE2q":[function(require,module,exports) {
     2function e(e){if(null==e)throw new TypeError("Cannot destructure undefined")}var n=wp.blocks.registerBlockType;e(wp.components),n("bbpress/forum-index",{title:"BBPress Forum Index",icon:"buddicons-bbpress-logo",category:"common",attributes:{},edit:function(){return React.createElement("div",{class:"bbpress-block"},React.createElement("h3",null,"BBPress Forum Index"))},save:function(){return null}});
     3},{}]},{},["aE2q"], null)
     4//# sourceMappingURL=blocks.js.map
     5 No newline at end of file
  • src/includes/admin/assets/js/blocks.js.map

    Property changes on: src/includes/admin/assets/js/blocks.js
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1{"version":3,"sources":["blocks.jsx"],"names":["registerBlockType","wp","blocks","components","title","icon","category","attributes","edit","save"],"mappings":";AAQA,SAAA,EAAA,GAAA,GAAA,MAAA,EAAA,MAAA,IAAA,UAAA,gCAPCA,IAAAA,EACGC,GAAGC,OADNF,kBAKGC,EAAAA,GAAGE,YAEPH,EAAmB,sBAAuB,CACzCI,MAAO,sBACPC,KAAM,yBACNC,SAAU,SAEVC,WAAY,GAEZC,KAAM,WAEJ,OAAA,MAAA,cAAA,MAAA,CAAK,MAAM,iBACV,MADD,cAAA,KAAA,KAAA,yBAMFC,KAAM,WACE,OAAA","file":"blocks.js","sourceRoot":"","sourcesContent":["const {\n\tregisterBlockType\n} = wp.blocks;\n\nconst {\n//\tTextControl\n} = wp.components;\n\nregisterBlockType( 'bbpress/forum-index', {\n\ttitle: 'BBPress Forum Index',\n\ticon: 'buddicons-bbpress-logo',\n\tcategory: 'common',\n\n\tattributes: {},\n\n\tedit: function() {\n\t\treturn (\n\t\t\t<div class=\"bbpress-block\">\n\t\t\t\t<h3>BBPress Forum Index</h3>\n\t\t\t</div>\n\t\t);\n\t},\n\n\tsave: function() {\n\t\treturn null;\n\t}\n} );"]}
     2 No newline at end of file
  • src/includes/admin/assets/js/blocks.jsx

     
     1const {
     2        registerBlockType
     3} = wp.blocks;
     4
     5const {
     6//      TextControl
     7} = wp.components;
     8
     9registerBlockType( 'bbpress/forum-index', {
     10        title: 'BBPress Forum Index',
     11        icon: 'buddicons-bbpress-logo',
     12        category: 'common',
     13
     14        attributes: {},
     15
     16        edit: function() {
     17                return (
     18                        <div class="bbpress-block">
     19                                <h3>BBPress Forum Index</h3>
     20                        </div>
     21                );
     22        },
     23
     24        save: function() {
     25                return null;
     26        }
     27} );
     28 No newline at end of file
  • src/includes/common/blocks.php

     
     1<?php
     2
     3/**
     4 * bbPress Blocks
     5 *
     6 * @package bbPress
     7 * @subpackage Blocks
     8 */
     9
     10// Exit if accessed directly
     11defined( 'ABSPATH' ) || exit;
     12
     13if ( ! class_exists( 'BBP_Blocks' ) ) :
     14/**
     15 * bbPress Shortcode Class
     16 *
     17 * @since 2.0.0 bbPress (r3031)
     18 */
     19class BBP_Blocks {
     20
     21        /** Vars ******************************************************************/
     22
     23        /**
     24         * @var BBP_Shortcodes Most of our blocks are just visual representations of existing shortcodes.
     25         */
     26        public $shortcodes;
     27
     28        /** Functions *************************************************************/
     29
     30        /**
     31         * Set up the blocks for the Block Editor.
     32         */
     33        public function __construct( BBP_Shortcodes $shortcodes = NULL ) {
     34                $this->shortcodes = $shortcodes;
     35                $this->register_blocks();
     36        }
     37
     38        public function register_blocks() {
     39                if ( ! function_exists( 'register_block_type' ) ) {
     40                        return;
     41                }
     42
     43                wp_register_script( 'bbp-blocks', plugins_url( '../admin/assets/js/blocks.js', __FILE__ ), [ 'wp-blocks', 'wp-components' ] );
     44                wp_register_style( 'bbp-blocks', plugins_url( '../admin/assets/css/blocks.css', __FILE__ ) );
     45
     46                register_block_type( 'bbpress/forum-index', array(
     47                        'render_callback' => array( $this, 'display_forum_index' ),
     48                        'editor_script'   => 'bbp-blocks',
     49                        'editor_style'    => 'bbp-blocks',
     50                ) );
     51        }
     52
     53        public function display_forum_index() {
     54                $this->shortcodes->display_forum_index();
     55        }
     56
     57}
     58endif;
     59 No newline at end of file