From a083e150a852eff2715957a31941669276e6cd20 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Mon, 29 May 2017 20:54:00 +0000 Subject: [PATCH] Mustache templates with dot notation, as indicated by Norbert (see [1]). User template is separated in subtemplates for better modularity and testability and without any significant performance penalty. --- repository/Brea/BreaMember.class.st | 112 +++++++++++++++++++--------- 1 file changed, 77 insertions(+), 35 deletions(-) diff --git a/repository/Brea/BreaMember.class.st b/repository/Brea/BreaMember.class.st index 0fe58e8..3b3dfc2 100644 --- a/repository/Brea/BreaMember.class.st +++ b/repository/Brea/BreaMember.class.st @@ -28,6 +28,16 @@ BreaMember >> country: anObject [ country := anObject ] +{ #category : #public } +BreaMember >> countryTemplate [ + ^ '{{#country}} + + Country + {{.}} + + {{/country}}' asMustacheTemplate value: self +] + { #category : #helpers } BreaMember >> createTestUser [ ^ self class new @@ -37,8 +47,8 @@ BreaMember >> createTestUser [ memberOf: 'HackBo' withWebsite: 'http://hackbo.co/'; memberOf: 'mutabiT' withWebsite: 'http://mutabit.com/'; website: 'http://test.user'; - email: 'iam@test.user'; twitter: '@offrayLC'; + email: 'iam@test.user'; tags: 'just, a lot, of words, separated, by commas'. ] @@ -62,6 +72,19 @@ BreaMember >> facebook: aProfileName [ self webPresence facebook: aProfileName ] +{ #category : #public } +BreaMember >> facebookTemplate [ + ^ '{{#facebook}} + + + Facebook + + + {{.}} + + {{/facebook}}' asMustacheTemplate value: self +] + { #category : #accessing } BreaMember >> familyName [ ^ familyName @@ -131,7 +154,6 @@ BreaMember >> htmlOutput [ { #category : #public } BreaMember >> htmlOutputTemplate [ "I show the member profile as HTML" - ^ '

{{givenName}} {{familyName}}

@@ -147,34 +169,14 @@ BreaMember >> htmlOutputTemplate [ Name {{givenName}} {{familyName}} - - - Country - {{country}} - - - Organization(s) - HackBo, mutabiT - - - Website - - {{website}} - - - {{#twitter}} - - Twitter - - {{twitter}} - - {{/twitter}} - - - Tags
- {{ tags }} - - + ', + self countryTemplate, + self organizationsTemplate, + self websiteTemplate, + self twitterTemplate, + self facebookTemplate, + self tagsTemplate, + '
@@ -215,6 +217,19 @@ BreaMember >> organizations: anObject [ organizations := anObject ] +{ #category : #public } +BreaMember >> organizationsTemplate [ + ^ ' + + Organization(s) + + {{#organizations}} + {{name}} + {{/organizations}} + + ' asMustacheTemplate value: self +] + { #category : #accessing } BreaMember >> password [ ^ password @@ -250,6 +265,18 @@ BreaMember >> tags: anObject [ tags := anObject ] +{ #category : #public } +BreaMember >> tagsTemplate [ + ^ '{{#tags}} + + + Tags
+ {{.}} + + + {{/tags}}' asMustacheTemplate value: self +] + { #category : #accessing } BreaMember >> twitter [ ^ self webPresence twitter. @@ -262,11 +289,15 @@ BreaMember >> twitter: aProfileName [ { #category : #public } BreaMember >> twitterTemplate [ - ^ ' - Twitter - - {{twitter}} - ' asMustacheTemplate value: self + ^ '{{#twitter}} + + + Twitter + + + {{.}} + + {{/twitter}}' asMustacheTemplate value: self ] { #category : #accessing } @@ -288,3 +319,14 @@ BreaMember >> website [ BreaMember >> website: anUrl [ self webPresence website: anUrl ] + +{ #category : #public } +BreaMember >> websiteTemplate [ + ^ '{{#website}} + + Website + + {{.}} + + {{/website}}' asMustacheTemplate value: self +]