|
| 1 | +// Using the same "brand" as the types for `htmlbars-inline-precompile` for |
| 2 | +// backwards compatibility. The actual value of the brand doesn't matter; it is |
| 3 | +// only important that it (a) is distinct and (b) interoperates with existing |
| 4 | +// uses of the `hbs` export from `htmlbars-inline-precompile` [1]. |
| 5 | +// |
| 6 | +// [1]: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/24a21e0b8ec7eccdec781d7513bfa5947f1c6e20/types/ember/index.d.ts#L540:L542 |
| 7 | +// |
| 8 | +// Note that we *intentionally* do not export this; the details are irrelevant |
| 9 | +// to consumers. The point is simply to have a *distinct* type that is therefore |
| 10 | +// not substitutable for just any other type. |
| 11 | +interface TemplateFactory { |
| 12 | + __htmlbars_inline_precompile_template_factory: any; |
| 13 | +} |
| 14 | + |
| 15 | +export interface PrecompileOptions { |
| 16 | + moduleName?: string; |
| 17 | + parseOptions?: { |
| 18 | + srcName?: string; |
| 19 | + }; |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * A helper for rendering components. |
| 24 | + * |
| 25 | + * @param tagged The template to render. |
| 26 | + * |
| 27 | + * ## Usage |
| 28 | + * |
| 29 | + * ### With tagged template |
| 30 | + * |
| 31 | + * ```ts |
| 32 | + * import { module, test } from 'qunit'; |
| 33 | + * import { setupRenderingTest } from 'ember-qunit'; |
| 34 | + * import { render } from '@ember/test-helpers'; |
| 35 | + * import { hbs } from 'ember-cli-htmlbars'; |
| 36 | + * |
| 37 | + * module('demonstrate hbs usage', function(hooks) { |
| 38 | + * setupRenderingTest(hooks); |
| 39 | + * |
| 40 | + * test('you can render things', function(assert) { |
| 41 | + * await render(hbs`<TestingComponents @isCool={{true}} />`); |
| 42 | + * assert.ok(true); |
| 43 | + * }); |
| 44 | + * }); |
| 45 | + * ``` |
| 46 | + * |
| 47 | + * ## With string and options |
| 48 | + * |
| 49 | + * ```ts |
| 50 | + * import Component from '@glimmer/component'; |
| 51 | + * import { setComponentTemplate } from '@ember/component'; |
| 52 | + * import { hbs } from 'ember-cli-htmlbars'; |
| 53 | + * |
| 54 | + * class Hello extends Component { |
| 55 | + * greeting = 'hello world'; |
| 56 | + * } |
| 57 | + * |
| 58 | + * setComponentTemplate( |
| 59 | + * hbs('<p>{{this.greeting}}</p>', { moduleName: 'hello.hbs' }), |
| 60 | + * MyComponent |
| 61 | + * ); |
| 62 | + * ``` |
| 63 | + */ |
| 64 | +export function hbs(template: string, options?: PrecompileOptions): TemplateFactory; |
| 65 | +export function hbs(tagged: TemplateStringsArray): TemplateFactory; |
0 commit comments