Add search abbreviations

Closes #193.
pull/229/merge
Thibaut 10 years ago
parent 13c1588f5a
commit 35f7b6a9bb

@ -120,6 +120,7 @@ class app.Searcher
EMPTY_STRING = ''
ELLIPSIS = '...'
STRING = 'string'
@normalizeString: (string) ->
string
@ -209,9 +210,15 @@ class app.Searcher
matcher = @matcher
for [0...@chunkSize()]
value = @data[@cursor][@attr]
valueLength = value.length
if score = matcher()
@addResult @data[@cursor], score
if value.split # string
valueLength = value.length
@addResult(@data[@cursor], score) if score = matcher()
else # array
score = 0
for value in @data[@cursor][@attr]
valueLength = value.length
score = Math.max(score, matcher() || 0)
@addResult(@data[@cursor], score) if score > 0
@cursor++
return

@ -6,6 +6,7 @@ class app.models.Entry extends app.Model
constructor: ->
super
@text = app.Searcher.normalizeString(@name)
@text = applyAliases(@text)
fullPath: ->
@doc.fullPath if @isIndex() then '' else @path
@ -32,3 +33,27 @@ class app.models.Entry extends app.Model
loadFile: (onSuccess, onError) ->
app.db.load(@, onSuccess, onError)
applyAliases = (string) ->
if ALIASES.hasOwnProperty(string)
return [string, ALIASES[string]]
else
words = string.split('.')
for word, i in words when ALIASES.hasOwnProperty(word)
words[i] = ALIASES[word]
return [string, words.join('.')]
return string
@ALIASES = ALIASES =
'angular.js': 'ng'
'backbone': 'bb'
'c++': 'cpp'
'coffeescript': 'cs'
'javascript': 'js'
'jquery': '$'
'knockout.js': 'ko'
'lodash': '_'
'markdown': 'md'
'postgresql': 'pg'
'sass': 'scss'
'underscore.js': '_'

@ -7,13 +7,16 @@ app.templates.helpPage = """
<ul class="_toc-list">
<li><a href="#search">Search</a>
<li><a href="#shortcuts">Keyboard Shortcuts</a>
<li><a href="#abbreviations">Abbreviations</a>
</ul>
</div>
<h2 class="_lined-heading" id="search">Search</h2>
<p>
The search is case-insensitive and supports fuzzy matching (for queries longer than two characters).
For example, searching <code class="_label">bgcp</code> brings up <code class="_label">background-clip</code>.
For example, searching <code class="_label">bgcp</code> brings up <code class="_label">background-clip</code>.<br>
Abbreviations are also supported (<a href="#abbreviations">full list</a> below).
For example, <code class="_label">$</code> is an alias for <code class="_label">jQuery</code>.
<dl>
<dt id="doc_search">Searching a single documentation
<dd>
@ -102,4 +105,14 @@ app.templates.helpPage = """
</dl>
<p class="_note">
<strong>Tip:</strong> If the cursor is no longer in the search field, press backspace or
continue to type and it will refocus the search field and start showing new results. """
continue to type and it will refocus the search field and start showing new results.
<h2 class="_lined-heading" id="abbreviations">Abbreviations</h2>
<p>Feel free to suggest new abbreviations on <a href="https://github.com/Thibaut/devdocs/issues/new">GitHub</a>.
<table class="_abbreviations">
<tr>
<th>Word
<th>Alias
#{("<tr><td>#{key}<td>#{value}" for key, value of app.models.Entry.ALIASES).join('')}
</table>
"""

@ -381,6 +381,12 @@
@extend %label;
}
//
// Abbreviations
//
._abbreviations td { @extend %code; }
//
// Utilities
//

Loading…
Cancel
Save