Skip to content

Commit 942e2bb

Browse files
committed
auto default content insertion when no template option is provided
1 parent 4eda3cf commit 942e2bb

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/compiler/transclude.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ exports.transclude = function (el, options) {
2828
if (_.isTemplate(el)) {
2929
el = templateParser.parse(el)
3030
}
31-
if (options && options.template) {
32-
el = transcludeTemplate(el, options)
31+
if (options) {
32+
if (options._asComponent && !options.template) {
33+
options.template = '<content></content>'
34+
}
35+
if (options.template) {
36+
options._content = _.extractContent(el)
37+
el = transcludeTemplate(el, options)
38+
}
3339
}
3440
if (el instanceof DocumentFragment) {
3541
// anchors for block instance
@@ -56,7 +62,6 @@ function transcludeTemplate (el, options) {
5662
if (!frag) {
5763
_.warn('Invalid template option: ' + template)
5864
} else {
59-
options._content = _.extractContent(el)
6065
var replacer = frag.firstChild
6166
if (options.replace) {
6267
if (
@@ -121,4 +126,4 @@ function mergeAttrs (from, to) {
121126
to.className = to.className + ' ' + value
122127
}
123128
}
124-
}
129+
}

test/unit/specs/compiler/content_spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ describe('Content Transclusion', function () {
3030
expect(el.firstChild.firstChild.textContent).toBe('hi')
3131
})
3232

33+
it('no template auto content', function () {
34+
el.innerHTML = '<p>hi</p>'
35+
options._asComponent = true
36+
mount()
37+
expect(el.firstChild.tagName).toBe('P')
38+
expect(el.firstChild.textContent).toBe('hi')
39+
})
40+
3341
it('fallback content', function () {
3442
options.template = '<content><p>fallback</p></content>'
3543
mount()

0 commit comments

Comments
 (0)