From 872fe87605af068d85f5322576c600441659bec6 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 24 Mar 2017 21:44:07 +0900 Subject: [PATCH 1/3] pick up from #664 --- docs/ja/configurations/custom-blocks.md | 70 ++++++++++++++++++++++++- docs/ja/start/spec.md | 7 +++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/docs/ja/configurations/custom-blocks.md b/docs/ja/configurations/custom-blocks.md index a9d41d00c..e4caef2c3 100644 --- a/docs/ja/configurations/custom-blocks.md +++ b/docs/ja/configurations/custom-blocks.md @@ -4,9 +4,9 @@ `*.vue` ファイル内にカスタム言語ブロックを定義することが出来ます。カスタムブロックの内容は `vue-loader` のオブジェクトで指定された loader によって処理され、次にコンポーネントモジュールによって要求されます。この設定は `lang` 属性の代わりにタグ名を使用する点をのぞいて[高度な loader の設定](../configurations/advanced.md)に記載されたものと似ています。 -もしカスタムブロックにマッチする loader を見つけたら、それは処理されます。でなければそのカスタムブロックは単に無視されます。 +もしカスタムブロックにマッチする loader を見つけたら、それは処理されます。でなければそのカスタムブロックは単に無視されます。Additionally, if the found loader returns a function, that function will be called with the component of the *.vue file as a parameter. -## 例 +## Single docs file example 全ての `` カスタムブロックを一つのドキュメントファイルに展開する例を示します: @@ -65,3 +65,69 @@ module.exports = { ] } ``` + +## Runtime available docs + +Here's an example of injecting the `` custom blocks into the component so that it's available during runtime. + +#### docs-loader.js + +In order for the custom block content to be injected, we'll need a custom loader: + +``` js +module.exports = function (source, map) { + this.callback(null, 'module.exports = function(Component) {Component.options.__docs = ' + + JSON.stringify(source) + + '}', map) +} +``` + +#### webpack.config.js + +Now we'll configure webpack to use our custom loader for `` custom blocks. + +``` js +const docsLoader = require.resolve('./custom-loaders/docs-loader.js') + +module.exports = { + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue', + options: { + loaders: { + 'docs': docsLoader + } + } + } + ] + } +} +``` + +#### component.vue + +We are now able to access the `` block's content of imported components during runtime. + +``` html + + + +``` diff --git a/docs/ja/start/spec.md b/docs/ja/start/spec.md index cc27296a8..7cc2eda72 100644 --- a/docs/ja/start/spec.md +++ b/docs/ja/start/spec.md @@ -94,6 +94,13 @@ export default {