-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Timeago Template Func #1207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timeago Template Func #1207
Conversation
template_functions.go
Outdated
@@ -145,6 +146,35 @@ var ( | |||
}, | |||
"slug": Slug, | |||
"even": func(a int) bool { return (a % 2) == 0 }, | |||
|
|||
// Using https://github.com/xeonx/timeago | |||
"timeago": func(viewArgs map[string]interface{}, datetime time.Time) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible can you modify this so it behaves similar to the i18template function.
Basically allow for variable number of arguments
- If one argument format the time as the default lang in the app.conf
- if two arguments, and second one is string assume that is the region
- if two arguments, and second is map assume that is the viewArgs and extract the CurrentLocaleViewArg from the map
template_functions.go
Outdated
return timeago.English.Format(datetime) | ||
} | ||
// internalization by current locale | ||
var customLanguage = timeago.Config{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Store the customLanguage outside the function in a map keyed by the localeStr, so that a new timeago.Config object doesnt get created every time a this template function is called
@notzippy Please check the changes, I'll wait for your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the one error message change, otherwise nice !
template_functions.go
Outdated
switch len(args) { | ||
case 0: | ||
ERROR.Printf("No arguements passed to template call") | ||
case 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably shoud say no arguements passed to TimeAgo call
Added new template function (Go) called "timeago" using https://github.com/xeonx/timeago
Documentation added to the website.
If the PR is accepted, consider the documentation revel/revel.github.io#133.