mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +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 serveStatic from 'serve-static'
|
||||
import { resolve, join } from 'path'
|
||||
import { encodeHtml, setAnsiColors } from './utils'
|
||||
setAnsiColors(ansiHTML)
|
||||
import * as utils from './utils'
|
||||
utils.setAnsiColors(ansiHTML)
|
||||
|
||||
class Nuxt {
|
||||
|
||||
@ -61,7 +61,10 @@ class Nuxt {
|
||||
imports: { serialize }
|
||||
})
|
||||
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)
|
||||
this.renderer = null
|
||||
@ -81,6 +84,8 @@ class Nuxt {
|
||||
this.renderAndGetWindow = render.renderAndGetWindow.bind(this)
|
||||
// Add this.generate
|
||||
this.generate = generate.bind(this)
|
||||
// Add this.utils (tests purpose)
|
||||
this.utils = utils
|
||||
return this
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
export function encodeHtml (str) {
|
||||
str.replace(/</g, '<').replace(/>/g, '>')
|
||||
return str.replace(/</g, '<').replace(/>/g, '>')
|
||||
}
|
||||
|
||||
export function getContext (req, res) {
|
||||
|
@ -1,6 +1,13 @@
|
||||
import test from 'ava'
|
||||
const utils = require('../lib/utils')
|
||||
const ansiHTML = require('ansi-html')
|
||||
import ansiHTML from '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 => {
|
||||
const html = '<h1>Hello</h1>'
|
||||
|
Loading…
Reference in New Issue
Block a user