-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11359 from emberjs/in-template-config
Implements RFC #60 (Component Unification)
- Loading branch information
Showing
10 changed files
with
469 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { render, internal } from 'htmlbars-runtime'; | ||
|
||
export default function attributes(morph, env, scope, template, parentNode, visitor) { | ||
let state = morph.state; | ||
let block = state.block; | ||
|
||
if (!block) { | ||
let element = findRootElement(parentNode); | ||
if (!element) { return; } | ||
|
||
normalizeClassStatement(template.statements, element); | ||
|
||
template.element = element; | ||
block = morph.state.block = internal.blockFor(render, template, { scope }); | ||
} | ||
|
||
block(env, [], undefined, morph, undefined, visitor); | ||
} | ||
|
||
function normalizeClassStatement(statements, element) { | ||
let className = element.getAttribute('class'); | ||
if (!className) { return; } | ||
|
||
for (let i=0, l=statements.length; i<l; i++) { | ||
let statement = statements[i]; | ||
|
||
if (statement[1] === 'class') { | ||
statement[2][2].unshift(className); | ||
} | ||
} | ||
} | ||
|
||
function findRootElement(parentNode) { | ||
let node = parentNode.firstChild; | ||
let found = null; | ||
|
||
while (node) { | ||
if (node.nodeType === 1) { | ||
// found more than one top-level element, so there is no "root element" | ||
if (found) { return null; } | ||
found = node; | ||
} | ||
node = node.nextSibling; | ||
} | ||
|
||
let className = found && found.getAttribute('class'); | ||
if (!className || className.split(' ').indexOf('ember-view') === -1) { | ||
return found; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.