File tree Expand file tree Collapse file tree 8 files changed +268
-14
lines changed Expand file tree Collapse file tree 8 files changed +268
-14
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ function processScript (scriptPart) {
19
19
module . exports = {
20
20
process ( src , path ) {
21
21
var parts = vueCompiler . parseComponent ( src , { pad : true } )
22
- const renderFunctions = compileTemplate ( parts . template . content )
22
+ const renderFunctions = compileTemplate ( parts . template )
23
23
24
24
const result = processScript ( parts . script )
25
25
Original file line number Diff line number Diff line change
1
+ var ensureRequire = require ( '../ensure-require.js' )
2
+
3
+ module . exports = function ( raw ) {
4
+ var html ;
5
+ ensureRequire ( 'pug' , 'pug' )
6
+ var jade = require ( 'pug' )
7
+ try {
8
+ var html = jade . compile ( raw ) ( )
9
+ } catch ( err ) {
10
+ throw Error ( err )
11
+ }
12
+ return html
13
+ }
Original file line number Diff line number Diff line change
1
+ module . exports = function ( name , deps ) {
2
+ var i , len
3
+ var missing = [ ]
4
+ if ( typeof deps === 'string' ) {
5
+ deps = [ deps ]
6
+ }
7
+ for ( i = 0 , len = deps . length ; i < len ; i ++ ) {
8
+ var mis
9
+ var req = deps [ i ]
10
+ if ( typeof req === 'string' ) {
11
+ mis = req
12
+ } else {
13
+ mis = req [ 1 ]
14
+ req = req [ 0 ]
15
+ }
16
+ try {
17
+ // hack for babel-runtime because it does not expose "main" field
18
+ if ( req === 'babel-runtime' ) {
19
+ req = 'babel-runtime/core-js'
20
+ }
21
+ require . resolve ( req )
22
+ } catch ( e ) {
23
+ missing . push ( mis )
24
+ }
25
+ }
26
+ if ( missing . length > 0 ) {
27
+ var message = 'You are trying to use "' + name + '". '
28
+ var npmInstall = 'npm install --save-dev ' + missing . join ( ' ' )
29
+ if ( missing . length > 1 ) {
30
+ var last = missing . pop ( )
31
+ message += missing . join ( ', ' ) + ' and ' + last + ' are '
32
+ } else {
33
+ message += missing [ 0 ] + ' is '
34
+ }
35
+ message += 'missing.\n\nTo install run:\n' + npmInstall
36
+ throw new Error ( message )
37
+ }
38
+ }
Original file line number Diff line number Diff line change 1
1
var chalk = require ( 'chalk' )
2
2
var vueCompiler = require ( 'vue-template-compiler' )
3
3
var transpile = require ( 'vue-template-es2015-compiler' )
4
+ var compilePug = require ( './compilers/pug-compiler' )
4
5
5
- module . exports = function compileTemplate ( template , compiler ) {
6
- var compiled = vueCompiler . compile ( template )
6
+ function getTemplateContent ( templatePart ) {
7
+ if ( templatePart . lang === 'pug' ) {
8
+ return compilePug ( templatePart . content )
9
+ }
10
+ return templatePart . content
11
+ }
12
+
13
+ module . exports = function compileTemplate ( templatePart , compiler ) {
14
+ var templateContent = getTemplateContent ( templatePart )
15
+
16
+ var compiled = vueCompiler . compile ( templateContent )
7
17
if ( compiled . errors . length ) {
8
18
compiled . errors . forEach ( function ( msg ) {
9
19
console . error ( '\n' + chalk . red ( msg ) + '\n' )
Original file line number Diff line number Diff line change 24
24
"eslint-plugin-vue" : " ^2.1.0" ,
25
25
"eslint-plugin-vue-libs" : " ^1.2.0" ,
26
26
"jest" : " ^20.0.4" ,
27
+ "pug" : " ^2.0.0-rc.3" ,
27
28
"vue" : " ^2.4.2" ,
28
29
"vue-template-compiler" : " ^2.4.2" ,
29
- "vue-template-es2015-compiler" : " ^1.5.3"
30
+ "vue-template-es2015-compiler" : " ^1.5.3" ,
31
+ "vue-test-utils" : " git+https://github.com/vuejs/vue-test-utils.git"
30
32
},
31
33
"peerDependencies" : {
32
34
"vue" : " ^2.x" ,
Original file line number Diff line number Diff line change
1
+ import { shallow } from 'vue-test-utils'
2
+ import Pug from './resources/Pug.vue'
3
+
4
+ test ( 'processes .vue file with pug template' , ( ) => {
5
+ const wrapper = shallow ( Pug )
6
+ expect ( wrapper . is ( 'div' ) ) . toBe ( true )
7
+ expect ( wrapper . hasClass ( 'pug' ) ) . toBe ( true )
8
+ } )
Original file line number Diff line number Diff line change
1
+ <template lang="pug">
2
+ .pug
3
+ </template >
4
+
5
+ <script >
6
+ export default {
7
+ name: ' pug'
8
+ };
9
+ </script >
You can’t perform that action at this time.
0 commit comments