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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add `after` template function to complement `first` #1200

Closed
wants to merge 5 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@ariejan
Contributor

ariejan commented Jun 10, 2015

The first template function allows the user to select the first X items of an array. I have a use case where I want those X first items, but I also want the rest of the items after X for separate processing. after adds this functionality.

{{ range after 10 .Data.Pages }}
    {{ .Render "title" }}
{{ end }}

There is one open question and that's the one of naming things 馃槇
Is after properly named? I chose it over remaining, as the supplied limit would not make sense. Are there any other candidates that need to be considered? /cc @spf13 what's your opinion on this?

ariejan added some commits Jun 10, 2015

Add `after` template function
Where `first` will return the first N items of a rangeable list,
`after` will return all items after the Nth item.

This allows the user to do something with the first N items and
something different with the remaining items after N.
@@ -177,7 +177,7 @@ func Substr(a interface{}, nums ...interface{}) (string, error) {
}
var start, length int
toInt := func (v interface{}, message string) (int, error) {
toInt := func(v interface{}, message string) (int, error) {

This comment has been minimized.

@ariejan

ariejan Jun 10, 2015

Contributor

Change made by gofmt.

@ariejan

ariejan Jun 10, 2015

Contributor

Change made by gofmt.

"html/template"
"path"
"reflect"
"runtime"
"testing"
"time"
"github.com/stretchr/testify/assert"

This comment has been minimized.

@ariejan

ariejan Jun 10, 2015

Contributor

Change made by gofmt.

@ariejan

ariejan Jun 10, 2015

Contributor

Change made by gofmt.

@ariejan

This comment has been minimized.

Show comment
Hide comment
@ariejan

ariejan Jun 10, 2015

Contributor

@spf13 gofmt also made some minor tweaks to the code that snuck into my commits. Do you want me to pull them out before considering this for merging?

Contributor

ariejan commented Jun 10, 2015

@spf13 gofmt also made some minor tweaks to the code that snuck into my commits. Do you want me to pull them out before considering this for merging?

@spf13

This comment has been minimized.

Show comment
Hide comment
@spf13

spf13 Jun 10, 2015

Contributor

no. It's all good. Go fmt is a good thing.

Contributor

spf13 commented Jun 10, 2015

no. It's all good. Go fmt is a good thing.

@spf13

This comment has been minimized.

Show comment
Hide comment
@spf13

spf13 Jun 10, 2015

Contributor

I feel like we need a last as well following this change.

Contributor

spf13 commented Jun 10, 2015

I feel like we need a last as well following this change.

@ariejan

This comment has been minimized.

Show comment
Hide comment
@ariejan

ariejan Jun 10, 2015

Contributor

@spf13 seems like a good idea, while I'm at it. Give me few moments... 馃暒

Contributor

ariejan commented Jun 10, 2015

@spf13 seems like a good idea, while I'm at it. Give me few moments... 馃暒

ariejan added some commits Jun 10, 2015

Add `last` template function
`last` allows the user to select the last X items of
and array.
@ariejan

This comment has been minimized.

Show comment
Hide comment
@ariejan

ariejan Jun 10, 2015

Contributor

@spf13 pending tests, here's your last :shipit:

Contributor

ariejan commented Jun 10, 2015

@spf13 pending tests, here's your last :shipit:

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Jun 15, 2015

Member

Merged in cc9536e Very useful. And with docs AND tests. Me like.

Member

bep commented Jun 15, 2015

Merged in cc9536e Very useful. And with docs AND tests. Me like.

@bep bep closed this Jun 15, 2015

@wayneashleyberry

This comment has been minimized.

Show comment
Hide comment
@wayneashleyberry

wayneashleyberry commented Nov 23, 2015

鉂わ笍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment