mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
Add utils in next instance
This commit is contained in:
parent
ac9412b908
commit
8f29fe6a54
11
lib/nuxt.js
11
lib/nuxt.js
@ -12,8 +12,8 @@ import * as render from './render'
|
|||||||
import generate from './generate'
|
import generate from './generate'
|
||||||
import serveStatic from 'serve-static'
|
import serveStatic from 'serve-static'
|
||||||
import { resolve, join } from 'path'
|
import { resolve, join } from 'path'
|
||||||
import { encodeHtml, setAnsiColors } from './utils'
|
import * as utils from './utils'
|
||||||
setAnsiColors(ansiHTML)
|
utils.setAnsiColors(ansiHTML)
|
||||||
|
|
||||||
class Nuxt {
|
class Nuxt {
|
||||||
|
|
||||||
@ -61,7 +61,10 @@ class Nuxt {
|
|||||||
imports: { serialize }
|
imports: { serialize }
|
||||||
})
|
})
|
||||||
this.errorTemplate = _.template(fs.readFileSync(resolve(__dirname, 'views', 'error.html'), 'utf8'), {
|
this.errorTemplate = _.template(fs.readFileSync(resolve(__dirname, 'views', 'error.html'), 'utf8'), {
|
||||||
imports: { ansiHTML, encodeHtml }
|
imports: {
|
||||||
|
ansiHTML,
|
||||||
|
encodeHtml: utils.encodeHtml
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// renderer used by Vue.js (via createBundleRenderer)
|
// renderer used by Vue.js (via createBundleRenderer)
|
||||||
this.renderer = null
|
this.renderer = null
|
||||||
@ -81,6 +84,8 @@ class Nuxt {
|
|||||||
this.renderAndGetWindow = render.renderAndGetWindow.bind(this)
|
this.renderAndGetWindow = render.renderAndGetWindow.bind(this)
|
||||||
// Add this.generate
|
// Add this.generate
|
||||||
this.generate = generate.bind(this)
|
this.generate = generate.bind(this)
|
||||||
|
// Add this.utils (tests purpose)
|
||||||
|
this.utils = utils
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
export function encodeHtml (str) {
|
export function encodeHtml (str) {
|
||||||
str.replace(/</g, '<').replace(/>/g, '>')
|
return str.replace(/</g, '<').replace(/>/g, '>')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getContext (req, res) {
|
export function getContext (req, res) {
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
const utils = require('../lib/utils')
|
import ansiHTML from 'ansi-html'
|
||||||
const ansiHTML = require('ansi-html')
|
|
||||||
|
let utils
|
||||||
|
// Init nuxt.js and create server listening on localhost:4000
|
||||||
|
test.before('Init Nuxt.js', async t => {
|
||||||
|
const Nuxt = require('../')
|
||||||
|
let nuxt = new Nuxt({ dev: false })
|
||||||
|
utils = nuxt.utils
|
||||||
|
})
|
||||||
|
|
||||||
test('encodeHtml', t => {
|
test('encodeHtml', t => {
|
||||||
const html = '<h1>Hello</h1>'
|
const html = '<h1>Hello</h1>'
|
||||||
|
Loading…
Reference in New Issue
Block a user