forked from docpad/docpad
/
files.coffee
41 lines (33 loc) · 874 Bytes
/
files.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Necessary
_ = require('underscore')
balUtil = require('bal-util')
# Local
{QueryCollection,Model} = require(__dirname+'/../base')
FileModel = require(__dirname+'/../models/file')
# Files Collection
class FilesCollection extends QueryCollection
# Base Model for all items in this collection
model: FileModel
# Base Collection for all child collections
collection: FilesCollection
# Fuzzy Find One
# Useful for layout searching
fuzzyFindOne: (data,sorting,paging) ->
# Prepare
queries = [
{id: data}
{relativePath: data}
{relativeBase: data}
{url: data}
{relativePath: $startsWith: data}
{fullPath: $startsWith: data}
{url: $startsWith: data}
]
# Try the queries
for query in queries
file = @findOne(query,sorting,paging)
return file if file
# Didn't find a file
return null
# Export
module.exports = FilesCollection