Skip to content

Commit 9694881

Browse files
committed
Initial commit
0 parents  commit 9694881

20 files changed

+718
-0
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
16+
[*.yml]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[*.md]
21+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
**/*.min.js
2+
**/*.build.js
3+
**/node_modules/**
4+
**/vendor/**
5+
build
6+
coverage
7+
cypress
8+
node_modules
9+
vendor

.eslintrc.json

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
{
2+
"root": true,
3+
"parser": "babel-eslint",
4+
"extends": [
5+
"wordpress",
6+
"plugin:react/recommended",
7+
"plugin:jsx-a11y/recommended",
8+
"plugin:jest/recommended"
9+
],
10+
"env": {
11+
"browser": false,
12+
"es6": true,
13+
"node": true,
14+
"mocha": true,
15+
"jest/globals": true
16+
},
17+
"parserOptions": {
18+
"sourceType": "module",
19+
"ecmaFeatures": {
20+
"jsx": true
21+
}
22+
},
23+
"globals": {
24+
"wp": true,
25+
"wpApiSettings": true,
26+
"window": true,
27+
"document": true
28+
},
29+
"plugins": ["react", "jsx-a11y", "jest"],
30+
"settings": {
31+
"react": {
32+
"pragma": "wp"
33+
}
34+
},
35+
"rules": {
36+
"array-bracket-spacing": ["error", "always"],
37+
"brace-style": ["error", "1tbs"],
38+
"camelcase": ["error", { "properties": "never" }],
39+
"comma-dangle": ["error", "always-multiline"],
40+
"comma-spacing": "error",
41+
"comma-style": "error",
42+
"computed-property-spacing": ["error", "always"],
43+
"constructor-super": "error",
44+
"dot-notation": "error",
45+
"eol-last": "error",
46+
"eqeqeq": "error",
47+
"func-call-spacing": "error",
48+
"indent": ["error", "tab", { "SwitchCase": 1 }],
49+
"jsx-a11y/label-has-for": [
50+
"error",
51+
{
52+
"required": "id"
53+
}
54+
],
55+
"jsx-a11y/media-has-caption": "off",
56+
"jsx-a11y/no-noninteractive-tabindex": "off",
57+
"jsx-a11y/role-has-required-aria-props": "off",
58+
"jsx-quotes": "error",
59+
"key-spacing": "error",
60+
"keyword-spacing": "error",
61+
"lines-around-comment": "off",
62+
"no-alert": "error",
63+
"no-bitwise": "error",
64+
"no-caller": "error",
65+
"no-console": "error",
66+
"no-const-assign": "error",
67+
"no-debugger": "error",
68+
"no-dupe-args": "error",
69+
"no-dupe-class-members": "error",
70+
"no-dupe-keys": "error",
71+
"no-duplicate-case": "error",
72+
"no-duplicate-imports": "error",
73+
"no-else-return": "error",
74+
"no-eval": "error",
75+
"no-extra-semi": "error",
76+
"no-fallthrough": "error",
77+
"no-lonely-if": "error",
78+
"no-mixed-operators": "error",
79+
"no-mixed-spaces-and-tabs": "error",
80+
"no-multiple-empty-lines": ["error", { "max": 1 }],
81+
"no-multi-spaces": "error",
82+
"no-multi-str": "off",
83+
"no-negated-in-lhs": "error",
84+
"no-nested-ternary": "error",
85+
"no-redeclare": "error",
86+
"no-restricted-syntax": [
87+
"error",
88+
{
89+
"selector":
90+
"ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]",
91+
"message": "Path access on WordPress dependencies is not allowed."
92+
},
93+
{
94+
"selector": "ImportDeclaration[source.value=/^blocks$/]",
95+
"message": "Use @wordpress/blocks as import path instead."
96+
},
97+
{
98+
"selector": "ImportDeclaration[source.value=/^components$/]",
99+
"message": "Use @wordpress/components as import path instead."
100+
},
101+
{
102+
"selector": "ImportDeclaration[source.value=/^date$/]",
103+
"message": "Use @wordpress/date as import path instead."
104+
},
105+
{
106+
"selector": "ImportDeclaration[source.value=/^editor$/]",
107+
"message": "Use @wordpress/editor as import path instead."
108+
},
109+
{
110+
"selector": "ImportDeclaration[source.value=/^element$/]",
111+
"message": "Use @wordpress/element as import path instead."
112+
},
113+
{
114+
"selector": "ImportDeclaration[source.value=/^i18n$/]",
115+
"message": "Use @wordpress/i18n as import path instead."
116+
},
117+
{
118+
"selector": "ImportDeclaration[source.value=/^data$/]",
119+
"message": "Use @wordpress/data as import path instead."
120+
},
121+
{
122+
"selector": "ImportDeclaration[source.value=/^utils$/]",
123+
"message": "Use @wordpress/utils as import path instead."
124+
},
125+
{
126+
"selector":
127+
"CallExpression[callee.name=/^__|_n|_x$/]:not([arguments.0.type=/^Literal|BinaryExpression$/])",
128+
"message": "Translate function arguments must be string literals."
129+
},
130+
{
131+
"selector":
132+
"CallExpression[callee.name=/^_n|_x$/]:not([arguments.1.type=/^Literal|BinaryExpression$/])",
133+
"message": "Translate function arguments must be string literals."
134+
},
135+
{
136+
"selector":
137+
"CallExpression[callee.name=_nx]:not([arguments.2.type=/^Literal|BinaryExpression$/])",
138+
"message": "Translate function arguments must be string literals."
139+
}
140+
],
141+
"no-shadow": "error",
142+
"no-undef": "error",
143+
"no-undef-init": "error",
144+
"no-unreachable": "error",
145+
"no-unsafe-negation": "error",
146+
"no-unused-expressions": "error",
147+
"no-unused-vars": "error",
148+
"no-useless-computed-key": "error",
149+
"no-useless-constructor": "error",
150+
"no-useless-return": "error",
151+
"no-var": "error",
152+
"no-whitespace-before-property": "error",
153+
"object-curly-spacing": ["error", "always"],
154+
"padded-blocks": ["error", "never"],
155+
"prefer-const": "error",
156+
"quote-props": ["error", "as-needed"],
157+
"react/display-name": "off",
158+
"react/jsx-curly-spacing": [
159+
"error",
160+
{
161+
"when": "always",
162+
"children": true
163+
}
164+
],
165+
"react/jsx-equals-spacing": "error",
166+
"react/jsx-indent": ["error", "tab"],
167+
"react/jsx-indent-props": ["error", "tab"],
168+
"react/jsx-key": "error",
169+
"react/jsx-tag-spacing": "error",
170+
"react/no-children-prop": "off",
171+
"react/no-find-dom-node": "warn",
172+
"react/prop-types": "off",
173+
"semi": "error",
174+
"semi-spacing": "error",
175+
"space-before-blocks": ["error", "always"],
176+
"space-before-function-paren": ["error", "never"],
177+
"space-in-parens": ["error", "always"],
178+
"space-infix-ops": ["error", { "int32Hint": false }],
179+
"space-unary-ops": [
180+
"error",
181+
{
182+
"overrides": {
183+
"!": true
184+
}
185+
}
186+
],
187+
"template-curly-spacing": ["error", "always"],
188+
"valid-jsdoc": ["error", { "requireReturn": false }],
189+
"valid-typeof": "error",
190+
"yoda": "off"
191+
}
192+
}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
3+
## Uncomment line below if you prefer to
4+
## keep compiled files out of version control
5+
# dist/
6+
.DS_Store

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Alternative Homepage Templates

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "getdave-sbe-cgb-guten-block",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"start": "cgb-scripts start",
7+
"build": "cgb-scripts build",
8+
"eject": "cgb-scripts eject"
9+
},
10+
"dependencies": {
11+
"cgb-scripts": "1.15.0"
12+
}
13+
}

plugin.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Plugin Name: Standalone Block Editor Demo
4+
* Plugin URI: https://aheadcreative.co.uk
5+
* Description: a @getdave demo of a standalone Gutenberg Block Editor instance.
6+
* Author: @getdave
7+
* Author URI: https://aheadcreative.co.uk
8+
* Version: 1.0.0
9+
* License: GPL2+
10+
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
11+
*
12+
* @package GSBE
13+
*/
14+
15+
// Exit if accessed directly.
16+
if ( ! defined( 'ABSPATH' ) ) {
17+
exit;
18+
}
19+
20+
/**
21+
* Block Initializer.
22+
*/
23+
require_once plugin_dir_path( __FILE__ ) . 'src/init.php';

src/blocks.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Gutenberg Blocks
3+
*
4+
* All blocks related JavaScript files should be imported here.
5+
* You can create a new block folder in this dir and include code
6+
* for that block here as well.
7+
*
8+
* All blocks should be included here since this is the file that
9+
* Webpack is compiling as the input file.
10+
*/
11+
12+
import './contact-section/block.js';
13+
import './intro-header-section/block.js';
14+
import './services-section/block.js';
15+
16+
import { ContactInfo } from '@automattic/jetpack-blocks';
17+
18+
console.log(ContactInfo);

src/common.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* #.# Common SCSS
3+
*
4+
* Can include things like variables and mixins
5+
* that are used across the project.
6+
*/
7+
8+
// Colors.
9+
$black: rgb(41, 41, 41);
10+
$white: #f4f4f4;
11+
$gray: #dedede;
12+
$green: #bada55;
13+
$red: orangered;

src/common/edit.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { __ } = wp.i18n;
2+
const {
3+
InnerBlocks,
4+
} = wp.editor;
5+
6+
const makeEdit = function(template) {
7+
return function({ attributes, setAttributes }) {
8+
return (
9+
<InnerBlocks
10+
template={template}
11+
/>
12+
);
13+
}
14+
};
15+
16+
export default makeEdit;

src/common/save.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { InnerBlocks } = wp.editor;
2+
3+
const save = function( props ) {
4+
return (
5+
<InnerBlocks.Content />
6+
);
7+
};
8+
9+
export default save;

src/contact-section/block.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* BLOCK: aht
3+
*
4+
* Registering a basic block with Gutenberg.
5+
* Simple block, renders and saves the same content without any interactivity.
6+
*/
7+
8+
// Import CSS.
9+
import './style.scss';
10+
import './editor.scss';
11+
import makeEdit from '../common/edit';
12+
import save from '../common/save';
13+
import BLOCK_TEMPLATE from './template';
14+
15+
const { __ } = wp.i18n; // Import __() from wp.i18n
16+
const { registerBlockType } = wp.blocks; // Import registerBlockType() from wp.blocks
17+
18+
19+
20+
/**
21+
* Register: aa Gutenberg Block.
22+
*
23+
* Registers a new block provided a unique name and an object defining its
24+
* behavior. Once registered, the block is made editor as an option to any
25+
* editor interface where blocks are implemented.
26+
*
27+
* @link https://wordpress.org/gutenberg/handbook/block-api/
28+
* @param {string} name Block name.
29+
* @param {Object} settings Block settings.
30+
* @return {?WPBlock} The block, if it has been successfully
31+
* registered; otherwise `undefined`.
32+
*/
33+
registerBlockType( 'aht-getdave/contact-block-section', {
34+
// Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block.
35+
title: __( 'Contact Us' ), // Block title.
36+
icon: 'phone', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
37+
category: 'sections', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
38+
keywords: [
39+
__( 'contact' ),
40+
__( 'get in touch' ),
41+
],
42+
43+
/**
44+
* The edit function describes the structure of your block in the context of the editor.
45+
* This represents what the editor will render when the block is used.
46+
*
47+
* The "edit" property must be a valid function.
48+
*
49+
* @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/
50+
*/
51+
edit: makeEdit(BLOCK_TEMPLATE),
52+
53+
/**
54+
* The save function defines the way in which the different attributes should be combined
55+
* into the final markup, which is then serialized by Gutenberg into post_content.
56+
*
57+
* The "save" property must be specified and must be a valid function.
58+
*
59+
* @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/
60+
*/
61+
save,
62+
} );

0 commit comments

Comments
 (0)