diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-09-29 19:38:55 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-09-29 19:38:55 +0200 |
commit | b5c407cf7bdea1a7b0da5044cb036e2753b32de2 (patch) | |
tree | c9bbeb75f43e9b3090c6e8ce7d261e2660b47a80 /packages/gitbook-plugin-hints | |
parent | 9d8dffb6f0aac87c3707a4171140fa66f7e2e82c (diff) | |
download | gitbook-b5c407cf7bdea1a7b0da5044cb036e2753b32de2.zip gitbook-b5c407cf7bdea1a7b0da5044cb036e2753b32de2.tar.gz gitbook-b5c407cf7bdea1a7b0da5044cb036e2753b32de2.tar.bz2 |
Start plugin "hints"
Diffstat (limited to 'packages/gitbook-plugin-hints')
-rw-r--r-- | packages/gitbook-plugin-hints/.gitignore | 31 | ||||
-rw-r--r-- | packages/gitbook-plugin-hints/.npmignore | 2 | ||||
-rw-r--r-- | packages/gitbook-plugin-hints/README.md | 41 | ||||
-rw-r--r-- | packages/gitbook-plugin-hints/index.js | 11 | ||||
-rw-r--r-- | packages/gitbook-plugin-hints/package.json | 29 | ||||
-rw-r--r-- | packages/gitbook-plugin-hints/src/index.js | 40 |
6 files changed, 154 insertions, 0 deletions
diff --git a/packages/gitbook-plugin-hints/.gitignore b/packages/gitbook-plugin-hints/.gitignore new file mode 100644 index 0000000..7c6f0eb --- /dev/null +++ b/packages/gitbook-plugin-hints/.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 diff --git a/packages/gitbook-plugin-hints/.npmignore b/packages/gitbook-plugin-hints/.npmignore new file mode 100644 index 0000000..7bc36b7 --- /dev/null +++ b/packages/gitbook-plugin-hints/.npmignore @@ -0,0 +1,2 @@ +# Publish assets on NPM +!_assets diff --git a/packages/gitbook-plugin-hints/README.md b/packages/gitbook-plugin-hints/README.md new file mode 100644 index 0000000..9952b97 --- /dev/null +++ b/packages/gitbook-plugin-hints/README.md @@ -0,0 +1,41 @@ +Styled hint blocks in your docs +============== + +This plugins requires gitbook `>=4.0.0`. + +### Install + +Add the below to your `book.json` file, then run `gitbook install` : + +```json +{ + "plugins": ["hints"] +} +``` + +### Usage + +You can now provide hints in various ways using the `hint` tag. + +```markdown +{% hint style='info' %} +Important info: this note needs to be highlighted +{% endhint %} +``` + +##### Styles + +Available styles are: + +- `info` (default) +- `tip` +- `danger` +- `warning` + +##### Custom Icons + +```markdown +{% hint style='info' icon="mail" %} +Important info: this note needs to be highlighted +{% endhint %} +``` diff --git a/packages/gitbook-plugin-hints/index.js b/packages/gitbook-plugin-hints/index.js new file mode 100644 index 0000000..55efd25 --- /dev/null +++ b/packages/gitbook-plugin-hints/index.js @@ -0,0 +1,11 @@ + +module.exports = { + blocks: { + hint: ({ kwargs }) => { + return { + style: kwargs.style || 'info', + icon: kwargs.icon + }; + } + } +}; diff --git a/packages/gitbook-plugin-hints/package.json b/packages/gitbook-plugin-hints/package.json new file mode 100644 index 0000000..bd9f65b --- /dev/null +++ b/packages/gitbook-plugin-hints/package.json @@ -0,0 +1,29 @@ +{ + "name": "gitbook-plugin-hints", + "description": "Defines four types of styled hint blocks: info, danger, tip, working.", + "main": "index.js", + "browser": "./_assets/theme.js", + "version": "2.0.0", + "dependencies": { + "classnames": "^2.2.5", + "gitbook-core": "^0.0.0" + }, + "devDependencies": { + "gitbook-plugin": "*" + }, + "engines": { + "gitbook": ">=4.0.0" + }, + "scripts": { + "build-js": "gitbook-plugin build ./src/index.js ./_assets/theme.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-hints/src/index.js b/packages/gitbook-plugin-hints/src/index.js new file mode 100644 index 0000000..0d1c152 --- /dev/null +++ b/packages/gitbook-plugin-hints/src/index.js @@ -0,0 +1,40 @@ +const classNames = require('classnames'); +const GitBook = require('gitbook-core'); +const { React } = GitBook; + +const STYLE_TO_ICON = { + info: 'info', + tip: 'question', + danger: 'exclamation-circle', + warning: 'exclamation-triangle' +}; + +const HintAlert = React.createClass({ + propTypes: { + icon: React.PropTypes.string, + style: React.PropTypes.string, + children: React.PropTypes.node + }, + + render() { + const { children, style, icon } = this.props; + const className = classNames('HintAlert', 'alert', `alert-${style}`); + + return ( + <div className={className}> + <div className="HintAlert/Icon"> + <GitBook.Icon id={icon || STYLE_TO_ICON[style]} /> + </div> + <div className="HintAlert/Content"> + {children} + </div> + </div> + ); + } +}); + +module.exports = GitBook.createPlugin({ + init: (dispatch, getState) => { + dispatch(GitBook.registerComponent(HintAlert, { role: 'block:hint' })); + } +}); |