mirror of https://github.com/vuejs/vue.git
add pluralize filter
This commit is contained in:
parent
2e5fc62dcb
commit
9546965ae0
1
TODO.md
1
TODO.md
|
|
@ -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
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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 = ''
|
||||
|
|
|
|||
|
|
@ -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]) || '$',
|
||||
|
|
|
|||
Loading…
Reference in New Issue