summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-10-10 12:45:18 +0200
committerSamy Pesse <samypesse@gmail.com>2016-10-10 12:45:18 +0200
commit66231f8b7f5b74efb15e2c6aa34af796e68b58c8 (patch)
tree206ed8cfeb55a270cade81647e19e2092f3d1a0c
parent7037ac55bd444441fcacefa1224a6c36e3ecd7a6 (diff)
downloadgitbook-66231f8b7f5b74efb15e2c6aa34af796e68b58c8.zip
gitbook-66231f8b7f5b74efb15e2c6aa34af796e68b58c8.tar.gz
gitbook-66231f8b7f5b74efb15e2c6aa34af796e68b58c8.tar.bz2
Add plugin "copy-code" to default
-rw-r--r--package.json2
-rw-r--r--packages/gitbook-plugin-copy-code/.gitignore31
-rw-r--r--packages/gitbook-plugin-copy-code/.npmignore2
-rw-r--r--packages/gitbook-plugin-copy-code/_assets/website/button.css27
-rw-r--r--packages/gitbook-plugin-copy-code/index.js10
-rw-r--r--packages/gitbook-plugin-copy-code/package.json29
-rw-r--r--packages/gitbook-plugin-copy-code/src/index.js54
-rw-r--r--packages/gitbook-plugin-headings/package.json70
-rw-r--r--packages/gitbook/package.json1
-rw-r--r--packages/gitbook/src/constants/defaultPlugins.js1
10 files changed, 191 insertions, 36 deletions
diff --git a/package.json b/package.json
index 91fda85..1b8014b 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
"scripts": {
"lint": "eslint .",
"test": "",
- "bootstrap": "lerna bootstrap",
+ "bootstrap": "npm run bump && lerna bootstrap",
"bump": "./scripts/bump.js",
"clean": "lerna clean",
"dist": "lerna run --concurrency 1 prepublish"
diff --git a/packages/gitbook-plugin-copy-code/.gitignore b/packages/gitbook-plugin-copy-code/.gitignore
new file mode 100644
index 0000000..ef47881
--- /dev/null
+++ b/packages/gitbook-plugin-copy-code/.gitignore
@@ -0,0 +1,31 @@
+# Logs
+logs
+*.log
+
+# Runtime data
+pids
+*.pid
+*.seed
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Compiled binary addons (http://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directory
+# Deployed apps should consider commenting this line out:
+# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
+node_modules
+
+# vim swapfile
+*.swp
+
+# Plugin assets
+_assets/plugin.js
diff --git a/packages/gitbook-plugin-copy-code/.npmignore b/packages/gitbook-plugin-copy-code/.npmignore
new file mode 100644
index 0000000..a0e53cf
--- /dev/null
+++ b/packages/gitbook-plugin-copy-code/.npmignore
@@ -0,0 +1,2 @@
+# Publish assets on NPM
+!_assets/plugin.js
diff --git a/packages/gitbook-plugin-copy-code/_assets/website/button.css b/packages/gitbook-plugin-copy-code/_assets/website/button.css
new file mode 100644
index 0000000..2fd034e
--- /dev/null
+++ b/packages/gitbook-plugin-copy-code/_assets/website/button.css
@@ -0,0 +1,27 @@
+.CodeBlockWithCopy-Container {
+ position: relative;
+}
+
+.CodeBlockWithCopy-Button {
+ position: absolute;
+ top: 5px;
+ right: 5px;
+ padding: 3px 6px;
+ margin: 0px;
+ text-transform: uppercase;
+ border-radius: 3px;
+ line-height: 1em;
+ font-size: 12px;
+ border: 1px solid rgba(0,0,0, 0.1);
+ color: rgba(0,0,0, 0.4);
+ cursor: pointer;
+ display: none;
+}
+
+.CodeBlockWithCopy-Container:hover .CodeBlockWithCopy-Button {
+ display: block;
+}
+
+.CodeBlockWithCopy-Button:hover {
+ border-color: rgba(0,0,0, 0.2);
+}
diff --git a/packages/gitbook-plugin-copy-code/index.js b/packages/gitbook-plugin-copy-code/index.js
new file mode 100644
index 0000000..e542ae8
--- /dev/null
+++ b/packages/gitbook-plugin-copy-code/index.js
@@ -0,0 +1,10 @@
+
+module.exports = {
+ blocks: {
+
+ },
+
+ hooks: {
+
+ }
+};
diff --git a/packages/gitbook-plugin-copy-code/package.json b/packages/gitbook-plugin-copy-code/package.json
new file mode 100644
index 0000000..b25ca43
--- /dev/null
+++ b/packages/gitbook-plugin-copy-code/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "gitbook-plugin-copy-code",
+ "description": "Button to copy code blocks",
+ "main": "index.js",
+ "browser": "./_assets/plugin.js",
+ "version": "4.0.0",
+ "dependencies": {
+ "copy-to-clipboard": "^3.0.5",
+ "gitbook-core": "4.0.0"
+ },
+ "devDependencies": {
+ "gitbook-plugin": "4.0.0"
+ },
+ "engines": {
+ "gitbook": ">=3.0.0"
+ },
+ "scripts": {
+ "build-js": "gitbook-plugin build ./src/index.js ./_assets/plugin.js",
+ "prepublish": "npm run build-js"
+ },
+ "homepage": "https://github.com/GitbookIO/gitbook",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/GitbookIO/gitbook.git"
+ },
+ "bugs": {
+ "url": "https://github.com/GitbookIO/gitbook/issues"
+ }
+}
diff --git a/packages/gitbook-plugin-copy-code/src/index.js b/packages/gitbook-plugin-copy-code/src/index.js
new file mode 100644
index 0000000..cfbe1b1
--- /dev/null
+++ b/packages/gitbook-plugin-copy-code/src/index.js
@@ -0,0 +1,54 @@
+const copy = require('copy-to-clipboard');
+const GitBook = require('gitbook-core');
+const { React } = GitBook;
+
+/**
+ * Get children as text
+ * @param {React.Children} children
+ * @return {String}
+ */
+function getChildrenToText(children) {
+ return React.Children.map(children, child => {
+ if (typeof child === 'string') {
+ return child;
+ } else {
+ return child.props.children ?
+ getChildrenToText(child.props.children) : '';
+ }
+ }).join('');
+}
+
+const CodeBlockWithCopy = React.createClass({
+ propTypes: {
+ children: React.PropTypes.node
+ },
+
+ onClick(event) {
+ const { children } = this.props;
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ const text = getChildrenToText(children);
+ copy(text);
+ },
+
+ render() {
+ const { children } = this.props;
+
+ return (
+ <div className="CodeBlockWithCopy-Container">
+ <GitBook.ImportCSS href="gitbook/copy-code/button.css" />
+
+ {children}
+ <span className="CodeBlockWithCopy-Button" onClick={this.onClick}>Copy</span>
+ </div>
+ );
+ }
+});
+
+module.exports = GitBook.createPlugin({
+ activate: (dispatch, getState, { Components }) => {
+ dispatch(Components.registerComponent(CodeBlockWithCopy, { role: 'html:pre' }));
+ }
+});
diff --git a/packages/gitbook-plugin-headings/package.json b/packages/gitbook-plugin-headings/package.json
index 3eb8b76..a733958 100644
--- a/packages/gitbook-plugin-headings/package.json
+++ b/packages/gitbook-plugin-headings/package.json
@@ -1,38 +1,38 @@
{
- "name": "gitbook-plugin-headings",
- "description": "Automatically add anchors to headings",
- "main": "index.js",
- "browser": "./_assets/plugin.js",
- "version": "4.0.0",
- "dependencies": {
+ "name": "gitbook-plugin-headings",
+ "description": "Automatically add anchors to headings",
+ "main": "index.js",
+ "browser": "./_assets/plugin.js",
+ "version": "4.0.0",
+ "dependencies": {
"classnames": "^2.2.5",
- "gitbook-core": "^4.0.0"
- },
- "devDependencies": {
- "gitbook-plugin": "4.0.0"
- },
- "engines": {
- "gitbook": ">=3.0.0"
- },
- "scripts": {
- "build-js": "gitbook-plugin build ./src/index.js ./_assets/plugin.js",
- "prepublish": "npm run build-js"
- },
- "homepage": "https://github.com/GitbookIO/gitbook",
- "repository": {
- "type": "git",
- "url": "https://github.com/GitbookIO/gitbook.git"
- },
- "bugs": {
- "url": "https://github.com/GitbookIO/gitbook/issues"
- },
- "gitbook": {
- "properties": {
- "position": {
- "type": "string",
- "title": "Position of anchors",
- "default": "left"
+ "gitbook-core": "4.0.0"
+ },
+ "devDependencies": {
+ "gitbook-plugin": "4.0.0"
+ },
+ "engines": {
+ "gitbook": ">=3.0.0"
+ },
+ "scripts": {
+ "build-js": "gitbook-plugin build ./src/index.js ./_assets/plugin.js",
+ "prepublish": "npm run build-js"
+ },
+ "homepage": "https://github.com/GitbookIO/gitbook",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/GitbookIO/gitbook.git"
+ },
+ "bugs": {
+ "url": "https://github.com/GitbookIO/gitbook/issues"
+ },
+ "gitbook": {
+ "properties": {
+ "position": {
+ "type": "string",
+ "title": "Position of anchors",
+ "default": "left"
+ }
}
- }
- }
-}
+ }
+} \ No newline at end of file
diff --git a/packages/gitbook/package.json b/packages/gitbook/package.json
index 01fa93e..6cb3f2c 100644
--- a/packages/gitbook/package.json
+++ b/packages/gitbook/package.json
@@ -24,6 +24,7 @@
"gitbook-asciidoc": "1.2.2",
"gitbook-core": "4.0.0",
"gitbook-markdown": "1.3.2",
+ "gitbook-plugin-copy-code": "4.0.0",
"gitbook-plugin-headings": "4.0.0",
"gitbook-plugin-highlight": "4.0.0",
"gitbook-plugin-livereload": "0.0.1",
diff --git a/packages/gitbook/src/constants/defaultPlugins.js b/packages/gitbook/src/constants/defaultPlugins.js
index f9ddb25..326ad3a 100644
--- a/packages/gitbook/src/constants/defaultPlugins.js
+++ b/packages/gitbook/src/constants/defaultPlugins.js
@@ -26,5 +26,6 @@ module.exports = Immutable.List([
'sharing',
'hints',
'headings',
+ 'copy-code',
'theme-default'
]).map(createFromDependency);