Commit d7b31f9faf920437d6848b4a73381ec7d88dee5a

Authored by Victor Costa
1 parent 3c4173e9

Migrate noosfero template filter to ngforward

src/app/components/noosfero/noosfero-template.filter.js
@@ -1,13 +0,0 @@ @@ -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 @@ @@ -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 return text; 10 return text;
11 - }  
12 - })  
13 -})(); 11 + }
  12 +
  13 +}
src/app/index.ts
@@ -42,7 +42,6 @@ NoosferoApp.run(noosferoAngularRunBlock); @@ -42,7 +42,6 @@ NoosferoApp.run(noosferoAngularRunBlock);
42 NoosferoApp.addController("AuthController", AuthController); 42 NoosferoApp.addController("AuthController", AuthController);
43 43
44 44
45 -require("./components/noosfero/noosfero-template.filter.js");  
46 require("./components/noosfero/noosfero.service.js"); 45 require("./components/noosfero/noosfero.service.js");
47 require("./components/noosfero/profile-image/profile-image.component.js"); 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,7 +10,7 @@ import {LinkListBlock} from "../components/noosfero-blocks/link-list/link-list.c
10 import {RecentDocumentsBlock} from "../components/noosfero-blocks/recent-documents/recent-documents.component"; 10 import {RecentDocumentsBlock} from "../components/noosfero-blocks/recent-documents/recent-documents.component";
11 import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image/profile-image.component"; 11 import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image/profile-image.component";
12 import {MembersBlock} from "../components/noosfero-blocks/members-block/members-block.component"; 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 import {AuthService} from "./../components/auth/auth_service"; 15 import {AuthService} from "./../components/auth/auth_service";
16 import {Session} from "./../components/auth/session"; 16 import {Session} from "./../components/auth/session";
@@ -35,7 +35,8 @@ export class MainContent { @@ -35,7 +35,8 @@ export class MainContent {
35 template: '<div ng-view></div>', 35 template: '<div ng-view></div>',
36 directives: [ 36 directives: [
37 NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock, 37 NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock,
38 - MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock, MembersBlock 38 + MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock,
  39 + MembersBlock, NoosferoTemplate
39 ], 40 ],
40 providers: [AuthService, Session] 41 providers: [AuthService, Session]
41 }) 42 })