Skip to content

Commit 0f73bce

Browse files
committed
improve readability
1 parent 3dde937 commit 0f73bce

File tree

2 files changed

+55
-43
lines changed

2 files changed

+55
-43
lines changed

README.md

+13-43
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,13 @@ The easiest way to install this library in your project is to use the correspond
1313
# vue add extensions
1414
```
1515

16-
#### Manual install
16+
This adds everything you need automatically to your project. Just make sure that `runtimeCompiler: true` is enabled in `vue.config.js` - to use template strings in Vue.
1717

18-
You can do everything manually too, if you want:
19-
```bash
20-
npm install vue-extensions
21-
```
22-
and add the following code:
23-
24-
Create a file, e.g. named `extensions.js`, which exports all of your extensions as default (you can e.g. automate the creation of this file in a script):
25-
```javascript
26-
import FooPlugin from '@/extensions/fooplugin'
27-
import BarPlugin from 'my/path/to/some/extensions/barextension.js'
28-
29-
export default {
30-
FooExtension,
31-
BarExtension
32-
}
33-
```
34-
35-
Now import that file into `main.js` and pass it as "extensions" option to `vue-extensions`:
36-
37-
```javascript
38-
39-
import Extensionpoints from 'vue-extensions'
40-
import AppExtensions from '@/extensions' // you can freely rename that
41-
42-
Vue.add(Extensionpoints, {extensions: AppExtensions})
43-
44-
new Vue({
45-
//...
46-
})
47-
```
48-
49-
Note that you have to enable Vue's runtime compiler if you want to render single file template components as extensions!
50-
51-
```Javascript
52-
// vue.config.js
53-
module.exports = {
54-
runtimeCompiler: true
55-
}
56-
```
18+
If you choose to install everything manually, see [Manual install](manuall-install.md).
5719

5820
## Extensions
5921

60-
Easily said: Extensions are Javascript modules that export a `hooks` object, which is a named index pointing to Vue components:
22+
Extensions are modules that export a default object with a `hooks` property, which is a named index pointing to Vue components. This seems complicated, but an example makes it much clearer:
6123

6224
```javascript
6325
// extensions/FooExtension/index.js
@@ -72,18 +34,26 @@ export default {
7234
}
7335
```
7436

75-
You have an `<extensionpoint>` tag in your project available now:
37+
One module can provide components for more than one hooks.
38+
39+
There is an `<extensionpoint>` tag in your project available now:
7640

7741
```html
7842
<template>
43+
<h3>Extensionpoints for "my-list-element" in a list:</h3>
7944
<ul>
80-
<extensionpoint hook="my-list-element">
45+
<extensionpoint hook="my-list-element"/>
8146
</ul>
47+
48+
<h3>Extensionpoints for "blah-another-hook"</h3>
49+
<extensionpoint hook="blah-another-hook"/>
8250
</template>
8351
```
8452

8553
The *vue-extensions* plugin renders the hooked elements replacing the <extensionpoint> element, one after another. It's up to you what the extensions are rendering: One extension can render a simple `<div>` element with an image, the next extension (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 there are no constraints, you are free to choose.
8654

55+
## Further usage
56+
The extensions.js file (or how you choose to name it) is intended to be created automatically by a script of your choice - If you want to see a project that uses this, see my [GDAPS][https://gdaps.readthedocs.io], which is a Django plugin system that can use Vue as frontend.
8757

8858
## Development
8959

manual-install.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Manual install
2+
3+
You can install vue-extensions manually too, if you want (instead of invoking `vue add extensions`):
4+
5+
```bash
6+
npm install vue-extensions
7+
```
8+
and add the following code:
9+
10+
Create a file, e.g. named `extensions.js`, which exports all of your extensions as default (you can e.g. automate the creation of this file in a script):
11+
```javascript
12+
import FooPlugin from '@/extensions/fooplugin'
13+
import BarPlugin from 'my/path/to/some/extensions/barextension.js'
14+
15+
export default {
16+
FooExtension,
17+
BarExtension
18+
}
19+
```
20+
21+
Now import that file into `main.js` and pass it as "extensions" option to `vue-extensions`:
22+
23+
```javascript
24+
25+
import Extensionpoints from 'vue-extensions'
26+
import AppExtensions from '@/extensions' // you can freely rename that
27+
28+
Vue.add(Extensionpoints, {extensions: AppExtensions})
29+
30+
new Vue({
31+
//...
32+
})
33+
```
34+
35+
Note that you have to enable Vue's runtime compiler if you want to render single file template components as extensions!
36+
37+
```javascript
38+
// vue.config.js
39+
module.exports = {
40+
runtimeCompiler: true
41+
}
42+
```

0 commit comments

Comments
 (0)