-
Notifications
You must be signed in to change notification settings - Fork 8
Exercise 6: strings
Kevin Schuchard edited this page Apr 30, 2019
·
13 revisions
Checkout the strings branch:
npm run clean
git checkout -f stringsIn the src/schematic-starter/schema.json file
- Add a prompt for
browserType
"browserType": {
"enum": ["netscape", "internetExplorer"],
"description": "Supported browser",
"default": "netscape",
"x-prompt": "Select the supported browser"
}In the src/schematic-starter/index.ts file
- Add a
nameguard and throw aSchematicsExceptionif not found.
if (!_options.name) {
throw new SchematicsException('Entity name is required');
}context.logger.debug(`adding files to ${path} dir`);Use the helper method provided to turn the prompt selection into a base64 string;
_options.browserType = getBase64Image(_options.browserType);return apply(url('./files'), [
template({
...strings,
..._options,
}),
move(path),
])(context);In the src/schematic-starter/files/__name@dasherize__.component.html file
- Interpolate the
browserTypevalue.
<img width="300" alt="browser type" src="<%= browserType %>">In the src/schematic-starter/files/__name@dasherize__.component.ts file
- Interpolate the
selector,nameandstyleproperties using thedasherizeclassifymethods where appropriate.
selector: '<%= selector %>',templateUrl: './<%= dasherize(name) %>.component.html',
styleUrls: ['./<%= dasherize(name) %>.component.<%= style %>']export class <%= classify(name) %>Component implements OnInit {npm testYou should have three new files added at sandbox/src/app/components/ with the browserType, selector, name and style properties correctly formatted.
- Try some of the other available string methods in the
.htmlor.tsfiles,
decamelize, dasherize, camelize, classify, underscore, capitalize, levenshtein