Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 9a28b52

Browse files
HerringtonDarkholmeznck
authored andcommitted
Fix #86, deIndent template code before preprocessing (#90)
* add failing test case for pug * deindent template code before preprocessor this makes pug work consistently * remove redundant re-deindent * remove trim * specify pug's doctype to use boolean attributes' terse style
1 parent 855006b commit 9a28b52

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

Diff for: src/template/pug.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export default async function (template, extras, options) {
22
const pug = require('pug')
3-
const trim = typeof template === 'string' ? template.trim() : template
4-
const compiler = pug.compile(trim, { filename: extras.id, ...options.pug })
3+
const compiler = pug.compile(template, { filename: extras.id, doctype: 'html', ...options.pug })
54

65
return compiler({css: extras.modules || {}})
76
}

Diff for: src/vueTransform.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ async function processTemplate (source, id, content, options, nodes, modules) {
5252
debug(`Process template: ${id}`)
5353

5454
const extras = { modules, id, lang: source.attrs.lang }
55-
const { code } = source
56-
const template = deIndent(
57-
await (options.disableCssModuleStaticReplacement !== true
58-
? templateProcessor(code, extras, options)
59-
: code)
55+
const code = deIndent(source.code)
56+
const template = await (
57+
options.disableCssModuleStaticReplacement !== true
58+
? templateProcessor(code, extras, options)
59+
: code
6060
)
6161

6262
if (!options.compileTemplate) {

Diff for: test/expects/pug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
var pug = { template: "<div class=\"pug__test keep-me\"><article><p>foo</p></article></div>",cssModules: {"test":"pug__test"},};
1+
var pug = { template: "<div class=\"pug__test keep-me\" v-if=\"true\"><article><p>foo</p></article></div><p v-else>nothing</p>",cssModules: {"test":"pug__test"},};
22

33
export default pug;

Diff for: test/fixtures/pug.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<template lang="pug">
22

33

4-
div(class=css.test class='keep-me')
4+
div(class=css.test class='keep-me' v-if="true")
55
article
66
p foo
7+
p(v-else)
8+
| nothing
9+
710

8-
911
</template>
1012

1113
<script lang="babel">

0 commit comments

Comments
 (0)