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
120120
121121 EMPTY_STRING = ''
122122 ELLIPSIS = '...'
123+ STRING = 'string'
123124
124125 @normalizeString: (string) ->
125126 string
@@ -209,9 +210,15 @@ class app.Searcher · 83 unmodified lines
209210 matcher = @matcher
210211 for [0...@chunkSize()]
211212 value = @data[@cursor][@attr]
212− valueLength = value.length
213− if score = matcher()
214− @addResult @data[@cursor], score
213+ if value.split # string
214+ valueLength = value.length
215+ @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
215222 @cursor++
216223 return
217224
assets/javascripts/models/entry.coffee+25−0
@@ -6,6 +6,7 @@ class app.models.Entry extends app.Model · 5 unmodified lines
66 constructor: ->
77 super
88 @text = app.Searcher.normalizeString(@name)
9+ @text = applyAliases(@text)
910
1011 fullPath: ->
1112 @doc.fullPath if @isIndex() then '' else @path
@@ -32,3 +33,27 @@ class app.models.Entry extends app.Model · 20 unmodified lines
3233
3334 loadFile: (onSuccess, onError) ->
3435 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
77 <ul class="_toc-list">
88 <li><a href="#search">Search</a>
99 <li><a href="#shortcuts">Keyboard Shortcuts</a>
10+ <li><a href="#abbreviations">Abbreviations</a>
1011 </ul>
1112 </div>
1213
1314 <h2 class="_lined-heading" id="search">Search</h2>
1415 <p>
1516 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>.
1720 <dl>
1821 <dt id="doc_search">Searching a single documentation
1922 <dd>
@@ -102,4 +105,14 @@ app.templates.helpPage = """ · 82 unmodified lines
102105 </dl>
103106 <p class="_note">
104107 <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
381381 @extend %label;
382382 }
383383
384+//
385+// Abbreviations
386+//
387+
388+._abbreviations td { @extend %code; }
389+
384390 //
385391 // Utilities
386392 //