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