Skip to content
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

Add template funcs countwords and countrunes #1440

Closed
wants to merge 1 commit into from
Closed

Add template funcs countwords and countrunes #1440

wants to merge 1 commit into from

Conversation

digitalcraftsman
Copy link
Member

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

@@ -460,18 +524,25 @@ e.g.
* `{{substr "BatMan" 0 -3}}` → "Bat"
* `{{substr "BatMan" 3 3}}` → "Man"


***
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's all these asterisks?

@digitalcraftsman digitalcraftsman changed the title Add template func countwords Add template funcs countwords and countrunes Sep 20, 2015
@digitalcraftsman
Copy link
Member Author

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
Copy link
Member Author

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

@bep
Copy link
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
Copy link
Member Author

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

@digitalcraftsman
Copy link
Member Author

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

/cc @bep

@spf13
Copy link
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
Copy link
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
Copy link
Contributor

spf13 commented Jan 2, 2016

merged as dfa34af

@spf13 spf13 closed this Jan 2, 2016
@digitalcraftsman digitalcraftsman deleted the tplfunc/countwords branch January 2, 2016 16:03
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants