History

Add search abbreviations

Closes #193.

Thibaut committed 11 years ago

Commit 35f7b6a1 parent 13c15884 files · +56 −5Browse files

Unified · Split

4 files
  1. assets/javascripts/app/searcher.coffee +10 −3
  2. assets/javascripts/models/entry.coffee +25 −0
  3. assets/javascripts/templates/pages/help_tmpl.coffee +15 −2
  4. assets/stylesheets/components/_content.scss +6 −0
assets/javascripts/app/searcher.coffee+10−3
@@ -120,6 +120,7 @@ class app.Searcher · 119 unmodified lines
120 120
121 EMPTY_STRING = ''121 EMPTY_STRING = ''
122 ELLIPSIS = '...'122 ELLIPSIS = '...'
123 STRING = 'string'
123 124
124 @normalizeString: (string) ->125 @normalizeString: (string) ->
125 string126 string
@@ -209,9 +210,15 @@ class app.Searcher · 83 unmodified lines
209 matcher = @matcher210 matcher = @matcher
210 for [0...@chunkSize()]211 for [0...@chunkSize()]
211 value = @data[@cursor][@attr]212 value = @data[@cursor][@attr]
212 valueLength = value.length213 if value.split # string
213 if score = matcher()214 valueLength = value.length
214 @addResult @data[@cursor], score215 @addResult(@data[@cursor], score) if score = matcher()
216 else # array
217 score = 0
218 for value in @data[@cursor][@attr]
219 valueLength = value.length
220 score = Math.max(score, matcher() || 0)
221 @addResult(@data[@cursor], score) if score > 0
215 @cursor++222 @cursor++
216 return223 return
217 224
assets/javascripts/models/entry.coffee+25−0
@@ -6,6 +6,7 @@ class app.models.Entry extends app.Model · 5 unmodified lines
6 constructor: ->6 constructor: ->
7 super7 super
8 @text = app.Searcher.normalizeString(@name)8 @text = app.Searcher.normalizeString(@name)
9 @text = applyAliases(@text)
9 10
10 fullPath: ->11 fullPath: ->
11 @doc.fullPath if @isIndex() then '' else @path12 @doc.fullPath if @isIndex() then '' else @path
@@ -32,3 +33,27 @@ class app.models.Entry extends app.Model · 20 unmodified lines
32 33
33 loadFile: (onSuccess, onError) ->34 loadFile: (onSuccess, onError) ->
34 app.db.load(@, onSuccess, onError)35 app.db.load(@, onSuccess, onError)
36
37 applyAliases = (string) ->
38 if ALIASES.hasOwnProperty(string)
39 return [string, ALIASES[string]]
40 else
41 words = string.split('.')
42 for word, i in words when ALIASES.hasOwnProperty(word)
43 words[i] = ALIASES[word]
44 return [string, words.join('.')]
45 return string
46
47 @ALIASES = ALIASES =
48 'angular.js': 'ng'
49 'backbone': 'bb'
50 'c++': 'cpp'
51 'coffeescript': 'cs'
52 'javascript': 'js'
53 'jquery': '$'
54 'knockout.js': 'ko'
55 'lodash': '_'
56 'markdown': 'md'
57 'postgresql': 'pg'
58 'sass': 'scss'
59 'underscore.js': '_'
assets/javascripts/templates/pages/help_tmpl.coffee+15−2
@@ -7,13 +7,16 @@ app.templates.helpPage = """ · 6 unmodified lines
7 <ul class="_toc-list">7 <ul class="_toc-list">
8 <li><a href="#search">Search</a>8 <li><a href="#search">Search</a>
9 <li><a href="#shortcuts">Keyboard Shortcuts</a>9 <li><a href="#shortcuts">Keyboard Shortcuts</a>
10 <li><a href="#abbreviations">Abbreviations</a>
10 </ul>11 </ul>
11 </div>12 </div>
12 13
13 <h2 class="_lined-heading" id="search">Search</h2>14 <h2 class="_lined-heading" id="search">Search</h2>
14 <p>15 <p>
15 The search is case-insensitive and supports fuzzy matching (for queries longer than two characters).16 The search is case-insensitive and supports fuzzy matching (for queries longer than two characters).
16 For example, searching <code class="_label">bgcp</code> brings up <code class="_label">background-clip</code>.17 For example, searching <code class="_label">bgcp</code> brings up <code class="_label">background-clip</code>.<br>
18 Abbreviations are also supported (<a href="#abbreviations">full list</a> below).
19 For example, <code class="_label">$</code> is an alias for <code class="_label">jQuery</code>.
17 <dl>20 <dl>
18 <dt id="doc_search">Searching a single documentation21 <dt id="doc_search">Searching a single documentation
19 <dd>22 <dd>
@@ -102,4 +105,14 @@ app.templates.helpPage = """ · 82 unmodified lines
102 </dl>105 </dl>
103 <p class="_note">106 <p class="_note">
104 <strong>Tip:</strong> If the cursor is no longer in the search field, press backspace or107 <strong>Tip:</strong> If the cursor is no longer in the search field, press backspace or
105 continue to type and it will refocus the search field and start showing new results. """108 continue to type and it will refocus the search field and start showing new results.
109
110 <h2 class="_lined-heading" id="abbreviations">Abbreviations</h2>
111 <p>Feel free to suggest new abbreviations on <a href="https://github.com/Thibaut/devdocs/issues/new">GitHub</a>.
112 <table class="_abbreviations">
113 <tr>
114 <th>Word
115 <th>Alias
116 #{("<tr><td>#{key}<td>#{value}" for key, value of app.models.Entry.ALIASES).join('')}
117 </table>
118"""
assets/stylesheets/components/_content.scss+6−0
@@ -381,6 +381,12 @@ · 380 unmodified lines
381 @extend %label;381 @extend %label;
382}382}
383 383
384//
385// Abbreviations
386//
387
388._abbreviations td { @extend %code; }
389
384//390//
385// Utilities391// Utilities
386//392//