Skip to content

Commit 872fe87

Browse files
committed
pick up from vuejs#664
1 parent e17f249 commit 872fe87

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

docs/ja/configurations/custom-blocks.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
55
`*.vue` ファイル内にカスタム言語ブロックを定義することが出来ます。カスタムブロックの内容は `vue-loader` のオブジェクトで指定された loader によって処理され、次にコンポーネントモジュールによって要求されます。この設定は `lang` 属性の代わりにタグ名を使用する点をのぞいて[高度な loader の設定](../configurations/advanced.md)に記載されたものと似ています。
66

7-
もしカスタムブロックにマッチする loader を見つけたら、それは処理されます。でなければそのカスタムブロックは単に無視されます。
7+
もしカスタムブロックにマッチする loader を見つけたら、それは処理されます。でなければそのカスタムブロックは単に無視されます。Additionally, if the found loader returns a function, that function will be called with the component of the *.vue file as a parameter.
88

9-
##
9+
## Single docs file example
1010

1111
全ての `<docs>` カスタムブロックを一つのドキュメントファイルに展開する例を示します:
1212

@@ -65,3 +65,69 @@ module.exports = {
6565
]
6666
}
6767
```
68+
69+
## Runtime available docs
70+
71+
Here's an example of injecting the `<docs>` custom blocks into the component so that it's available during runtime.
72+
73+
#### docs-loader.js
74+
75+
In order for the custom block content to be injected, we'll need a custom loader:
76+
77+
``` js
78+
module.exports = function (source, map) {
79+
this.callback(null, 'module.exports = function(Component) {Component.options.__docs = ' +
80+
JSON.stringify(source) +
81+
'}', map)
82+
}
83+
```
84+
85+
#### webpack.config.js
86+
87+
Now we'll configure webpack to use our custom loader for `<docs>` custom blocks.
88+
89+
``` js
90+
const docsLoader = require.resolve('./custom-loaders/docs-loader.js')
91+
92+
module.exports = {
93+
module: {
94+
rules: [
95+
{
96+
test: /\.vue$/,
97+
loader: 'vue',
98+
options: {
99+
loaders: {
100+
'docs': docsLoader
101+
}
102+
}
103+
}
104+
]
105+
}
106+
}
107+
```
108+
109+
#### component.vue
110+
111+
We are now able to access the `<docs>` block's content of imported components during runtime.
112+
113+
``` html
114+
<template>
115+
<div>
116+
<component-b />
117+
<p>{{ docs }}</p>
118+
</div>
119+
</template>
120+
121+
<script>
122+
import componentB from 'componentB';
123+
124+
export default = {
125+
data () {
126+
return {
127+
docs: componentB.__docs
128+
}
129+
},
130+
components: {componentB}
131+
}
132+
</script>
133+
```

docs/ja/start/spec.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ export default {
9494
<style src="todomvc-app-css/index.css">
9595
```
9696
97+
`src` imports also work with custom blocks, e.g.:
98+
99+
``` html
100+
<unit-test src="./unit-test.js">
101+
</unit-test>
102+
```
103+
97104
### シンタックスハイライト
98105
99106
現在それらはシンタクスハイライトをサポートしているのは、[Sublime Text](https://github.com/vuejs/vue-syntax-highlight), [Atom](https://atom.io/packages/language-vue), [Vim](https://github.com/posva/vim-vue), [Visual Studio Code](https://marketplace.visualstudio.com/items/liuji-jim.vue), [Brackets](https://github.com/pandao/brackets-vue), [JetBrains products](https://plugins.jetbrains.com/plugin/8057) (WebStorm, PhpStorm, etc). 他のエディタ/IDEへのコントリビュートは高く評価されます!もし Vue コンポーネント内でプリプロセッサを使用していない場合は、エディタで `*.vue` ファイルを HTML として扱うことが出来ます。

0 commit comments

Comments
 (0)