Unified · Split
| @@ -4,11 +4,19 @@ class app.collections.Docs extends app.Collection · 3 unmodified lines | ||
| 4 | 4 | findBySlug: (slug) -> |
| 5 | 5 | @findBy('slug', slug) or @findBy('slug_without_version', slug) |
| 6 | 6 | |
| 7 | + NORMALIZE_VERSION_RGX = /\.(\d)$/ | |
| 8 | + NORMALIZE_VERSION_SUB = '.0$1' | |
| 7 | 9 | sort: -> |
| 8 | 10 | @models.sort (a, b) -> |
| 9 | − a = a.name.toLowerCase() | |
| 10 | − b = b.name.toLowerCase() | |
| 11 | − if a < b then -1 else if a > b then 1 else 0 | |
| 11 | + if a.name is b.name | |
| 12 | + if not a.version or a.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB) > b.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB) | |
| 13 | + -1 | |
| 14 | + else | |
| 15 | + 1 | |
| 16 | + else if a.name.toLowerCase() > b.name.toLowerCase() | |
| 17 | + 1 | |
| 18 | + else | |
| 19 | + -1 | |
| 12 | 20 | |
| 13 | 21 | # Load models concurrently. |
| 14 | 22 | # It's not pretty but I didn't want to import a promise library only for this. |