Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 78 lines (64 sloc) 2.813 kb
e9e80fd László Bácsi Support for more than one design doc in jake tasks
authored
1 exports.repos =
b0b9b6e László Bácsi Tasks for fetching repos from GitHub and updating design documents
authored
2 views:
3 by_watchers:
4 map: (doc) -> emit doc.watchers, doc.description if doc.watchers
f578dd1 László Bácsi View for fuzzy completion
authored
5
b0b9b6e László Bácsi Tasks for fetching repos from GitHub and updating design documents
authored
6 by_language:
8e9e968 László Bácsi Fix typo in repos/language view
authored
7 map: (doc) -> emit doc.language, doc.description if doc.language
f578dd1 László Bácsi View for fuzzy completion
authored
8
b0b9b6e László Bácsi Tasks for fetching repos from GitHub and updating design documents
authored
9 by_prefix:
10 map: (doc) ->
11cc4d6 László Bácsi Store only a few attributes of the search results in the database
authored
11 return unless doc.owner and doc.name
b0b9b6e László Bácsi Tasks for fetching repos from GitHub and updating design documents
authored
12
13 # emit all prefixes of name
14 for c, i in doc.name
fe09067 László Bácsi Make completion case-insensitive
authored
15 emit [doc.name.substr(0, i+1).toLowerCase(), doc.watchers], doc.description
b0b9b6e László Bácsi Tasks for fetching repos from GitHub and updating design documents
authored
16
17 # emit all prefixes of owner
18 for c, i in doc.owner
fe09067 László Bácsi Make completion case-insensitive
authored
19 prefix = doc.owner.substr(0, i+1).toLowerCase()
b0b9b6e László Bácsi Tasks for fetching repos from GitHub and updating design documents
authored
20 emit [prefix, doc.watchers], doc.description
21
22 # emit all combined prefixes
23 for d, j in doc.name
fe09067 László Bácsi Make completion case-insensitive
authored
24 emit [prefix + '/' + doc.name.substr(0, j+1).toLowerCase(), doc.watchers], doc.description
f578dd1 László Bácsi View for fuzzy completion
authored
25 return
26
27 by_fuzzy:
28 map: (doc) ->
29 return unless doc.owner and doc.name
30
31 combinations = (arr, max) ->
32 combine = (n, src, got, all) ->
33 if n is 0
34 all[all.length] = got if got.length > 0
35 return
36 for item, j in src
37 combine(n - 1, src.slice(j + 1), got.concat([item]), all)
38 return
39 all = []
40 max = arr.length unless max and max < arr.length
41 for i in [1..max]
42 combine(i, arr, [], all)
43 all
44
45 prefixVariations = (words, max, got=[]) ->
46 current = words[0]
47 max_length = if max and max < current.length then max else current.length
48 if words.length > 1
49 all = []
50 for i in [1..max_length]
51 all = all.concat(prefixVariations(words.slice(1), max, got.concat([current.substr(0,i)])))
52 all
53 else
54 got.concat([current.substr(0,i)]).join('') for i in [1..max_length]
55
56 # only split on capital letters if there's no _ or - in the id
57 id = doc._id.indexOf('_') == -1 && doc._id.indexOf('-') == -1 && doc._id.replace(/([A-Z][^A-Z])/g, '-$1') || doc._id
58 words = id.toLowerCase().split(/[^a-z0-9]+/).filter (s) -> s.length > 0
59
60 for combination in combinations(words, 7)
61 max = if combination.length < 5 then undefined else 10-combination.length
62 for key in prefixVariations(combination, max)
63 emit [key, doc.watchers], doc.description
64
65 # making sure the full names are emitted
66 if words.length > 7 or combination.length > 4 and words.some((w) -> w.length > 10-words.length)
67 emit [doc._id.toLowerCase().replace(/[^a-z0-9]/g, ''), doc.watchers], doc.description
68
69 return
b0b9b6e László Bácsi Tasks for fetching repos from GitHub and updating design documents
authored
70
71 lists:
72 complete: (head, req) ->
73 start
74 headers: { 'Content-Type': 'text/plain' }
75 while row = getRow()
76 send "#{row.id.replace(':', '/')} (#{row.key[1]}) #{row.value}\n"
77 return
Something went wrong with that request. Please try again.