Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat (ng-pluralize): add alternative mapping using attributes #2454

Closed
wants to merge 1 commit into from

Conversation

lgalfaso
Copy link
Contributor

When using ngPluralize, I found myself having to escape the characters " and '.
This PR adds an alternative way to define the mapping using attributes to the element like this

<ng:pluralize count='viewCount' offset='1'
    _0='Nobody is viewing.'
    _1='{{p1}} is viewing.'
    one='{{p1}} and one other person are viewing.'
    other='{{p1}} and {} other people are viewing.'>
</ng:pluralize>

@IgorMinar
Copy link
Contributor

I'm not keen on this syntax as it requires the _NUM hack. Could we use the body of the element or prefix all attributes with "when-" instead?

@petebacondarwin
Copy link
Member

+1 for when-X="..."

I am also rather drawn to the idea of using inner elements, which would allow us to have HTML and directives inside the templates. But working with transclusion in this way is rather problematic right now so probably for the future.

<ng-pluralize count="viewers.count' offset='1' ng-init="viewers="['a', 'b', 'c']">
  <ng-pluralize-template when="0">Nobody is viewing</ng-pluralize-template>
  <ng-pluralize-template when="1">
    <a ng-click="showViewer(0)">{{viewers[0]}}</a> is viewing
  </ng-pluralize-template>
  <ng-pluralize-template when="one">
    <a ng-click="showViewer(0)">{{viewers[0]}}</a> and
    <a ng-click="showViewer(0)">{{viewers[1]}}</a> are viewing
  </ng-pluralize-template>
  <ng-pluralize-template when="other">
    <div>{{viewers[0] and {{$offsetCount}} are viewing</div>
    <div>{{$count}} are viewing</div>
  </ng-pluralize-template>
</ng-pluralize>

@lgalfaso
Copy link
Contributor Author

lgalfaso commented May 5, 2013

I like the idea of a when-X attribute, will look into making the changes so it works this way. Agree that with the current state of transclusion, having the second proposal from @petebacondarwin can be an issue

@petebacondarwin
Copy link
Member

@lgalfaso - Great! How are you getting on making the change to when- style attributes?

@lgalfaso
Copy link
Contributor Author

lgalfaso commented May 8, 2013

@petebacondarwin The change is simple, I am just trying to figure out how to handle negative numbers in a visually appealing way. Does when--2 looks ok for -2?

@petebacondarwin
Copy link
Member

when-minus-2?

Pete
...from my mobile.
On May 8, 2013 4:03 PM, "Lucas Galfasó" notifications@github.com wrote:

@petebacondarwin https://github.com/petebacondarwin The change is
simple, I am just trying to figure out how to handle negative numbers in a
visually appealing way. Does when--2 looks ok for -2?


Reply to this email directly or view it on GitHubhttps://github.com//pull/2454#issuecomment-17611604
.

@lgalfaso
Copy link
Contributor Author

lgalfaso commented May 8, 2013

@petebacondarwin Looks like a good alternative. Just push a new patch

@@ -25,27 +25,40 @@
* and explicit number rules throughout later parts of this documentation.
*
* # Configuring ngPluralize
* You configure ngPluralize by providing 2 attributes: `count` and `when`.
* You configure ngPluralize by providing the attribute `count` any of the two ways to
Copy link
Member

Choose a reason for hiding this comment

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

This line is a bit unclear. Perhaps it could be something like this

You configure ngPluralize by providing attributes, count, when and offset to describe what should be counted and how to map that count to templates for display.

And then enumerate the attributes and how they work below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks changed

@petebacondarwin
Copy link
Member

Also, what happens if someone tries to use both strategies? It seems that at the moment both configurations are used with the when-X attributes overriding what is in the when="{}" object. Is this what you expect and if so we ought to make it explicit in the text and the documentation.

@lgalfaso
Copy link
Contributor Author

lgalfaso commented Jul 2, 2013

@petebacondarwin Added the following comment to clarify what happens when the two mapping mechanisms are used

It is possible to mix the two forms to define a mapping. In this case, if there is a conflict the definition used using when will take precedence.

@lgalfaso
Copy link
Contributor Author

lgalfaso commented Jul 2, 2013

@petebacondarwin Thanks for looking into this, and let me know if you would like me to rebase this into a single commit

'<ng-pluralize count="email" ' +
"when-minus-1='You have negative email. Whohoo!' " +
"when-0='You have no new email' " +
"one='You have one new email' " +
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be when-one and when-other below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is to accept the unicode plural categories as-is, without the when- prefix. Can change this to be when- prefixed if you think it would make more sense

Copy link
Member

Choose a reason for hiding this comment

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

I think when-... throughout it definitely the way forward. It helps make it clear what you are talking about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this being consistent, changed

@IgorMinar
Copy link
Contributor

the rest looks good to me

@lgalfaso
Copy link
Contributor Author

Please let me know if you would like me to rebase this into a single commit

@pkozlowski-opensource
Copy link
Member

@lgalfaso yes, squasing commits would be helpful - would make it easier to review and merge

@lgalfaso
Copy link
Contributor Author

@pkozlowski-opensource sure, done

@IgorMinar
Copy link
Contributor

LGTM.

@pkozlowski-opensource please merge

@pkozlowski-opensource
Copy link
Member

on it

@pkozlowski-opensource
Copy link
Member

@lgalfaso Sorry for being pain in a neck but 2ff7a69 is based on the 3-months old master and doesn't merge cleanly. I was trying to merge it in pkozlowski-opensource@f9c75e4 but after the merge there are several test failrues (different ones on different browsers), see:
http://ci.angularjs.org/job/angular.js-pawel/110/console

Not sure if this is due to my merges or there is something else going on so it would be awesome if you could have a look. Thnx!

lgalfaso added a commit to lgalfaso/angular.js that referenced this pull request Jul 12, 2013
Add an alternative way to define a mapping for ng:pluralize using
attributes instead of the `when` attribute

Closes angular#2454
@lgalfaso
Copy link
Contributor Author

@pkozlowski-opensource 5e8dfe1 is a clean merge to master

@pkozlowski-opensource
Copy link
Member

@lgalfaso merges cleanly now but there are 2 tests failures on IE8:
http://ci.angularjs.org/job/angular.js-pawel/112/console

When pushing a fix for those tests could you make sure that there is only one commit in the lgalfaso:easy-pluralize branch? (just push forced update). This would make my life easier!

Add an alternative way to define a mapping for ng:pluralize using
attributes instead of the `when` attribute

Closes angular#2454
@lgalfaso
Copy link
Contributor Author

@pkozlowski-opensource I do not have access to an IE8, but I think that 9e5876f will make IE8 happy

@pkozlowski-opensource
Copy link
Member

Bingo, lgalfaso@9e5876f did the trick.

Landed as a170fc1. Thank you!

ctrahey pushed a commit to ctrahey/angular.js that referenced this pull request Jul 22, 2013
Add an alternative way to define a mapping for ng:pluralize using
attributes instead of the `when` attribute

Closes angular#2454
@lgalfaso lgalfaso deleted the easy-pluralize branch February 8, 2014 17:21
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.

4 participants