-
-
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.
[FEATURE ember-htmlbars-dashless-helpers] RFC#58.
- Loading branch information
Showing
15 changed files
with
376 additions
and
27 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
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
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
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
26 changes: 26 additions & 0 deletions
26
packages/ember-htmlbars/lib/system/discover-known-helpers.js
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,26 @@ | ||
import isEnabled from "ember-metal/features"; | ||
import dictionary from 'ember-metal/dictionary'; | ||
import keys from 'ember-metal/keys'; | ||
|
||
export default function discoverKnownHelpers(container) { | ||
let registry = container && container._registry; | ||
let helpers = dictionary(null); | ||
|
||
if (isEnabled('ember-htmlbars-dashless-helpers')) { | ||
if (!registry) { | ||
return helpers; | ||
} | ||
|
||
let known = registry.knownForType('helper'); | ||
let knownContainerKeys = keys(known); | ||
|
||
for (let index = 0, length = knownContainerKeys.length; index < length; index++) { | ||
let fullName = knownContainerKeys[index]; | ||
let name = fullName.slice(7); // remove `helper:` from fullName | ||
|
||
helpers[name] = true; | ||
} | ||
} | ||
|
||
return helpers; | ||
} |
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
46 changes: 46 additions & 0 deletions
46
packages/ember-htmlbars/tests/integration/helper-lookup-test.js
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,46 @@ | ||
import isEnabled from "ember-metal/features"; | ||
import Registry from "container/registry"; | ||
import compile from "ember-template-compiler/system/compile"; | ||
import ComponentLookup from 'ember-views/component_lookup'; | ||
import Component from "ember-views/views/component"; | ||
import { helper } from "ember-htmlbars/helper"; | ||
import { runAppend, runDestroy } from "ember-runtime/tests/utils"; | ||
|
||
var registry, container, component; | ||
|
||
QUnit.module('component - invocation', { | ||
setup() { | ||
registry = new Registry(); | ||
container = registry.container(); | ||
registry.optionsForType('component', { singleton: false }); | ||
registry.optionsForType('view', { singleton: false }); | ||
registry.optionsForType('template', { instantiate: false }); | ||
registry.optionsForType('helper', { instantiate: false }); | ||
registry.register('component-lookup:main', ComponentLookup); | ||
}, | ||
|
||
teardown() { | ||
runDestroy(container); | ||
runDestroy(component); | ||
registry = container = component = null; | ||
} | ||
}); | ||
|
||
if (isEnabled('ember-htmlbars-dashless-helpers')) { | ||
QUnit.test('non-dashed helpers are found', function() { | ||
expect(1); | ||
|
||
registry.register('helper:fullname', helper(function( [first, last]) { | ||
return `${first} ${last}`; | ||
})); | ||
|
||
component = Component.extend({ | ||
layout: compile('{{fullname "Robert" "Jackson"}}'), | ||
container: container | ||
}).create(); | ||
|
||
runAppend(component); | ||
|
||
equal(component.$().text(), 'Robert Jackson'); | ||
}); | ||
} |
Oops, something went wrong.