Skip to content

Commit 67b8312

Browse files
committed
initial plugin skeleton
1 parent d6de7d0 commit 67b8312

14 files changed

+3530
-0
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/**

.eslintrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": ["eslint:recommended", "aenondynamics", "plugin:react/recommended"],
3+
"plugins": [
4+
"react"
5+
]
6+
}

build.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project name="Enlighter-Gutenberg" default="devcopy" basedir=".">
4+
5+
<!-- ANT-contrib !-->
6+
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
7+
8+
<!-- Plugin Test - DEVELOPMENT ONLY -->
9+
<target name="devcopy">
10+
<!-- Credentials, Host Settings !-->
11+
<loadproperties srcFile=".credentials/account.conf" prefix="dev"/>
12+
13+
<!-- transfer deploy plugin !-->
14+
<echo message="Uploading files [Single Site]"/>
15+
<scp todir="${dev.user}@${dev.host}:${dev.path}" trust="true" port="${dev.port}"
16+
keyfile="${user.home}/${dev.keyfile}">
17+
<fileset dir=".">
18+
<include name="dist/**"/>
19+
<includesfile name="enlighter-gutenberg.php"/>
20+
</fileset>
21+
</scp>
22+
</target>
23+
24+
</project>

dist/enlighterjs.gutenberg.min.js

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*! EnlighterJS Syntax Highlighter Gutenberg Plugin 1.0.0 | Mozilla Public License 2.0 | https://enlighterjs.org */
2+
var EnlighterJS_Gutenberg = (function (exports) {
3+
'use strict';
4+
5+
// wrapper..
6+
7+
// ----------------------------------------------------------------------
8+
9+
// alias
10+
var _TextEditor = wp.editor.PlainText;
11+
12+
// ----------------------------------------------------------------------
13+
14+
// Standard Codeblock
15+
var _codeblock = {
16+
17+
// metadata
18+
title: 'Enlighter Sourcecode',
19+
icon: 'editor-code',
20+
category: 'formatting',
21+
keywords: ['code', 'sourcecode', 'enlighter'],
22+
23+
// internal block state
24+
// @see https://wordpress.org/gutenberg/handbook/block-api/attributes/
25+
attributes: {
26+
// extract sourcecode from saved (html) content
27+
content: {
28+
type: 'string',
29+
selector: 'pre.EnlighterJSRAW',
30+
source: 'text'
31+
}
32+
},
33+
34+
// extended block support features
35+
// @see https://wordpress.org/gutenberg/handbook/block-api/#supports-optional
36+
supports: {
37+
// no custom classes
38+
customClassName: false,
39+
40+
// remove auto generated wrapper classname
41+
className: false,
42+
43+
// disable html edit mode
44+
html: false
45+
},
46+
47+
// allow transform from RAW DOM <pre> node
48+
transforms: {
49+
from: [{
50+
type: 'raw',
51+
isMatch: function isMatch(node) {
52+
return node.nodeName === 'PRE' && node.children.length === 1;
53+
},
54+
schema: {
55+
pre: {
56+
children: {
57+
'#text': {}
58+
}
59+
}
60+
}
61+
}]
62+
},
63+
64+
// The "edit" property must be a valid function.
65+
edit: function blockEdit(_ref) {
66+
var attributes = _ref.attributes,
67+
setAttributes = _ref.setAttributes,
68+
className = _ref.className;
69+
70+
71+
// use standard Gutenberg PlainText View with custom styles
72+
return (
73+
// outer container
74+
wp.element.createElement(
75+
'div',
76+
{ className: className },
77+
wp.element.createElement(_TextEditor, {
78+
value: attributes.content,
79+
onChange: function onChange(content) {
80+
return setAttributes({ content: content });
81+
},
82+
placeholder: 'Insert Sourcecode..',
83+
'aria-label': 'Code'
84+
}),
85+
wp.element.createElement(
86+
'div',
87+
{ className: 'enlighter-footer-label' },
88+
wp.element.createElement(
89+
'small',
90+
null,
91+
'EnlighterJS Syntax Highlighter'
92+
)
93+
)
94+
)
95+
);
96+
},
97+
98+
// render element as html
99+
save: function blockRender(_ref2) {
100+
var attributes = _ref2.attributes;
101+
102+
console.log(attributes);
103+
// add enlighterjs related attributes
104+
return wp.element.createElement(
105+
'pre',
106+
{
107+
'data-enlighter-language': 'generic',
108+
'data-enlighter-theme': 'ddd',
109+
className: 'EnlighterJSRAW'
110+
},
111+
attributes.content
112+
);
113+
}
114+
};
115+
116+
// ----------------------------------------------------------------------
117+
118+
// Register Enlighter Blockcode
119+
wp.blocks.registerBlockType('enlighter/codeblock', _codeblock);
120+
121+
// static properties
122+
var version = '1.0.0';
123+
124+
exports.version = version;
125+
126+
return exports;
127+
128+
}({}));

enlighter-gutenberg.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
Plugin Name: EnlighterJS Gutenberg
4+
Plugin URI: https://enlighterjs.org
5+
Description: DEVELOPMENT PLUGIN - NOT TO BE USED IN PRODUCTION!
6+
Version: 0.1-ALPHA1
7+
Author: Andi Dittrich
8+
Author URI: https://andidittrich.de
9+
License: GPL-2.0
10+
*/
11+
12+
// ----------------------------------------------------------------------
13+
// This Source Code Form is subject to the terms of the Mozilla Public
14+
// License, v. 2.0. If a copy of the MPL was not distributed with this
15+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
16+
// --
17+
// Copyright 2018 Andi Dittrich <https://andidittrich.de>
18+
// ----------------------------------------------------------------------
19+
20+
// Development Plugin - NOT TO BE USED IN PRODUCTION!
21+
22+
23+
define('ENLIGHTER_GUTENBERG_PLUGIN_PATH', dirname(__FILE__));
24+
define('ENLIGHTER_GUTENBERG_PLUGIN_URL', plugins_url('/enlighter-gutenberg/'));
25+
26+
27+
add_action('enqueue_block_editor_assets', function(){
28+
wp_enqueue_script(
29+
'enlighterjs-gutenberg',
30+
ENLIGHTER_GUTENBERG_PLUGIN_URL . 'dist/enlighterjs.gutenberg.min.js',
31+
array('wp-blocks', 'wp-i18n', 'wp-element'),
32+
sha1_file(ENLIGHTER_GUTENBERG_PLUGIN_PATH . '/dist/enlighterjs.gutenberg.min.js')
33+
);
34+
});

gulp

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
./node_modules/gulp/bin/gulp.js "$@"

gulpfile.js

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// ----------------------------------------------------------------------
2+
// This Source Code Form is subject to the terms of the Mozilla Public
3+
// License, v. 2.0. If a copy of the MPL was not distributed with this
4+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
// --
6+
// Copyright 2016-2018 Andi Dittrich <https://andidittrich.de>
7+
// ----------------------------------------------------------------------
8+
9+
10+
// --------------------------------------------------------------------------
11+
// EnlighterJS Syntax Highlighter - https://enlighterjs.org
12+
// --------------------------------------------------------------------------
13+
14+
const _package = require('./package.json');
15+
const _path = require('path');
16+
const _gulp = require('gulp');
17+
const _log = require('fancy-log');
18+
19+
const _gulp_less = require('gulp-less');
20+
const _gulp_replace = require('gulp-replace');
21+
const _prettyError = require('gulp-prettyerror');
22+
const _concat = require('gulp-concat-util');
23+
const _gulp_cleancss = require('gulp-clean-css');
24+
const _wrapper = require('gulp-wrapper');
25+
const _uglify = require('gulp-uglify');
26+
const _rollup = require('rollup');
27+
const _rollup_babel = require('rollup-plugin-babel');
28+
29+
// default task
30+
_gulp.task('default', ['library']);
31+
32+
// license header prepended to builds
33+
const licenseHeader = `/*! EnlighterJS Syntax Highlighter Gutenberg Plugin ${_package.version} | Mozilla Public License 2.0 | https://enlighterjs.org */\n`;
34+
35+
// transpile ES6 and write to tmp file
36+
_gulp.task('es6-transpile', async function(){
37+
const bundle = await _rollup.rollup({
38+
input: './src/EnlighterJS.Gutenberg.js',
39+
plugins: [
40+
_rollup_babel()
41+
]
42+
});
43+
44+
// write the bundle to disk
45+
await bundle.write({
46+
format: 'iife',
47+
name: 'EnlighterJS_Gutenberg',
48+
file: './.tmp/enlighterjs.gutenberg.js'
49+
});
50+
});
51+
52+
// compress
53+
_gulp.task('library', ['es6-transpile'], function(){
54+
55+
// add jquery addon and minify it
56+
return _gulp.src(['.tmp/enlighterjs.gutenberg.js'])
57+
58+
// minify
59+
//.pipe(_uglify())
60+
.pipe(_concat('enlighterjs.gutenberg.min.js'))
61+
62+
// add license header
63+
.pipe(_wrapper({
64+
header: licenseHeader
65+
}))
66+
67+
// add version string
68+
.pipe(_gulp_replace(/\[\[VERSION]]/g, _package.version))
69+
70+
.pipe(_gulp.dest('./dist/'));
71+
});
72+
73+
// generator to transpile less->css
74+
function less2css(themes, outputFilename){
75+
const themesources = themes.map(function(l){
76+
return 'src/themes/' + l + '.less';
77+
});
78+
79+
// base is always required!
80+
return _gulp.src(['src/themes/base.less'].concat(themesources))
81+
.pipe(_prettyError())
82+
83+
.pipe(_gulp_less())
84+
.pipe(_gulp_cleancss())
85+
.pipe(_concat(outputFilename + '.min.css'))
86+
87+
// add license header
88+
.pipe(_wrapper({
89+
header: licenseHeader
90+
}))
91+
92+
.pipe(_gulp.dest('dist'));
93+
}
94+
95+
// LESS to CSS (Base + Themes)- FULL Bundle
96+
_gulp.task('less-themes-full', function (){
97+
return less2css(themelist, 'enlighterjs');
98+
});
99+
100+
// Single Theme export
101+
_gulp.task('less-themes-single', function(){
102+
return themelist.map(name => less2css([name], 'enlighterjs.' + name));
103+
});
104+
105+
_gulp.task('watch', ['library', 'less-themes-full', 'webserver'], function(){
106+
// js, jsx files
107+
_gulp.watch(['src/**/*.js', 'src/**/*.jsx'], ['library']).on('change', function(event) {
108+
_log('File ' + event.path + ' was ' + event.type + ', running tasks...');
109+
});
110+
111+
// less files
112+
_gulp.watch('src/themes/*.less', ['less-themes-full']).on('change', function(event) {
113+
_log('File ' + event.path + ' was ' + event.type + ', running tasks...');
114+
});
115+
});
116+
117+
// development webserver
118+
_gulp.task('webserver', function(){
119+
// start development webserver
120+
const webapp = _express();
121+
webapp.get('/', function(req, res){
122+
res.sendFile(_path.join(__dirname, 'Development.html'));
123+
});
124+
webapp.use(_express.static(_path.join(__dirname, 'dist')));
125+
webapp.listen(8888, () => _log('DEV Webserver Online - localhost:8888'));
126+
});

package.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "enlighterjs-gutenberg",
3+
"description": "an open source syntax highlighter written in pure javascript",
4+
"version": "1.0.0",
5+
"homepage": "https://enlighterjs.org",
6+
"author": {
7+
"name": "Andi Dittrich",
8+
"url": "https://andidittrich.de"
9+
},
10+
"license": "MPL-2.0",
11+
"repository": "EnlighterJS/EnlighterJS.Gutenberg",
12+
"bugs": {
13+
"url": "https://github.com/EnlighterJS/EnlighterJS.Gutenberg/issues"
14+
},
15+
"scripts": {
16+
"test": "eslint src/"
17+
},
18+
"browser": "./dist/enlighterjs.gutenberg.min.js",
19+
"devDependencies": {
20+
"babel-core": "^6.26.3",
21+
"babel-plugin-external-helpers": "^6.22.0",
22+
"babel-plugin-transform-react-jsx": "^6.24.1",
23+
"babel-preset-env": "^1.7.0",
24+
"babel-preset-react": "^6.24.1",
25+
"fancylog": "^3.1.1",
26+
"gulp": "^3.9.1",
27+
"gulp-clean-css": "^3.9.4",
28+
"gulp-concat-util": "^0.5.5",
29+
"gulp-less": "^4.0.1",
30+
"gulp-prettyerror": "^1.2.1",
31+
"gulp-replace": "^1.0.0",
32+
"gulp-uglify": "^3.0.1",
33+
"gulp-wrapper": "^1.0.0",
34+
"rollup": "^0.63.5",
35+
"rollup-plugin-babel": "^3.0.7"
36+
}
37+
}

0 commit comments

Comments
 (0)