Comments (3)
@diego3g I thought about that
class Content {
private readonly content: string
public params: []
private template: string
get value(): string {
return this.content
}
public compose(paramsentry = {}) {
if (!this.validateParams(paramsentry)) {}
this.template = this.value
for (let key in paramsentry) {
const rgx = new RegExp(`{{ *(${key}) *}}`,'g')
this.template = this.template.replace(rgx, paramsentry[key])
}
return this.template
}
private validateParams (params: []) {
// TODO: validar todos os params passados
return
}
private constructor(content: string) {
this.content = content
this.params = this.extract(content)
}
static validate(content: string): boolean {
if (!content) {
return false
}
return true
}
private extract(content: string) {
return content.match(/{{(.*?)}}/g).map(cnt => cnt.replace('{{', '').replace('}}', '').trim())
}
static create(content: string): Either<InvalidContentError, Content> {
if (!this.validate(content)) {
return false
}
return new Content(content)
}
}
const template = Content.create('{{ message_content }} {{ safe_url }} {{url}}')
template.compose({
message_content: 'Um conteudo bem bacana',
safe_url: 'http://safe.com.br',
url: 'http://url.com.br'
})
output
'Um conteudo bem bacana http://safe.com.br http://url.com.br'
What do you think?
from umbriel.
Yeah, I think it's a good approach, we'll just have to define what are the required variables to check when creating the template.
from umbriel.
if we declare the variable, we can define it required or not.
not required example:
{{ message_not_required? }}
from umbriel.
Related Issues (20)
- Get all senders and templates routes
- Schedule message sending
- Handle bounce events HOT 3
- Add orderings to lists
- Save message editable content as well
- Allow to set account settings
- Update message
- Send a test email before sending to mass
- Message public share URL
- Performance issues HOT 9
- Implement the presentation layer
- Select provider based on configuration
- Dependency Dashboard
- UserRepository is updating in message with User Datas.
- Count subscribers of tag route HOT 1
- List all tags route
- Return tag ID on contact details route
- Message sending progress HOT 1
- Messages stats with distinct users HOT 1
- Case insensitive search
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umbriel.