add pluralize filter

This commit is contained in:
Evan You 2013-08-11 22:35:06 -04:00
parent 2e5fc62dcb
commit 9546965ae0
5 changed files with 54 additions and 1638 deletions

View File

@ -1,5 +1,6 @@
- tests
- docs
- validation as filter, e.g. sd-value="email | validate email"
- sd-with
- standarized way to reuse components (sd-component?)
- plugins: seed-touch, seed-storage, seed-router

1676
dist/seed.js vendored

File diff suppressed because one or more lines are too long

View File

@ -53,7 +53,7 @@
</section>
<footer id="footer" sd-show="total">
<span id="todo-count">
<strong sd-text="remaining"></strong> {{itemLabel}} left
<strong sd-text="remaining"></strong> {{remaining | pluralize item}} left
</span>
<ul id="filters">
<li><a href="#/all" sd-class="selected:checkFilter">All</a></li>

View File

@ -15,8 +15,7 @@ Seed.controller('Todos', function (scope) {
updateFilter()
window.addEventListener('hashchange', updateFilter)
function updateFilter () {
if (!location.hash) return
scope.filter = location.hash.slice(2) || 'all'
scope.filter = location.hash ? location.hash.slice(2) : 'all'
}
// regular properties -----------------------------------------------------
@ -34,10 +33,6 @@ Seed.controller('Todos', function (scope) {
return scope.total - scope.remaining
}}
scope.itemLabel = {get: function () {
return scope.remaining > 1 ? 'items' : 'item'
}}
// dynamic context computed property using info from target scope
scope.filterTodo = {get: function (e) {
return filters[scope.filter](e.scope.completed)
@ -63,7 +58,7 @@ Seed.controller('Todos', function (scope) {
// event handlers ---------------------------------------------------------
scope.addTodo = function () {
var value = scope.newTodo.trim()
var value = scope.newTodo && scope.newTodo.trim()
if (value) {
scope.todos.unshift({ title: value, completed: false })
scope.newTodo = ''

View File

@ -29,6 +29,10 @@ module.exports = {
return value ? value.toString().toLowerCase() : ''
},
pluralize: function (value, args) {
return value === 1 ? args[0] : (args[1] || args[0] + 's')
},
currency: function (value, args) {
if (!value) return ''
var sign = (args && args[0]) || '$',