mirror of
https://github.com/Luzifer/mondash.git
synced 2024-11-10 00:20:02 +00:00
Extract required filter from pongo2-addons
Current version of pongo2-addons only works with master branch and is not versioned. Also current version of prongo2-addons contains errors related to markdown parser which is not used within mondash. Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
e4d3089e3e
commit
fadd08d920
3 changed files with 33 additions and 4 deletions
4
Gopkg.lock
generated
4
Gopkg.lock
generated
|
@ -9,7 +9,7 @@
|
|||
|
||||
[[projects]]
|
||||
name = "github.com/aws/aws-sdk-go"
|
||||
packages = ["aws","aws/awserr","aws/awsutil","aws/client","aws/client/metadata","aws/credentials","aws/endpoints","aws/request","aws/signer/v4","internal/shareddefaults","private/protocol","private/protocol/query","private/protocol/query/queryutil","private/protocol/rest","private/protocol/restxml","private/protocol/xml/xmlutil","service/s3"]
|
||||
packages = ["aws","aws/awserr","aws/awsutil","aws/client","aws/client/metadata","aws/corehandlers","aws/credentials","aws/credentials/ec2rolecreds","aws/credentials/endpointcreds","aws/credentials/stscreds","aws/defaults","aws/ec2metadata","aws/endpoints","aws/request","aws/session","aws/signer/v4","internal/shareddefaults","private/protocol","private/protocol/query","private/protocol/query/queryutil","private/protocol/rest","private/protocol/restxml","private/protocol/xml/xmlutil","service/s3","service/sts"]
|
||||
revision = "991fe2497a95d757bb53f95cbcebf3d26134c9fe"
|
||||
version = "v1.12.32"
|
||||
|
||||
|
@ -105,6 +105,6 @@
|
|||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "2544efe6d7c15494a53f84f4639759ad68c124eadbd0608faebc66d767db2d3c"
|
||||
inputs-digest = "d6eacc94cd9bd400bffbca99280d82e6e82fad1f84460edb4d4fc0fc78df83f1"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
package filters
|
||||
|
||||
import "github.com/flosch/pongo2"
|
||||
import (
|
||||
"time"
|
||||
|
||||
humanize "github.com/flosch/go-humanize"
|
||||
"github.com/flosch/pongo2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
pongo2.RegisterFilter("lastNItems", filterLastNItems)
|
||||
pongo2.RegisterFilter("naturaltime", filterTimeuntilTimesince)
|
||||
}
|
||||
|
||||
func filterLastNItems(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
||||
|
@ -18,3 +24,27 @@ func filterLastNItems(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *po
|
|||
|
||||
return in.Slice(from, in.Len()), nil
|
||||
}
|
||||
|
||||
func filterTimeuntilTimesince(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
|
||||
basetime, isTime := in.Interface().(time.Time)
|
||||
if !isTime {
|
||||
return nil, &pongo2.Error{
|
||||
Sender: "filter:timeuntil/timesince",
|
||||
ErrorMsg: "time-value is not a time.Time-instance",
|
||||
}
|
||||
}
|
||||
var paramtime time.Time
|
||||
if !param.IsNil() {
|
||||
paramtime, isTime = param.Interface().(time.Time)
|
||||
if !isTime {
|
||||
return nil, &pongo2.Error{
|
||||
Sender: "filter:timeuntil/timesince",
|
||||
ErrorMsg: "time-parameter is not a time.Time-instance",
|
||||
}
|
||||
}
|
||||
} else {
|
||||
paramtime = time.Now()
|
||||
}
|
||||
|
||||
return pongo2.AsValue(humanize.TimeDuration(basetime.Sub(paramtime))), nil
|
||||
}
|
||||
|
|
1
main.go
1
main.go
|
@ -14,7 +14,6 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
|
||||
_ "github.com/Luzifer/mondash/filters"
|
||||
_ "github.com/flosch/pongo2-addons"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
Loading…
Reference in a new issue