Skip to content

Commit 050022b

Browse files
committed
Move docs_aliases to class App
1 parent ed116eb commit 050022b

File tree

4 files changed

+43
-49
lines changed

4 files changed

+43
-49
lines changed

assets/javascripts/app/config.js.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
app.config = {
22
db_filename: 'db.json',
33
default_docs: <%= App.default_docs.to_json %>,
4+
docs_aliases: <%= App.docs_aliases.to_json %>,
45
docs_origin: '<%= App.docs_origin %>',
56
env: '<%= App.environment %>',
67
history_cache_size: 10,

assets/javascripts/models/entry.js

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,23 @@
22

33
app.models.Entry = class Entry extends app.Model {
44
static applyAliases(string) {
5-
if (Entry.ALIASES.hasOwnProperty(string)) {
6-
return [string, Entry.ALIASES[string]];
5+
const aliases = app.config.docs_aliases;
6+
if (aliases.hasOwnProperty(string)) {
7+
return [string, aliases[string]];
78
} else {
89
const words = string.split(".");
910
for (let i = 0; i < words.length; i++) {
1011
var word = words[i];
11-
if (Entry.ALIASES.hasOwnProperty(word)) {
12-
words[i] = Entry.ALIASES[word];
12+
if (aliases.hasOwnProperty(word)) {
13+
words[i] = aliases[word];
1314
return [string, words.join(".")];
1415
}
1516
}
1617
}
1718
return string;
1819
}
1920

20-
static ALIASES = {
21-
angular: "ng",
22-
"angular.js": "ng",
23-
"backbone.js": "bb",
24-
"c++": "cpp",
25-
coffeescript: "cs",
26-
crystal: "cr",
27-
elixir: "ex",
28-
javascript: "js",
29-
julia: "jl",
30-
jquery: "$",
31-
"knockout.js": "ko",
32-
kubernetes: "k8s",
33-
less: "ls",
34-
lodash: "_",
35-
löve: "love",
36-
marionette: "mn",
37-
markdown: "md",
38-
matplotlib: "mpl",
39-
modernizr: "mdr",
40-
"moment.js": "mt",
41-
openjdk: "java",
42-
nginx: "ngx",
43-
numpy: "np",
44-
pandas: "pd",
45-
postgresql: "pg",
46-
python: "py",
47-
"ruby.on.rails": "ror",
48-
ruby: "rb",
49-
rust: "rs",
50-
sass: "scss",
51-
tensorflow: "tf",
52-
typescript: "ts",
53-
"underscore.js": "_",
54-
};
5521
// Attributes: name, type, path
56-
5722
constructor() {
5823
super(...arguments);
5924
this.text = Entry.applyAliases(app.Searcher.normalizeString(this.name));

lib/app.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,42 @@ class App < Sinatra::Application
3333
set :default_docs, %w(css dom html http javascript)
3434
set :news_path, File.join(root, assets_prefix, 'javascripts', 'news.json')
3535

36+
set :docs_aliases, {
37+
'angular' => 'ng',
38+
'angular.js' => 'ng',
39+
'backbone.js' => 'bb',
40+
'c++' => 'cpp',
41+
'coffeescript' => 'cs',
42+
'crystal' => 'cr',
43+
'elixir' => 'ex',
44+
'javascript' => 'js',
45+
'julia' => 'jl',
46+
'jquery' => '$',
47+
'knockout.js' => 'ko',
48+
'kubernetes' => 'k8s',
49+
'less' => 'ls',
50+
'lodash' => '_',
51+
'löve' => 'love',
52+
'marionette' => 'mn',
53+
'markdown' => 'md',
54+
'matplotlib' => 'mpl',
55+
'modernizr' => 'mdr',
56+
'moment.js' => 'mt',
57+
'openjdk' => 'java',
58+
'nginx' => 'ngx',
59+
'numpy' => 'np',
60+
'pandas' => 'pd',
61+
'postgresql' => 'pg',
62+
'python' => 'py',
63+
'ruby.on.rails' => 'ror',
64+
'ruby' => 'rb',
65+
'rust' => 'rs',
66+
'sass' => 'scss',
67+
'tensorflow' => 'tf',
68+
'typescript' => 'ts',
69+
'underscore.js' => '_',
70+
}
71+
3672
set :csp, false
3773

3874
require 'docs'

lib/docs/core/manifest.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@ def as_json
2020
if doc.options[:attribution].is_a?(String)
2121
json[:attribution] = doc.options[:attribution].strip
2222
end
23-
24-
# parse doc aliases from JS file as Ruby hash
25-
entry_file = File.open("assets/javascripts/models/entry.js")
26-
data = entry_file.read
27-
aliases = eval data.split("ALIASES = ").last.split(";").first
28-
29-
# set alias value
30-
json["alias"] = aliases[json["slug"].try(:to_sym)]
31-
23+
json[:alias] = App.docs_aliases[json["slug"].try(:to_sym)]
3224
result << json
3325
end
3426
end

0 commit comments

Comments
 (0)