|
1 | 1 | # vue-extensionpoints
|
2 | 2 |
|
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. |
4 | 8 |
|
5 | 9 | ## Install
|
6 | 10 |
|
| 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: |
7 | 19 | ```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 | +} |
9 | 32 | ```
|
10 | 33 |
|
11 |
| -## Usage |
| 34 | +Now import that file in `main.js` and pass it to `vue-extensionpoints`: |
| 35 | + |
12 | 36 | ```javascript
|
13 |
| -// main.js |
14 |
| -import Extensions from 'vue-extensionpoints' |
15 |
| -import foo from '@/plugins/foo' |
16 | 37 |
|
17 |
| -Vue.use(Extensions, {plugins: {foo}}) |
| 38 | +import Extensionpoints from 'vue-extensionpoints' |
| 39 | +import plugins from '@/plugins' |
| 40 | + |
| 41 | +Vue.add(Extensionpoints, plugins) |
18 | 42 |
|
19 | 43 | new Vue({
|
20 |
| - // ... |
| 44 | + //... |
21 | 45 | })
|
22 | 46 | ```
|
23 | 47 |
|
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 |
25 | 49 |
|
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: |
27 | 66 |
|
28 | 67 | ```html
|
29 | 68 | <template>
|
30 | 69 | <ul>
|
31 |
| - <extension hook="my-list-element"> |
| 70 | + <extensionpoint hook="my-list-element"> |
32 | 71 | </ul>
|
33 | 72 | </template>
|
34 | 73 | ```
|
35 | 74 |
|
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 | + |
37 | 77 |
|
38 |
| -```javascript |
39 |
| -import FooListElement from './components/list_element' |
40 |
| -import { FooElement, BazElement } from './components/elements' |
| 78 | +## Development |
41 | 79 |
|
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. |
49 | 81 |
|
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 |
51 | 83 |
|
| 84 | +vue-extensionpoints is licensed under the [MIT](https://opensource.org/licenses/mit-license.php) license |
52 | 85 |
|
53 |
| -#### Compile and minifies library for production |
| 86 | +#### Compile and minifiy library for production |
54 | 87 | ```
|
55 | 88 | npm run build-lib
|
56 | 89 | ```
|
57 | 90 |
|
58 | 91 | #### 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 | + |
59 | 98 | ```
|
60 | 99 | npm run test
|
61 | 100 | ```
|
|
0 commit comments