Add field to docs.json denoting available aliases
Unified · Split
| @@ -1,6 +1,7 @@ | |||
| 1 | app.config = { | 1 | app.config = { |
| 2 | db_filename: 'db.json', | 2 | db_filename: 'db.json', |
| 3 | default_docs: <%= App.default_docs.to_json %>, | 3 | default_docs: <%= App.default_docs.to_json %>, |
| 4 | docs_aliases: <%= App.docs_aliases.to_json %>, | ||
| 4 | docs_origin: '<%= App.docs_origin %>', | 5 | docs_origin: '<%= App.docs_origin %>', |
| 5 | env: '<%= App.environment %>', | 6 | env: '<%= App.environment %>', |
| 6 | history_cache_size: 10, | 7 | history_cache_size: 10, |
| @@ -2,14 +2,15 @@ · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | app.models.Entry = class Entry extends app.Model { | 3 | app.models.Entry = class Entry extends app.Model { |
| 4 | static applyAliases(string) { | 4 | static applyAliases(string) { |
| 5 | if (Entry.ALIASES.hasOwnProperty(string)) { | 5 | const aliases = app.config.docs_aliases; |
| 6 | return [string, Entry.ALIASES[string]]; | 6 | if (aliases.hasOwnProperty(string)) { |
| 7 | return [string, aliases[string]]; | ||
| 7 | } else { | 8 | } else { |
| 8 | const words = string.split("."); | 9 | const words = string.split("."); |
| 9 | for (let i = 0; i < words.length; i++) { | 10 | for (let i = 0; i < words.length; i++) { |
| 10 | var word = words[i]; | 11 | var word = words[i]; |
| 11 | if (Entry.ALIASES.hasOwnProperty(word)) { | 12 | if (aliases.hasOwnProperty(word)) { |
| 12 | words[i] = Entry.ALIASES[word]; | 13 | words[i] = aliases[word]; |
| 13 | return [string, words.join(".")]; | 14 | return [string, words.join(".")]; |
| 14 | } | 15 | } |
| 15 | } | 16 | } |
| @@ -17,43 +18,7 @@ app.models.Entry = class Entry extends app.Model { · 1 unmodified line | |||
| 17 | return string; | 18 | return string; |
| 18 | } | 19 | } |
| 19 | 20 | ||
| 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 | }; | ||
| 55 | // Attributes: name, type, path | 21 | // Attributes: name, type, path |
| 56 | |||
| 57 | constructor() { | 22 | constructor() { |
| 58 | super(...arguments); | 23 | super(...arguments); |
| 59 | this.text = Entry.applyAliases(app.Searcher.normalizeString(this.name)); | 24 | this.text = Entry.applyAliases(app.Searcher.normalizeString(this.name)); |
| @@ -33,6 +33,42 @@ class App < Sinatra::Application · 32 unmodified lines | |||
| 33 | set :default_docs, %w(css dom html http javascript) | 33 | set :default_docs, %w(css dom html http javascript) |
| 34 | set :news_path, File.join(root, assets_prefix, 'javascripts', 'news.json') | 34 | set :news_path, File.join(root, assets_prefix, 'javascripts', 'news.json') |
| 35 | 35 | ||
| 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 | |||
| 36 | set :csp, false | 72 | set :csp, false |
| 37 | 73 | ||
| 38 | require 'docs' | 74 | require 'docs' |
| @@ -20,6 +20,7 @@ module Docs · 19 unmodified lines | |||
| 20 | if doc.options[:attribution].is_a?(String) | 20 | if doc.options[:attribution].is_a?(String) |
| 21 | json[:attribution] = doc.options[:attribution].strip | 21 | json[:attribution] = doc.options[:attribution].strip |
| 22 | end | 22 | end |
| 23 | json[:alias] = App.docs_aliases[json["slug"].try(:to_sym)] | ||
| 23 | result << json | 24 | result << json |
| 24 | end | 25 | end |
| 25 | end | 26 | end |
| @@ -1 +1 @@ | |||
| 1 | [{"name":"CSS","slug":"css","type":"mdn","release":null,"mtime":1420139788,"db_size":3460507},{"name":"DOM","slug":"dom","type":"mdn","release":null,"mtime":1420139789,"db_size":11399128},{"name":"DOM Events","slug":"dom_events","type":"mdn","release":null,"mtime":1420139790,"db_size":889020},{"name":"HTML","slug":"html~5","type":"mdn","version":"5","mtime":1420139791,"db_size":1835647},{"name":"HTML","slug":"html~4","type":"mdn","version":"4","mtime":1420139790,"db_size":1835646},{"name":"HTTP","slug":"http","type":"rfc","release":null,"mtime":1420139790,"db_size":183083},{"name":"JavaScript","slug":"javascript","type":"mdn","release":null,"mtime":1420139791,"db_size":4125477}] | 1 | [{"name":"CSS","slug":"css","type":"mdn","release":null,"mtime":1420139788,"db_size":3460507,"alias":null},{"name":"DOM","slug":"dom","type":"mdn","release":null,"mtime":1420139789,"db_size":11399128,"alias":null},{"name":"DOM Events","slug":"dom_events","type":"mdn","release":null,"mtime":1420139790,"db_size":889020,"alias":null},{"name":"HTML","slug":"html~5","type":"mdn","version":"5","mtime":1420139791,"db_size":1835647,"alias":null},{"name":"HTML","slug":"html~4","type":"mdn","version":"4","mtime":1420139790,"db_size":1835646,"alias":null},{"name":"HTTP","slug":"http","type":"rfc","release":null,"mtime":1420139790,"db_size":183083,"alias":null},{"name":"JavaScript","slug":"javascript","type":"mdn","release":null,"mtime":1420139791,"db_size":4125477,"alias":"js"}] |
| @@ -64,7 +64,7 @@ class ManifestTest < Minitest::Spec · 63 unmodified lines | |||
| 64 | it "includes the doc's meta representation" do | 64 | it "includes the doc's meta representation" do |
| 65 | json = manifest.as_json | 65 | json = manifest.as_json |
| 66 | assert_equal 1, json.length | 66 | assert_equal 1, json.length |
| 67 | assert_equal "{\"name\"=>\"Test\", \"db_size\"=>776533, :attribution=>\"foo\"}", json[0].to_s | 67 | assert_equal "{\"name\"=>\"Test\", \"db_size\"=>776533, :attribution=>\"foo\", \"alias\"=>nil}", json[0].to_s |
| 68 | end | 68 | end |
| 69 | end | 69 | end |
| 70 | 70 | ||