Commit d7b31f9faf920437d6848b4a73381ec7d88dee5a
1 parent
3c4173e9
Exists in
master
and in
34 other branches
Migrate noosfero template filter to ngforward
Showing
5 changed files
with
33 additions
and
27 deletions
Show diff stats
src/app/components/noosfero/noosfero-template.filter.js
... | ... | @@ -1,13 +0,0 @@ |
1 | -(function() { | |
2 | - 'use strict'; | |
3 | - angular | |
4 | - .module("noosferoApp") | |
5 | - .filter("noosferoTemplate", function() { | |
6 | - return function(text, options) { | |
7 | - for(var option in options) { | |
8 | - text = text.replace('{'+option+'}', options[option]); | |
9 | - } | |
10 | - return text; | |
11 | - } | |
12 | - }) | |
13 | -})(); |
src/app/components/noosfero/noosfero-template.filter.spec.ts
0 → 100644
... | ... | @@ -0,0 +1,19 @@ |
1 | +import {quickCreateComponent} from "../../../spec/helpers"; | |
2 | +import {NoosferoTemplate} from './noosfero-template.filter'; | |
3 | + | |
4 | +describe("Filters", () => { | |
5 | + describe("Noosfero Template Filter", () => { | |
6 | + | |
7 | + beforeEach(angular.mock.module("templates")); | |
8 | + | |
9 | + it("replace the options in text with the values passed on options", done => { | |
10 | + let text = 'profile: {profile}, other: {other}'; | |
11 | + let htmlTemplate = `{{ '${text}' | noosferoTemplate: {profile: 'profile1', other: 'other value'} }}`; | |
12 | + quickCreateComponent({ providers: [NoosferoTemplate], template: htmlTemplate }).then(fixture => { | |
13 | + expect(fixture.debugElement.text()).toEqual("profile: profile1, other: other value"); | |
14 | + done(); | |
15 | + }); | |
16 | + }); | |
17 | + | |
18 | + }); | |
19 | +}); | ... | ... |
src/app/components/noosfero/noosfero-template.filter.ts
1 | -(function() { | |
2 | - 'use strict'; | |
3 | - angular | |
4 | - .module("noosferoApp") | |
5 | - .filter("noosferoTemplate", function() { | |
6 | - return function(text, options) { | |
7 | - for(var option in options) { | |
8 | - text = text.replace('{'+option+'}', options[option]); | |
1 | +import {Pipe} from "ng-forward"; | |
2 | + | |
3 | +@Pipe("noosferoTemplate") | |
4 | +export class NoosferoTemplate { | |
5 | + | |
6 | + transform(text: string, options: any) { | |
7 | + for (var option in options) { | |
8 | + text = text.replace('{' + option + '}', options[option]); | |
9 | 9 | } |
10 | 10 | return text; |
11 | - } | |
12 | - }) | |
13 | -})(); | |
11 | + } | |
12 | + | |
13 | +} | ... | ... |
src/app/index.ts
... | ... | @@ -42,7 +42,6 @@ NoosferoApp.run(noosferoAngularRunBlock); |
42 | 42 | NoosferoApp.addController("AuthController", AuthController); |
43 | 43 | |
44 | 44 | |
45 | -require("./components/noosfero/noosfero-template.filter.js"); | |
46 | 45 | require("./components/noosfero/noosfero.service.js"); |
47 | 46 | require("./components/noosfero/profile-image/profile-image.component.js"); |
48 | 47 | ... | ... |
src/app/main/main.component.ts
... | ... | @@ -10,7 +10,7 @@ import {LinkListBlock} from "../components/noosfero-blocks/link-list/link-list.c |
10 | 10 | import {RecentDocumentsBlock} from "../components/noosfero-blocks/recent-documents/recent-documents.component"; |
11 | 11 | import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image/profile-image.component"; |
12 | 12 | import {MembersBlock} from "../components/noosfero-blocks/members-block/members-block.component"; |
13 | - | |
13 | +import {NoosferoTemplate} from "../components/noosfero/noosfero-template.filter"; | |
14 | 14 | |
15 | 15 | import {AuthService} from "./../components/auth/auth_service"; |
16 | 16 | import {Session} from "./../components/auth/session"; |
... | ... | @@ -35,7 +35,8 @@ export class MainContent { |
35 | 35 | template: '<div ng-view></div>', |
36 | 36 | directives: [ |
37 | 37 | NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock, |
38 | - MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock, MembersBlock | |
38 | + MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock, | |
39 | + MembersBlock, NoosferoTemplate | |
39 | 40 | ], |
40 | 41 | providers: [AuthService, Session] |
41 | 42 | }) | ... | ... |