From f0a6bdd51aaa98a750f8abee6d0d2c6f076eacce Mon Sep 17 00:00:00 2001 From: Ricardo Gobbo de Souza Date: Wed, 7 Feb 2018 09:58:48 -0200 Subject: [PATCH 1/5] feat: add layout on module --- lib/core/module.js | 8 ++++++++ test/fixtures/module/modules/basic/index.js | 3 +++ test/fixtures/module/modules/basic/layout.vue | 6 ++++++ test/fixtures/module/router.js | 6 ++++++ test/fixtures/module/views/layout.vue | 10 ++++++++++ test/module.test.js | 10 ++++++++++ 6 files changed, 43 insertions(+) create mode 100644 test/fixtures/module/modules/basic/layout.vue create mode 100644 test/fixtures/module/views/layout.vue diff --git a/lib/core/module.js b/lib/core/module.js index 7dc6d904bd..c60aa70f31 100755 --- a/lib/core/module.js +++ b/lib/core/module.js @@ -71,6 +71,14 @@ module.exports = class ModuleContainer { }) } + addLayout(template, name) { + const { dst, src } = this.addTemplate(template) + const srcPath = path.parse(src) + + // Add to nuxt layouys + this.options.layouts[name || srcPath.name] = `./${dst}` + } + addServerMiddleware(middleware) { this.options.serverMiddleware.push(middleware) } diff --git a/test/fixtures/module/modules/basic/index.js b/test/fixtures/module/modules/basic/index.js index aab03927b0..99428e1093 100755 --- a/test/fixtures/module/modules/basic/index.js +++ b/test/fixtures/module/modules/basic/index.js @@ -8,6 +8,9 @@ module.exports = function basicModule(options, resolve) { // Add a plugin this.addPlugin(path.resolve(__dirname, 'reverse.js')) + // Add a layout + this.addLayout(path.resolve(__dirname, 'layout.vue')) + // Extend build this.extendBuild((config, { isClient, isServer }) => { // Do nothing! diff --git a/test/fixtures/module/modules/basic/layout.vue b/test/fixtures/module/modules/basic/layout.vue new file mode 100644 index 0000000000..ed699cfa2f --- /dev/null +++ b/test/fixtures/module/modules/basic/layout.vue @@ -0,0 +1,6 @@ + diff --git a/test/fixtures/module/router.js b/test/fixtures/module/router.js index 3899de8cd8..ac5f850f8b 100644 --- a/test/fixtures/module/router.js +++ b/test/fixtures/module/router.js @@ -5,6 +5,7 @@ Vue.use(Router) const indexPage = () => import('~/views/index.vue').then(m => m.default || m) const aboutPage = () => import('~/views/about.vue').then(m => m.default || m) +const layoutPage = () => import('~/views/layout.vue').then(m => m.default || m) export function createRouter() { return new Router({ @@ -19,6 +20,11 @@ export function createRouter() { path: '/about', component: aboutPage, name: 'about' + }, + { + path: '/layout', + component: layoutPage, + name: 'layout' } ] }) diff --git a/test/fixtures/module/views/layout.vue b/test/fixtures/module/views/layout.vue new file mode 100644 index 0000000000..9bf372487d --- /dev/null +++ b/test/fixtures/module/views/layout.vue @@ -0,0 +1,10 @@ + + diff --git a/test/module.test.js b/test/module.test.js index 61f221a304..81addd5e24 100755 --- a/test/module.test.js +++ b/test/module.test.js @@ -47,6 +47,16 @@ test.serial('Plugin', async t => { t.true(html.includes('

TXUN

'), 'plugin works') }) +test.serial('Layout', async t => { + t.true( + nuxt.options.layouts.layout.includes('layout'), + 'layout added to config' + ) + + const { html } = await nuxt.renderRoute('/layout') + t.true(html.includes('

Module Layouts

'), 'layout works') +}) + test.serial('Hooks', async t => { t.is(nuxt.__module_hook, 1) t.is(nuxt.__renderer_hook, 2) From 764fe7b8f10e688f8d44c157b4f09fc7efcb4304 Mon Sep 17 00:00:00 2001 From: Ricardo Gobbo de Souza Date: Wed, 14 Feb 2018 17:31:11 -0200 Subject: [PATCH 4/5] fix: typo --- lib/core/module.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/module.js b/lib/core/module.js index c60aa70f31..aa21eae2e5 100755 --- a/lib/core/module.js +++ b/lib/core/module.js @@ -75,7 +75,7 @@ module.exports = class ModuleContainer { const { dst, src } = this.addTemplate(template) const srcPath = path.parse(src) - // Add to nuxt layouys + // Add to nuxt layouts this.options.layouts[name || srcPath.name] = `./${dst}` } From f7928d0413a7a46a5c7bf3503f6d584e75a0f16e Mon Sep 17 00:00:00 2001 From: Ricardo Gobbo de Souza Date: Wed, 14 Feb 2018 17:32:41 -0200 Subject: [PATCH 5/5] perf: if need parse path --- lib/core/module.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/core/module.js b/lib/core/module.js index aa21eae2e5..e79e3f6db2 100755 --- a/lib/core/module.js +++ b/lib/core/module.js @@ -73,10 +73,9 @@ module.exports = class ModuleContainer { addLayout(template, name) { const { dst, src } = this.addTemplate(template) - const srcPath = path.parse(src) // Add to nuxt layouts - this.options.layouts[name || srcPath.name] = `./${dst}` + this.options.layouts[name || path.parse(src).name] = `./${dst}` } addServerMiddleware(middleware) {