Skip to content

Commit 53c87ab

Browse files
committed
update docs
1 parent 9898fbc commit 53c87ab

File tree

3 files changed

+69
-26
lines changed

3 files changed

+69
-26
lines changed

README.md

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,100 @@
11
# vue-extensionpoints
22

3-
This library is a Vue.js plugin providing you with an element which acts as extension point. This extension has a named "hook". Plugins then can provide components for this extension point which are automatically found and rendered replacing the extension.
3+
This library is a [Vue.js](https://vuejs.org) plugin providing a custom element which acts as extension point, with a named "hook". Plugins of your application then can provide components for this extension point which are automatically found and rendered replacing the extension.
4+
5+
This is intended wherever you need to have a "list" of different looking components at one place each provided by a plugin.
6+
7+
If you just need a list of the same component, just with different data, don't use `vue-extensionpoints` just use a `v-for` directive.
48

59
## Install
610

11+
The easiest way to install this library in your project is to use the corresponding Vue plugin [extensionpoints](https://github.com/nerdocs/vue-cli-plugin-extensionpoints). It will do all magic for you:
12+
```bash
13+
# vue add extensionpoints
14+
```
15+
16+
#### Manual install
17+
18+
You can do everything manually too, if you want:
719
```bash
8-
# npm install vue-extensionpoints
20+
npm install vue-extensionpoints
21+
```
22+
and add the following code:
23+
24+
Create a file, e.g. named `plugins.js` (or `plugins/index.js`) which exports all of your plugins (you can e.g. automate the creation of this file in a script):
25+
```javascript
26+
import FooPlugin from '@/plugins/fooplugin'
27+
import BarPlugin from 'my/path/to/some/plugins/barplugin.js'
28+
29+
export default {
30+
FooPlugin, BarPlugin
31+
}
932
```
1033

11-
## Usage
34+
Now import that file in `main.js` and pass it to `vue-extensionpoints`:
35+
1236
```javascript
13-
// main.js
14-
import Extensions from 'vue-extensionpoints'
15-
import foo from '@/plugins/foo'
1637

17-
Vue.use(Extensions, {plugins: {foo}})
38+
import Extensionpoints from 'vue-extensionpoints'
39+
import plugins from '@/plugins'
40+
41+
Vue.add(Extensionpoints, plugins)
1842

1943
new Vue({
20-
// ...
44+
//...
2145
})
2246
```
2347

24-
You can import the `options` object from a file that can be created automatially, depending on how you have structured your plugin structures.
48+
## Plugins
2549

26-
You have an `<extension>` tag available now:
50+
Easily said: Plugins are Javascript modules that export a `hooks` object, which is a named index to Vue components:
51+
52+
```javascript
53+
// plugins/FooPlugin/index.js
54+
import AComponent from './components/acomponent.vue'
55+
import {FooElement, BazElement} from './components/othercomponents.vue'
56+
57+
export default {
58+
hooks: {
59+
"my-list-element": [AComponent],
60+
"blah-another-hook": [FooElement, BazElement]
61+
}
62+
}
63+
```
64+
65+
You have an `<extension>` tag in your project available now:
2766

2867
```html
2968
<template>
3069
<ul>
31-
<extension hook="my-list-element">
70+
<extensionpoint hook="my-list-element">
3271
</ul>
3372
</template>
3473
```
3574

36-
Now, in plugins/foo.js:
75+
The *vue-extensionpoints* plugin renders the hooked elements replacing the <extension> element, one after another. It's up to you what the plugin is rendering: One plugin can render a simple `<div>` element with an image, the next plugin (same hook!) can render a complicated component with variables, sub-components etc. The `extensionpoint` renders them one after another. You only have to make sure that your components do what they promise: in the sample case above, `FooListElement` should render a <li> element - because it will be rendered within an <ul> element. But thee are no constraints, you are free to choose.
76+
3777

38-
```javascript
39-
import FooListElement from './components/list_element'
40-
import { FooElement, BazElement } from './components/elements'
78+
## Development
4179

42-
export default {
43-
hooks: {
44-
"my-list-element": FooListElement
45-
"blah-another-hook": [FooElement, BazElement]
46-
}
47-
}
48-
```
80+
You have an idea, improvement, found a bug? Don't hesitate to contact me. PRs and bug fixes are welcome.
4981

50-
vue-extensionpoints finds this file and renders the hooked elements replacing the <extension> element, one after another. You have to make sure that your components do what they promise: in this case, FooListElement should render a <li> element - because it will be rendered within an <ul> element. But thee are no constraints, you are free to choose whatever you want here.
82+
## License
5183

84+
vue-extensionpoints is licensed under the [MIT](https://opensource.org/licenses/mit-license.php) license
5285

53-
#### Compile and minifies library for production
86+
#### Compile and minifiy library for production
5487
```
5588
npm run build-lib
5689
```
5790

5891
#### Run your tests
92+
Currently there are no tests, because of three important causes:
93+
94+
a) I'm lazy
95+
b) tests are not necessary here
96+
c) I'm lazy - did I say that already?
97+
5998
```
6099
npm run test
61100
```

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-extensionpoints",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"license": "MIT",
55
"author": "Christian González <[email protected]>",
66
"scripts": {
@@ -10,6 +10,10 @@
1010
"lint": "vue-cli-service lint",
1111
"prepublish": "npm run lint && npm run build-lib"
1212
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git://github.com/nerdocs/vue-extensionpoints"
16+
},
1317
"main": "./dist/vue-extensionpoints.common.js",
1418
"dependencies": {
1519
"core-js": "^3.4.3",

0 commit comments

Comments
 (0)