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 = '' EMPTY_STRING = ''
ELLIPSIS = '...' ELLIPSIS = '...'
STRING = 'string'
@normalizeString: (string) -> @normalizeString: (string) ->
string string
@ -209,9 +210,15 @@ class app.Searcher
matcher = @matcher matcher = @matcher
for [0...@chunkSize()] for [0...@chunkSize()]
value = @data[@cursor][@attr] value = @data[@cursor][@attr]
if value.split # string
valueLength = value.length valueLength = value.length
if score = matcher() @addResult(@data[@cursor], score) if score = matcher()
@addResult @data[@cursor], score 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++ @cursor++
return return

@ -6,6 +6,7 @@ class app.models.Entry extends app.Model
constructor: -> constructor: ->
super super
@text = app.Searcher.normalizeString(@name) @text = app.Searcher.normalizeString(@name)
@text = applyAliases(@text)
fullPath: -> fullPath: ->
@doc.fullPath if @isIndex() then '' else @path @doc.fullPath if @isIndex() then '' else @path
@ -32,3 +33,27 @@ class app.models.Entry extends app.Model
loadFile: (onSuccess, onError) -> loadFile: (onSuccess, onError) ->
app.db.load(@, 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"> <ul class="_toc-list">
<li><a href="#search">Search</a> <li><a href="#search">Search</a>
<li><a href="#shortcuts">Keyboard Shortcuts</a> <li><a href="#shortcuts">Keyboard Shortcuts</a>
<li><a href="#abbreviations">Abbreviations</a>
</ul> </ul>
</div> </div>
<h2 class="_lined-heading" id="search">Search</h2> <h2 class="_lined-heading" id="search">Search</h2>
<p> <p>
The search is case-insensitive and supports fuzzy matching (for queries longer than two characters). 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> <dl>
<dt id="doc_search">Searching a single documentation <dt id="doc_search">Searching a single documentation
<dd> <dd>
@ -102,4 +105,14 @@ app.templates.helpPage = """
</dl> </dl>
<p class="_note"> <p class="_note">
<strong>Tip:</strong> If the cursor is no longer in the search field, press backspace or <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; @extend %label;
} }
//
// Abbreviations
//
._abbreviations td { @extend %code; }
// //
// Utilities // Utilities
// //

Loading…
Cancel
Save