test(core): hello world i18n demo (#22654)

PR Close #22654
This commit is contained in:
Olivier Combe 2018-03-21 17:56:01 +01:00 committed by Matias Niemelä
parent 204ba9d413
commit 99711b12f9
3 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package(default_visibility = ["//visibility:public"])
load("//tools:defaults.bzl", "ts_library", "ivy_ng_module")
load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
ivy_ng_module(
name = "hello_world_i18n",
srcs = ["index.ts"],
deps = [
"//packages/core",
],
)
ng_rollup_bundle(
name = "bundle",
# Remove once #22913 lands
entry_point = "packages/core/test/bundling/hello_world_i18n/index.js",
deps = [
":hello_world_i18n",
"//packages/core",
],
)
ts_devserver(
name = "devserver",
static_files = [
":bundle.min_debug.js",
":bundle.min.js",
"index.html",
],
deps = [
# fix for ibazel until https://github.com/angular/angular/pull/22912 gets merged
"//packages/compiler",
],
)

View File

@ -0,0 +1,31 @@
<!doctype html>
<html>
<head>
<title>Angular Hello World Example</title>
</head>
<body>
<!-- The Angular application will be bootstrapped into this element. -->
<hello-world></hello-world>
<!--
Script tag which bootstraps the application. Use `?debug` in URL to select
the debug version of the script.
There are two scripts sources: `bundle.min.js` and `bundle.min_debug.js` You can
switch between which bundle the browser loads to experiment with the application.
- `bundle.min.js`: Is what the site would serve to their users. It has gone
through rollup, build-optimizer, and uglify with tree shaking.
- `bundle.min_debug.js`: Is what the developer would like to see when debugging
the application. It has also done through full pipeline of rollup, build-optimizer,
and uglify, however special flags were passed to uglify to prevent inlining and
property renaming.
-->
<script>
document.write('<script src="' +
(document.location.search.endsWith('debug') ? '/bundle.min_debug.js' : '/bundle.min.js') +
'"></' + 'script>');
</script>
</body>
</html>

View File

@ -0,0 +1,33 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Component, NgModule, ɵrenderComponent as renderComponent} from '@angular/core';
// simulate translations for now
const translations: {[key: string]: string} = {
'Hello World!': 'Bonjour Monde!',
'Hello Title!': 'Bonjour Titre!',
};
// simulate Google Closure getMsg for now
(window as any).goog = {getMsg: (key: string) => { return translations[key] || key; }};
@Component({
selector: 'hello-world',
template: `<div i18n i18n-title title="Hello Title!">Hello World!</div>`
})
export class HelloWorld {
}
// TODO(misko): Forgetting to export HelloWorld and not having NgModule fails silently.
@NgModule({declarations: [HelloWorld]})
export class INeedToExistEvenThoughtIAmNotNeeded {
}
// TODO(misko): Package should not be required to make this work.
renderComponent(HelloWorld);