Add template funcs countwords and countrunes #1440

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
@digitalcraftsman
Member

digitalcraftsman commented Sep 18, 2015

Takes any type, tries to conver it into a string and returns the total number of words.

@bep

View changes

docs/content/templates/functions.md
@@ -460,18 +524,25 @@ e.g.
* `{{substr "BatMan" 0 -3}}` → "Bat"
* `{{substr "BatMan" 3 3}}` → "Man"
+
+***

This comment has been minimized.

@bep

bep Sep 18, 2015

Member

What's all these asterisks?

@bep

bep Sep 18, 2015

Member

What's all these asterisks?

@digitalcraftsman digitalcraftsman changed the title from Add template func countwords to Add template funcs countwords and countrunes Sep 20, 2015

@digitalcraftsman

This comment has been minimized.

Show comment
Hide comment
@digitalcraftsman

digitalcraftsman Sep 20, 2015

Member

I revisited the functions and aspects @bep mentioned in his comments. To support CJK languages I added the countrunes function.

Both countwords and countrunes behave like .WordCount and .RuneCount. In a nutshell, I extracted the code that both page variables use to determine the content length, wrapped them into template functions and tried different text snippets.

Usually all functions have a test case to check if they work properly. Since both template functions use the same code as .WordCount and .RuneCount I looked at their testing functions.

A quick look at them showed that they used sample content defined in constants. I used them to test my template functions manually and compared the result with the exptected values in the existing test functions and got the same results. So, should I add testing functions anyway?

Finally, I removed the asterisks that were initially added as spacers between the functions to get a better overview.

Member

digitalcraftsman commented Sep 20, 2015

I revisited the functions and aspects @bep mentioned in his comments. To support CJK languages I added the countrunes function.

Both countwords and countrunes behave like .WordCount and .RuneCount. In a nutshell, I extracted the code that both page variables use to determine the content length, wrapped them into template functions and tried different text snippets.

Usually all functions have a test case to check if they work properly. Since both template functions use the same code as .WordCount and .RuneCount I looked at their testing functions.

A quick look at them showed that they used sample content defined in constants. I used them to test my template functions manually and compared the result with the exptected values in the existing test functions and got the same results. So, should I add testing functions anyway?

Finally, I removed the asterisks that were initially added as spacers between the functions to get a better overview.

@digitalcraftsman

This comment has been minimized.

Show comment
Hide comment
@digitalcraftsman

digitalcraftsman Oct 7, 2015

Member

Is this PR in a mergable state or is something missing?

Member

digitalcraftsman commented Oct 7, 2015

Is this PR in a mergable state or is something missing?

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Oct 7, 2015

Member

It is mergable -- but I wonder: What is the use case for this? When do you need to count words?

Member

bep commented Oct 7, 2015

It is mergable -- but I wonder: What is the use case for this? When do you need to count words?

@digitalcraftsman

This comment has been minimized.

Show comment
Hide comment
@digitalcraftsman

digitalcraftsman Oct 7, 2015

Member

I thought especially about external ressources that you can fetch with getJSON.

Member

digitalcraftsman commented Oct 7, 2015

I thought especially about external ressources that you can fetch with getJSON.

@digitalcraftsman

This comment has been minimized.

Show comment
Hide comment
@digitalcraftsman

digitalcraftsman Dec 18, 2015

Member

Is there any interest for such template functions or should I close this issue?

/cc @bep

Member

digitalcraftsman commented Dec 18, 2015

Is there any interest for such template functions or should I close this issue?

/cc @bep

@spf13

This comment has been minimized.

Show comment
Hide comment
@spf13

spf13 Jan 1, 2016

Contributor

@digitalcraftsman @bep I'm fine with this code. I'm not sure what the valid use is for it though. If anyone has one, happy to merge. I'd be surprised if someone doesn't have one for it and it doesn't really add any weight to have this functionality.

Contributor

spf13 commented Jan 1, 2016

@digitalcraftsman @bep I'm fine with this code. I'm not sure what the valid use is for it though. If anyone has one, happy to merge. I'd be surprised if someone doesn't have one for it and it doesn't really add any weight to have this functionality.

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Jan 1, 2016

Member

I was going to say documentation, but I notice @digitalcraftsman has supplied perfect docs for this, so yes -- I don't need this, but I'm sure someone will. I'm fine with this.

Member

bep commented Jan 1, 2016

I was going to say documentation, but I notice @digitalcraftsman has supplied perfect docs for this, so yes -- I don't need this, but I'm sure someone will. I'm fine with this.

@spf13

This comment has been minimized.

Show comment
Hide comment
@spf13

spf13 Jan 2, 2016

Contributor

merged as dfa34af

Contributor

spf13 commented Jan 2, 2016

merged as dfa34af

@spf13 spf13 closed this Jan 2, 2016

@digitalcraftsman digitalcraftsman deleted the digitalcraftsman:tplfunc/countwords branch Jan 2, 2016

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