Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gutenberg] Add amp-mathml block #1165

Merged
merged 29 commits into from
May 23, 2018
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dc1bd61
Add skeleton for custom blocks.
miina May 8, 2018
0058e7f
Start adding amp-timeout block.
miina May 9, 2018
1c672a7
Try fixing datetime.
miina May 10, 2018
2dc91cd
Continue implementing amp-timeago.
miina May 10, 2018
2f63cbe
Add cutoff.
miina May 10, 2018
ba90909
Fix timeout save method.
miina May 14, 2018
f81068a
Ignore auto-gen file for JSCS
miina May 14, 2018
99a68cb
Fix conf for React.
miina May 14, 2018
affc5e3
Merge remote-tracking branch 'origin/develop' into add/prenetation_bl…
miina May 14, 2018
75aae8c
Create class for blocks. Fix js issues.
miina May 14, 2018
eb61d46
Add build to JS ignore.
miina May 14, 2018
acfa7bc
Modify ignore files.
miina May 14, 2018
840dc56
Try fixing jshint.
miina May 14, 2018
d4af74c
Revert jshint change.
miina May 14, 2018
026057f
Retry fixing jshint.
miina May 14, 2018
2899fa3
Try fixing missing react plugin.
miina May 14, 2018
abcd21f
Another try for fixing conf.
miina May 14, 2018
286f477
Update dev-lib.
miina May 14, 2018
b600191
Add compiled file to eslint ignore.
miina May 14, 2018
438567b
Try fixing eslint unused var issue.
miina May 15, 2018
8ca47a4
Add width, height, layout to amp-timeago.
miina May 15, 2018
3490255
Rename timeago block.
miina May 16, 2018
8389034
Revert unnecessary changes.
miina May 16, 2018
bfbed6f
Add clock icon for amp-timeago.
miina May 17, 2018
55ed536
Fix issue with height.
miina May 17, 2018
090a4f6
Remove complied JS from repo; compile JS when doing build
westonruter May 20, 2018
329d3f4
Add amp-mathml block.
miina May 22, 2018
4eced7d
Merge develop & resolve conflicts.
miina May 22, 2018
a8b3db8
Remove amp-mathml inline option until inline blocks are supported in …
westonruter May 23, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"presets": [
[
"env",
{
"modules": false
}
]
],
"plugins": [
"transform-object-rest-spread",
[
"transform-react-jsx",
{
"pragma": "wp.element.createElement"
}
]
],
"env": {
"default": {
"plugins": ["transform-runtime"]
},
"production": {}
}
}
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*.min.js
**/node_modules/**
**/vendor/**
**/assets/js/amp-blocks-compiled.js
15 changes: 14 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
{
"root": true,
"extends": [
"wordpress"
"wordpress",
"eslint:recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"react"
],
"env": {
"browser": true
@@ -121,6 +133,7 @@
"react/display-name": "off",
"react/no-children-prop": "off",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"semi": "error",
"semi-spacing": "error",
"space-before-blocks": [
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -4,3 +4,4 @@ build
node_modules
wiki
amp.zip
**/*-compiled.js
4 changes: 4 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*.min.js
**/node_modules/**
**/vendor/**
**/assets/js/amp-blocks-compiled.js
1 change: 0 additions & 1 deletion .jshintrc

This file was deleted.

27 changes: 27 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"es3": true,
"esversion": 6,
"expr": true,
"immed": true,
"noarg": true,
"nonbsp": true,
"onevar": true,
"quotmark": "single",
"trailing": true,
"undef": true,
"unused": true,

"browser": true,

"globals": {
"_": false,
"Backbone": false,
"jQuery": false,
"JSON": false,
"wp": false
}
}
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -100,9 +100,10 @@ module.exports = function( grunt ) {
versionAppend = commitHash + '-' + new Date().toISOString().replace( /\.\d+/, '' ).replace( /-|:/g, '' );

paths = lsOutput.trim().split( /\n/ ).filter( function( file ) {
return ! /^(\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|tests|wp-assets|dev-lib|readme\.md|composer\..*)/.test( file );
return ! /^(blocks|\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|tests|wp-assets|dev-lib|readme\.md|composer\..*)/.test( file );
} );
paths.push( 'vendor/autoload.php' );
paths.push( 'assets/js/*-compiled.js' );
paths.push( 'vendor/composer/**' );
paths.push( 'vendor/sabberworm/php-css-parser/lib/**' );

2 changes: 1 addition & 1 deletion assets/js/amp-block-validation.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

/* exported ampBlockValidation */
/* global wp, _ */
var ampBlockValidation = ( function() {
var ampBlockValidation = ( function() { // eslint-disable-line no-unused-vars
'use strict';

var module = {
2 changes: 1 addition & 1 deletion assets/js/amp-customize-controls.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* exported ampCustomizeControls */
/* eslint no-magic-numbers: [ "error", { "ignore": [ 0, 1, 250] } ] */

var ampCustomizeControls = ( function( api, $ ) {
var ampCustomizeControls = ( function( api, $ ) { // eslint-disable-line no-unused-vars
'use strict';

var component = {
2 changes: 1 addition & 1 deletion assets/js/amp-customize-preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* exported ampCustomizePreview */

var ampCustomizePreview = ( function( api ) {
var ampCustomizePreview = ( function( api ) { // eslint-disable-line no-unused-vars
'use strict';

var component = {};
2 changes: 1 addition & 1 deletion assets/js/amp-post-meta-box.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
*
* @since 0.6
*/
var ampPostMetaBox = ( function( $ ) {
var ampPostMetaBox = ( function( $ ) { // eslint-disable-line no-unused-vars
'use strict';

var component = {
56 changes: 56 additions & 0 deletions blocks/amp-mathml/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

/**
* Internal block libraries.
*/
const { __ } = wp.i18n;
const {
registerBlockType
} = wp.blocks;
const {
PlainText
} = wp.editor;

/**
* Register block.
*/
export default registerBlockType(
'amp/amp-mathml',
{
title: __( 'AMP MathML' ),
category: 'common',
icon: 'welcome-learn-more',
keywords: [
__( 'Mathematical formula' ),
__( 'Scientific content ' )
],

attributes: {
dataFormula: {
type: 'string'
}
},

edit( { attributes, setAttributes } ) {
const { dataFormula } = attributes;

return [
<PlainText
key='formula'
value={ dataFormula }
placeholder={ __( 'Insert formula' ) }
onChange={ ( value ) => setAttributes( { dataFormula: value } ) }
/>
];
},

save( { attributes } ) {
let mathmlProps = {
'data-formula': attributes.dataFormula,
layout: 'container'
};
return (
<amp-mathml { ...mathmlProps }></amp-mathml>
);
}
}
);
4 changes: 4 additions & 0 deletions blocks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Import blocks.
*/
import './amp-mathml';
4 changes: 4 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,10 @@ To install the `pre-commit` hook, do `bash dev-lib/install-pre-commit-hook.sh`.

Note that pull requests will be checked against [WordPress-Coding-Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) with PHPCS, and for JavaScript linting is done with ESLint and (for now) JSCS and JSHint.

## Modifying JavaScript for Blocks

To edit JavaScript code which is built/complied, run `npm run dev` to watch the files which Webpack will build. These complied files are excluded from version control but they are included in the release packages.

## Creating a Plugin Build

To create a build of the plugin for installing in WordPress as a ZIP package, do:
13 changes: 11 additions & 2 deletions includes/admin/class-amp-editor-blocks.php
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ class AMP_Editor_Blocks {
*/
public function init() {
if ( function_exists( 'gutenberg_init' ) ) {
add_action( 'admin_enqueue_scripts', array( $this, 'add_editor_filters' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
add_filter( 'wp_kses_allowed_html', array( $this, 'whitelist_layout_in_wp_kses_allowed_html' ), 10 );
}
}
@@ -39,7 +39,16 @@ public function whitelist_layout_in_wp_kses_allowed_html( $tags ) {
* Enqueue filters for extending core blocks attributes.
* Has to be loaded before registering the blocks in registerCoreBlocks.
*/
public function add_editor_filters() {
public function enqueue_block_editor_assets() {

// Scripts.
wp_enqueue_script(
'amp-editor-blocks-build',
amp_get_asset_url( 'js/amp-blocks-compiled.js' ),
array( 'wp-blocks', 'lodash', 'wp-i18n', 'wp-element', 'wp-components' ),
AMP__VERSION
);

wp_enqueue_script(
'amp-editor-blocks',
amp_get_asset_url( 'js/amp-editor-blocks.js' ),
5,479 changes: 4,933 additions & 546 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -10,17 +10,28 @@
"license": "GPL-2.0+",
"private": true,
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"cross-env": "^5.1.5",
"eslint": "^4.19.1",
"eslint-config-wordpress": "^2.0.0",
"grunt": "^1.0.1",
"eslint-plugin-react": "^7.8.2",
"grunt": "^1.0.2",
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-jshint": "^1.1.0",
"grunt-shell": "^2.1.0",
"grunt-wp-deploy": "^1.2.1"
"grunt-wp-deploy": "^1.2.1",
"webpack": "^3.12.0"
},
"main": "blocks/index.js",
"scripts": {
"build": "grunt build",
"deploy": "grunt deploy"
"build": "cross-env BABEL_ENV=production webpack; grunt build",
"deploy": "grunt deploy",
"dev": "cross-env BABEL_ENV=default webpack --watch"
}
}
25 changes: 25 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* global require, module, __dirname */

const path = require( 'path' );

module.exports = {
entry: {
'./assets/js/amp-blocks-compiled': './blocks/index.js'
},
output: {
path: path.resolve( __dirname ),
filename: '[name].js'
},
devtool: 'cheap-eval-source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader'
}
}
]
}
};