From d7b31f9faf920437d6848b4a73381ec7d88dee5a Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 7 Mar 2016 17:05:39 -0300 Subject: [PATCH] Migrate noosfero template filter to ngforward --- src/app/components/noosfero/noosfero-template.filter.js | 13 ------------- src/app/components/noosfero/noosfero-template.filter.spec.ts | 19 +++++++++++++++++++ src/app/components/noosfero/noosfero-template.filter.ts | 22 +++++++++++----------- src/app/index.ts | 1 - src/app/main/main.component.ts | 5 +++-- 5 files changed, 33 insertions(+), 27 deletions(-) delete mode 100644 src/app/components/noosfero/noosfero-template.filter.js create mode 100644 src/app/components/noosfero/noosfero-template.filter.spec.ts diff --git a/src/app/components/noosfero/noosfero-template.filter.js b/src/app/components/noosfero/noosfero-template.filter.js deleted file mode 100644 index 42073b4..0000000 --- a/src/app/components/noosfero/noosfero-template.filter.js +++ /dev/null @@ -1,13 +0,0 @@ -(function() { - 'use strict'; - angular - .module("noosferoApp") - .filter("noosferoTemplate", function() { - return function(text, options) { - for(var option in options) { - text = text.replace('{'+option+'}', options[option]); - } - return text; - } - }) -})(); diff --git a/src/app/components/noosfero/noosfero-template.filter.spec.ts b/src/app/components/noosfero/noosfero-template.filter.spec.ts new file mode 100644 index 0000000..0e7b613 --- /dev/null +++ b/src/app/components/noosfero/noosfero-template.filter.spec.ts @@ -0,0 +1,19 @@ +import {quickCreateComponent} from "../../../spec/helpers"; +import {NoosferoTemplate} from './noosfero-template.filter'; + +describe("Filters", () => { + describe("Noosfero Template Filter", () => { + + beforeEach(angular.mock.module("templates")); + + it("replace the options in text with the values passed on options", done => { + let text = 'profile: {profile}, other: {other}'; + let htmlTemplate = `{{ '${text}' | noosferoTemplate: {profile: 'profile1', other: 'other value'} }}`; + quickCreateComponent({ providers: [NoosferoTemplate], template: htmlTemplate }).then(fixture => { + expect(fixture.debugElement.text()).toEqual("profile: profile1, other: other value"); + done(); + }); + }); + + }); +}); diff --git a/src/app/components/noosfero/noosfero-template.filter.ts b/src/app/components/noosfero/noosfero-template.filter.ts index 42073b4..106b512 100644 --- a/src/app/components/noosfero/noosfero-template.filter.ts +++ b/src/app/components/noosfero/noosfero-template.filter.ts @@ -1,13 +1,13 @@ -(function() { - 'use strict'; - angular - .module("noosferoApp") - .filter("noosferoTemplate", function() { - return function(text, options) { - for(var option in options) { - text = text.replace('{'+option+'}', options[option]); +import {Pipe} from "ng-forward"; + +@Pipe("noosferoTemplate") +export class NoosferoTemplate { + + transform(text: string, options: any) { + for (var option in options) { + text = text.replace('{' + option + '}', options[option]); } return text; - } - }) -})(); + } + +} diff --git a/src/app/index.ts b/src/app/index.ts index 6a75122..953ebcd 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -42,7 +42,6 @@ NoosferoApp.run(noosferoAngularRunBlock); NoosferoApp.addController("AuthController", AuthController); -require("./components/noosfero/noosfero-template.filter.js"); require("./components/noosfero/noosfero.service.js"); require("./components/noosfero/profile-image/profile-image.component.js"); diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 142e078..1ff1272 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -10,7 +10,7 @@ import {LinkListBlock} from "../components/noosfero-blocks/link-list/link-list.c import {RecentDocumentsBlock} from "../components/noosfero-blocks/recent-documents/recent-documents.component"; import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image/profile-image.component"; import {MembersBlock} from "../components/noosfero-blocks/members-block/members-block.component"; - +import {NoosferoTemplate} from "../components/noosfero/noosfero-template.filter"; import {AuthService} from "./../components/auth/auth_service"; import {Session} from "./../components/auth/session"; @@ -35,7 +35,8 @@ export class MainContent { template: '
', directives: [ NoosferoArticleBlog, ArticleView, Boxes, Block, LinkListBlock, - MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock, MembersBlock + MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock, + MembersBlock, NoosferoTemplate ], providers: [AuthService, Session] }) -- libgit2 0.21.2