Skip to content

Commit

Permalink
Merge pull request #1165 from Automattic/add/amp-mathml_component
Browse files Browse the repository at this point in the history
[Gutenberg] Add amp-mathml block
  • Loading branch information
westonruter committed May 23, 2018
2 parents a68c93f + a8b3db8 commit 2435b18
Show file tree
Hide file tree
Showing 18 changed files with 5,129 additions and 559 deletions.
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
Expand Down Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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/**' );

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

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

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

var component = {
Expand Down
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
Expand Up @@ -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:
Expand Down
13 changes: 11 additions & 2 deletions includes/admin/class-amp-editor-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
Expand All @@ -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' ),
Expand Down
Loading

0 comments on commit 2435b18

Please sign in to comment.