Permalink
Browse files

add a model name formatter

  • Loading branch information...
1 parent 5015cfb commit 0936df8968e731702b80e464cf051380888d4381 Chris McBride committed Dec 19, 2012
Showing with 19 additions and 10 deletions.
  1. +13 −5 lib/format.coffee
  2. +6 −5 quips.coffee
View
@@ -41,9 +41,17 @@ formatNumber = (number, places) ->
i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + ',') +
(if places then "." + Math.abs(number - i).toFixed(places).slice(2) else "")
+modelNames = (models) ->
+ names = model.get('name') for model in models
+ if names.length < 3
+ names.join(' and ')
+ else
+ "#{names[0...names.length-1].join(', ')}, and #{names[names.length-1]}"
+
module.exports =
- date: date
- dateTime: dateTime
- boolean: boolean
- money: money
- number: number
+ date: date
+ dateTime: dateTime
+ boolean: boolean
+ money: money
+ number: number
+ modelNames: modelNames
View
@@ -34,11 +34,12 @@ module.exports =
# Formatters
formatters:
- date: require('quips/lib/format').date
- dateTime: require('quips/lib/format').dateTime
- boolean: require('quips/lib/format').boolean
- money: require('quips/lib/format').money
- number: require('quips/lib/format').number
+ date: require('quips/lib/format').date
+ dateTime: require('quips/lib/format').dateTime
+ boolean: require('quips/lib/format').boolean
+ money: require('quips/lib/format').money
+ number: require('quips/lib/format').number
+ modelNames: require('quips/lib/format').modelNames
# Test
ChaiExtensions: require 'quips/test/lib/chai_extensions'

0 comments on commit 0936df8

Please sign in to comment.