UNPKG

2.02 kBTypeScriptView Raw
1// Shut off automatically-export-everything-mode. We only want to export the
2// things we explicitly *say* to export.
3export {};
4
5// Allows us to create a branded/opaque type which can *only* be constructed
6// without an unsafe cast by calling `hbs()`.
7declare const Data: unique symbol;
8
9/**
10 The result of calling `hbs()`: an internal type for Ember to use with other
11 framework-level APIs (public and private) like `setComponentTemplate()`.
12
13 This type is *not* user-constructible; it is only legal to get it from `hbs`.
14 */
15declare class TemplateFactory {
16 private [Data]: 'template-factory';
17}
18
19// Only export the type side of the class, so that callers are not misled into
20// thinking that they can instantiate, subclass, etc.
21export type { TemplateFactory };
22
23export interface PrecompileOptions {
24 moduleName?: string;
25 parseOptions?: {
26 srcName?: string;
27 };
28}
29
30/**
31 * A helper for rendering components.
32 *
33 * @param tagged The template to render.
34 *
35 * ## Usage
36 *
37 * ### With tagged template
38 *
39 * ```ts
40 * import { module, test } from 'qunit';
41 * import { setupRenderingTest } from 'ember-qunit';
42 * import { render } from '@ember/test-helpers';
43 * import { hbs } from 'ember-cli-htmlbars';
44 *
45 * module('demonstrate hbs usage', function(hooks) {
46 * setupRenderingTest(hooks);
47 *
48 * test('you can render things', function(assert) {
49 * await render(hbs`<TestingComponents @isCool={{true}} />`);
50 * assert.ok(true);
51 * });
52 * });
53 * ```
54 *
55 * ## With string and options
56 *
57 * ```ts
58 * import Component from '@glimmer/component';
59 * import { setComponentTemplate } from '@ember/component';
60 * import { hbs } from 'ember-cli-htmlbars';
61 *
62 * class Hello extends Component {
63 * greeting = 'hello world';
64 * }
65 *
66 * setComponentTemplate(
67 * hbs('<p>{{this.greeting}}</p>', { moduleName: 'hello.hbs' }),
68 * MyComponent
69 * );
70 * ```
71 */
72export function hbs(template: string, options?: PrecompileOptions): TemplateFactory;
73export function hbs(tagged: TemplateStringsArray): TemplateFactory;