Skip to content

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

Merged
merged 2 commits into from
Aug 3, 2017
Merged

Timeago Template Func #1207

merged 2 commits into from
Aug 3, 2017

Conversation

wariosolis
Copy link
Contributor

@wariosolis wariosolis commented Jul 22, 2017

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.

@@ -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 {
Copy link
Collaborator

@notzippy notzippy Jul 22, 2017

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

return timeago.English.Format(datetime)
}
// internalization by current locale
var customLanguage = timeago.Config{
Copy link
Collaborator

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

@wariosolis
Copy link
Contributor Author

@notzippy Please check the changes, I'll wait for your comments.

Copy link
Collaborator

@notzippy notzippy left a 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 !

switch len(args) {
case 0:
ERROR.Printf("No arguements passed to template call")
case 1:
Copy link
Collaborator

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

@notzippy notzippy added this to the v0.18 milestone Jul 23, 2017
@notzippy notzippy added waffle: needs review type-enhancement New enhancement of existing feature and removed waffle: ready labels Jul 26, 2017
@notzippy notzippy merged commit e954823 into revel:develop Aug 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement New enhancement of existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants