wwwjdic 15.0.0 → 16.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +13 -0
  3. data/Gemfile +4 -0
  4. data/README.md +6 -7
  5. data/Rakefile +4 -0
  6. data/examples/basics.rb +4 -0
  7. data/examples/translate.rb +26 -0
  8. data/examples/uri.rb +16 -0
  9. data/html/CHANGELOG.html +37 -30
  10. data/html/COPYING_md.html +22 -30
  11. data/html/Gemfile.html +25 -31
  12. data/html/Object.html +825 -63
  13. data/html/README_md.html +27 -33
  14. data/html/Rakefile.html +25 -31
  15. data/html/WWWJDic.html +42 -124
  16. data/html/WWWJDic/ParsableDuckType.html +35 -57
  17. data/html/WWWJDic/Parser.html +48 -90
  18. data/html/WWWJDic/Parsers.html +28 -36
  19. data/html/WWWJDic/Parsers/Dict.html +47 -73
  20. data/html/WWWJDic/Parsers/Display.html +42 -68
  21. data/html/WWWJDic/Parsers/Key.html +42 -68
  22. data/html/WWWJDic/Parsers/Search.html +38 -61
  23. data/html/WWWJDic/Parsers/Server.html +42 -68
  24. data/html/WWWJDic/Splitter.html +76 -173
  25. data/html/WWWJDic/Utils.html +28 -36
  26. data/html/WWWJDic/Utils/Downloader.html +28 -36
  27. data/html/WWWJDic/Utils/Downloader/Downloader.html +41 -80
  28. data/html/WWWJDic/Utils/Raisers.html +42 -96
  29. data/html/WWWJDic/WWWJDic.html +160 -342
  30. data/html/copyright_md.html +22 -30
  31. data/html/created.rid +32 -54
  32. data/html/css/rdoc.css +1 -1
  33. data/html/index.html +26 -51
  34. data/html/js/darkfish.js +84 -84
  35. data/html/js/navigation.js.gz +0 -0
  36. data/html/js/search.js +110 -110
  37. data/html/js/search_index.js +1 -1
  38. data/html/js/search_index.js.gz +0 -0
  39. data/html/js/searcher.js +229 -229
  40. data/html/js/searcher.js.gz +0 -0
  41. data/html/table_of_contents.html +153 -161
  42. data/lib/wwwjdic.rb +7 -4
  43. data/lib/wwwjdic/application.rb +52 -25
  44. data/lib/wwwjdic/constants.rb +33 -3
  45. data/lib/wwwjdic/locales/de.yml +2 -0
  46. data/lib/wwwjdic/locales/en.yml +2 -0
  47. data/lib/wwwjdic/locales/es.yml +2 -0
  48. data/lib/wwwjdic/locales/fr.yml +2 -0
  49. data/lib/wwwjdic/locales/hu.yml +2 -0
  50. data/lib/wwwjdic/locales/it.yml +2 -0
  51. data/lib/wwwjdic/locales/ja.yml +3 -1
  52. data/lib/wwwjdic/locales/nl.yml +2 -0
  53. data/lib/wwwjdic/locales/ru.yml +2 -0
  54. data/lib/wwwjdic/locales/sl.yml +2 -0
  55. data/lib/wwwjdic/locales/sv.yml +2 -0
  56. data/lib/wwwjdic/parser.rb +7 -4
  57. data/lib/wwwjdic/parsers/dict.rb +4 -1
  58. data/lib/wwwjdic/parsers/display.rb +4 -1
  59. data/lib/wwwjdic/parsers/key.rb +4 -1
  60. data/lib/wwwjdic/parsers/search.rb +4 -0
  61. data/lib/wwwjdic/parsers/server.rb +4 -1
  62. data/lib/wwwjdic/utils/downloader.rb +7 -8
  63. data/lib/wwwjdic/utils/raisers.rb +7 -13
  64. data/lib/wwwjdic/utils/splitter.rb +18 -9
  65. data/lib/wwwjdic/version.rb +5 -1
  66. data/test/test_helper.rb +4 -0
  67. data/test/test_wwwjdic.rb +4 -0
  68. data/test/wwwjdic/locales/de.yml +2 -0
  69. data/test/wwwjdic/locales/en.yml +2 -0
  70. data/test/wwwjdic/locales/es.yml +2 -0
  71. data/test/wwwjdic/locales/fr.yml +2 -0
  72. data/test/wwwjdic/locales/hu.yml +2 -0
  73. data/test/wwwjdic/locales/it.yml +2 -0
  74. data/test/wwwjdic/locales/ja.yml +2 -0
  75. data/test/wwwjdic/locales/nl.yml +2 -0
  76. data/test/wwwjdic/locales/ru.yml +2 -0
  77. data/test/wwwjdic/locales/sl.yml +2 -0
  78. data/test/wwwjdic/locales/sv.yml +2 -0
  79. data/test/wwwjdic/locales/test_locales.rb +35 -19
  80. data/test/wwwjdic/parsers/test_dict.rb +62 -36
  81. data/test/wwwjdic/parsers/test_display.rb +4 -0
  82. data/test/wwwjdic/parsers/test_key.rb +4 -0
  83. data/test/wwwjdic/parsers/test_server.rb +4 -0
  84. data/test/wwwjdic/test_application.rb +196 -148
  85. data/test/wwwjdic/test_parsable_duck_type.rb +4 -3
  86. data/test/wwwjdic/utils/test_downloader.rb +4 -0
  87. data/test/wwwjdic/utils/test_raisers.rb +42 -27
  88. data/wwwjdic.gemspec +14 -11
  89. metadata +19 -33
Binary file
data/html/js/search.js CHANGED
@@ -1,110 +1,110 @@
1
- Search = function(data, input, result) {
2
- this.data = data;
3
- this.input = input;
4
- this.result = result;
5
-
6
- this.current = null;
7
- this.view = this.result.parentNode;
8
- this.searcher = new Searcher(data.index);
9
- this.init();
10
- }
11
-
12
- Search.prototype = Object.assign({}, Navigation, new function() {
13
- var suid = 1;
14
-
15
- this.init = function() {
16
- var _this = this;
17
- var observer = function(e) {
18
- switch(e.keyCode) {
19
- case 38: // Event.KEY_UP
20
- case 40: // Event.KEY_DOWN
21
- return;
22
- }
23
- _this.search(_this.input.value);
24
- };
25
- this.input.addEventListener('keyup', observer);
26
- this.input.addEventListener('click', observer); // mac's clear field
27
-
28
- this.searcher.ready(function(results, isLast) {
29
- _this.addResults(results, isLast);
30
- })
31
-
32
- this.initNavigation();
33
- this.setNavigationActive(false);
34
- }
35
-
36
- this.search = function(value, selectFirstMatch) {
37
- value = value.trim().toLowerCase();
38
- if (value) {
39
- this.setNavigationActive(true);
40
- } else {
41
- this.setNavigationActive(false);
42
- }
43
-
44
- if (value == '') {
45
- this.lastQuery = value;
46
- this.result.innerHTML = '';
47
- this.result.setAttribute('aria-expanded', 'false');
48
- this.setNavigationActive(false);
49
- } else if (value != this.lastQuery) {
50
- this.lastQuery = value;
51
- this.result.setAttribute('aria-busy', 'true');
52
- this.result.setAttribute('aria-expanded', 'true');
53
- this.firstRun = true;
54
- this.searcher.find(value);
55
- }
56
- }
57
-
58
- this.addResults = function(results, isLast) {
59
- var target = this.result;
60
- if (this.firstRun && (results.length > 0 || isLast)) {
61
- this.current = null;
62
- this.result.innerHTML = '';
63
- }
64
-
65
- for (var i=0, l = results.length; i < l; i++) {
66
- var item = this.renderItem.call(this, results[i]);
67
- item.setAttribute('id', 'search-result-' + target.childElementCount);
68
- target.appendChild(item);
69
- }
70
-
71
- if (this.firstRun && results.length > 0) {
72
- this.firstRun = false;
73
- this.current = target.firstChild;
74
- this.current.classList.add('search-selected');
75
- }
76
- //TODO: ECMAScript
77
- //if (jQuery.browser.msie) this.$element[0].className += '';
78
-
79
- if (isLast) this.result.setAttribute('aria-busy', 'false');
80
- }
81
-
82
- this.move = function(isDown) {
83
- if (!this.current) return;
84
- var next = isDown ? this.current.nextElementSibling : this.current.previousElementSibling;
85
- if (next) {
86
- this.current.classList.remove('search-selected');
87
- next.classList.add('search-selected');
88
- this.input.setAttribute('aria-activedescendant', next.getAttribute('id'));
89
- this.scrollIntoView(next, this.view);
90
- this.current = next;
91
- this.input.value = next.firstChild.firstChild.text;
92
- this.input.select();
93
- }
94
- return true;
95
- }
96
-
97
- this.hlt = function(html) {
98
- return this.escapeHTML(html).
99
- replace(/\u0001/g, '<em>').
100
- replace(/\u0002/g, '</em>');
101
- }
102
-
103
- this.escapeHTML = function(html) {
104
- return html.replace(/[&<>]/g, function(c) {
105
- return '&#' + c.charCodeAt(0) + ';';
106
- });
107
- }
108
-
109
- });
110
-
1
+ Search = function(data, input, result) {
2
+ this.data = data;
3
+ this.input = input;
4
+ this.result = result;
5
+
6
+ this.current = null;
7
+ this.view = this.result.parentNode;
8
+ this.searcher = new Searcher(data.index);
9
+ this.init();
10
+ }
11
+
12
+ Search.prototype = Object.assign({}, Navigation, new function() {
13
+ var suid = 1;
14
+
15
+ this.init = function() {
16
+ var _this = this;
17
+ var observer = function(e) {
18
+ switch(e.keyCode) {
19
+ case 38: // Event.KEY_UP
20
+ case 40: // Event.KEY_DOWN
21
+ return;
22
+ }
23
+ _this.search(_this.input.value);
24
+ };
25
+ this.input.addEventListener('keyup', observer);
26
+ this.input.addEventListener('click', observer); // mac's clear field
27
+
28
+ this.searcher.ready(function(results, isLast) {
29
+ _this.addResults(results, isLast);
30
+ })
31
+
32
+ this.initNavigation();
33
+ this.setNavigationActive(false);
34
+ }
35
+
36
+ this.search = function(value, selectFirstMatch) {
37
+ value = value.trim().toLowerCase();
38
+ if (value) {
39
+ this.setNavigationActive(true);
40
+ } else {
41
+ this.setNavigationActive(false);
42
+ }
43
+
44
+ if (value == '') {
45
+ this.lastQuery = value;
46
+ this.result.innerHTML = '';
47
+ this.result.setAttribute('aria-expanded', 'false');
48
+ this.setNavigationActive(false);
49
+ } else if (value != this.lastQuery) {
50
+ this.lastQuery = value;
51
+ this.result.setAttribute('aria-busy', 'true');
52
+ this.result.setAttribute('aria-expanded', 'true');
53
+ this.firstRun = true;
54
+ this.searcher.find(value);
55
+ }
56
+ }
57
+
58
+ this.addResults = function(results, isLast) {
59
+ var target = this.result;
60
+ if (this.firstRun && (results.length > 0 || isLast)) {
61
+ this.current = null;
62
+ this.result.innerHTML = '';
63
+ }
64
+
65
+ for (var i=0, l = results.length; i < l; i++) {
66
+ var item = this.renderItem.call(this, results[i]);
67
+ item.setAttribute('id', 'search-result-' + target.childElementCount);
68
+ target.appendChild(item);
69
+ };
70
+
71
+ if (this.firstRun && results.length > 0) {
72
+ this.firstRun = false;
73
+ this.current = target.firstChild;
74
+ this.current.classList.add('search-selected');
75
+ }
76
+ //TODO: ECMAScript
77
+ //if (jQuery.browser.msie) this.$element[0].className += '';
78
+
79
+ if (isLast) this.result.setAttribute('aria-busy', 'false');
80
+ }
81
+
82
+ this.move = function(isDown) {
83
+ if (!this.current) return;
84
+ var next = isDown ? this.current.nextElementSibling : this.current.previousElementSibling;
85
+ if (next) {
86
+ this.current.classList.remove('search-selected');
87
+ next.classList.add('search-selected');
88
+ this.input.setAttribute('aria-activedescendant', next.getAttribute('id'));
89
+ this.scrollIntoView(next, this.view);
90
+ this.current = next;
91
+ this.input.value = next.firstChild.firstChild.text;
92
+ this.input.select();
93
+ }
94
+ return true;
95
+ }
96
+
97
+ this.hlt = function(html) {
98
+ return this.escapeHTML(html).
99
+ replace(/\u0001/g, '<em>').
100
+ replace(/\u0002/g, '</em>');
101
+ }
102
+
103
+ this.escapeHTML = function(html) {
104
+ return html.replace(/[&<>]/g, function(c) {
105
+ return '&#' + c.charCodeAt(0) + ';';
106
+ });
107
+ }
108
+
109
+ });
110
+
@@ -1 +1 @@
1
- var search_data = {"index":{"searchIndex":["object","wwwjdic","parsableducktype","parser","parsers","dict","display","key","search","server","splitter","utils","downloader","downloader","raisers","wwwjdic","breener()","content()","dictionary()","dictionary=()","download_file()","json_translate()","json_uri()","lines()","load_yaml_file()","message()","new()","new()","new()","parse()","parse()","parse()","parse()","parse()","parse()","parser()","raiser_array()","raiser_downcase()","raiser_to_i()","raw_uri()","reset()","server()","server=()","test_parsable_duck_type()","title()","to_s()","translate()","translation()","uri()","changelog","copying","gemfile","readme","rakefile","copyright"],"longSearchIndex":["object","wwwjdic","wwwjdic::parsableducktype","wwwjdic::parser","wwwjdic::parsers","wwwjdic::parsers::dict","wwwjdic::parsers::display","wwwjdic::parsers::key","wwwjdic::parsers::search","wwwjdic::parsers::server","wwwjdic::splitter","wwwjdic::utils","wwwjdic::utils::downloader","wwwjdic::utils::downloader::downloader","wwwjdic::utils::raisers","wwwjdic::wwwjdic","wwwjdic::breener()","wwwjdic::splitter#content()","wwwjdic::wwwjdic#dictionary()","wwwjdic::wwwjdic#dictionary=()","wwwjdic::utils::downloader::downloader::download_file()","wwwjdic::wwwjdic#json_translate()","wwwjdic::wwwjdic#json_uri()","wwwjdic::splitter#lines()","object#load_yaml_file()","wwwjdic::splitter#message()","wwwjdic::parser::new()","wwwjdic::splitter::new()","wwwjdic::wwwjdic::new()","wwwjdic::parser#parse()","wwwjdic::parsers::dict#parse()","wwwjdic::parsers::display#parse()","wwwjdic::parsers::key#parse()","wwwjdic::parsers::search#parse()","wwwjdic::parsers::server#parse()","wwwjdic::parser()","wwwjdic::utils::raisers#raiser_array()","wwwjdic::utils::raisers#raiser_downcase()","wwwjdic::utils::raisers#raiser_to_i()","wwwjdic::wwwjdic#raw_uri()","wwwjdic::wwwjdic#reset()","wwwjdic::wwwjdic#server()","wwwjdic::wwwjdic#server=()","wwwjdic::parsableducktype#test_parsable_duck_type()","wwwjdic::splitter#title()","wwwjdic::wwwjdic#to_s()","wwwjdic::wwwjdic#translate()","wwwjdic::splitter#translation()","wwwjdic::wwwjdic#uri()","","","","","",""],"info":[["Object","","Object.html","",""],["WWWJDic","","WWWJDic.html","","<p>Author &mdash; Marco Bresciani\n<p>Copyright &mdash; (C) 2014 Marco Bresciani\n<p>License &mdash; GNU General Public License version 3 …\n"],["WWWJDic::ParsableDuckType","","WWWJDic/ParsableDuckType.html","","<p>This module represents the parsable duck type element for testing purposes.\n<p>Author &mdash; Marco Bresciani\n<p>Copyright … &mdash; "],["WWWJDic::Parser","","WWWJDic/Parser.html","","<p>This class is a simple utility that is used to parse and filter parameters for wwwjdic.\n<p>Author &mdash; Marco Bresciani …\n"],["WWWJDic::Parsers","","WWWJDic/Parsers.html","",""],["WWWJDic::Parsers::Dict","","WWWJDic/Parsers/Dict.html","","<p>This class is an implementation of the Parsable duck type that checks the dictionary type. The only needed …\n"],["WWWJDic::Parsers::Display","","WWWJDic/Parsers/Display.html","","<p>This class is an implementation of the Parsable duck type that checks the display type. The only needed …\n"],["WWWJDic::Parsers::Key","","WWWJDic/Parsers/Key.html","","<p>This class is an implementation of the Parsable duck type that checks the display type. The only needed …\n"],["WWWJDic::Parsers::Search","","WWWJDic/Parsers/Search.html","","<p>This class is an implementation of the Parsable duck type that checks the display type. The only needed …\n"],["WWWJDic::Parsers::Server","","WWWJDic/Parsers/Server.html","","<p>This class is an implementation of the Parsable duck type that checks the display type. The only needed …\n"],["WWWJDic::Splitter","","WWWJDic/Splitter.html","","<p>This class is a simple API to interact with WWWJDic Backboor Entry/API.\n<p>Author &mdash; Marco Bresciani\n<p>Copyright … &mdash; "],["WWWJDic::Utils","","WWWJDic/Utils.html","","<p>This module is a simple collection of useful things and methods that I prefer to keep as DRYer as possible. …\n"],["WWWJDic::Utils::Downloader","","WWWJDic/Utils/Downloader.html","","<p>This module is a simple wrapper container for Peter R. Marreck&#39;s gist.\n<p>Author &mdash; Jon Maken\n<p>License &mdash; 3-clause …\n"],["WWWJDic::Utils::Downloader::Downloader","","WWWJDic/Utils/Downloader/Downloader.html","","<p>An HTTP/HTTPS/FTP file downloader library/CLI based upon MiniPortile&#39;s HTTP implementation.\n<p>Author … &mdash; "],["WWWJDic::Utils::Raisers","","WWWJDic/Utils/Raisers.html","","<p>This module contains some utility method to raise errors according to (possibly) common conditions.\n<p>Author … &mdash; "],["WWWJDic::WWWJDic","","WWWJDic/WWWJDic.html","","<p>This class is a simple API to interact with WWWJDic Backboor Entry/API.\n<p>Author &mdash; Marco Bresciani\n<p>Copyright … &mdash; "],["breener","WWWJDic","WWWJDic.html#method-c-breener","()","<p>Creates a new WWWJDic object (from the verb &#39;to Breen&#39;… :) ).\n<p>Usage &mdash; <p><code>new_wwwjdic = WWWJDic::breener</code> …\n\n"],["content","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-content","()","<p>@return [Array] the arrays of elements containing the answer\n"],["dictionary","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-dictionary","()","<p>Return the default used dictionary string, if any.\n<p>Returns &mdash; a String with the dictionary full name.\n\n"],["dictionary=","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-dictionary-3D","(dict)","<p>Configure the default used dictionary using either code/number or (exact) string.\n<p>Usage &mdash; &lt;tt&gt;new_wwwjdic.dictionary= …\n"],["download_file","WWWJDic::Utils::Downloader::Downloader","WWWJDic/Utils/Downloader/Downloader.html#method-c-download_file","(url, full_path, count = 3)",""],["json_translate","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-json_translate","(word = nil, args = {}, filename = nil)","<p>Save a file, with specified <code>filename</code>, that contains the current wwwjdic configuration, in JSON format. …\n"],["json_uri","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-json_uri","(word = nil, args = {})","<p>Create the reference uri for a <code>word</code> translation, according to specified parameters, with JSON output. …\n"],["lines","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-lines","()",""],["load_yaml_file","Object","Object.html#method-i-load_yaml_file","(locale)",""],["message","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-message","()",""],["new","WWWJDic::Parser","WWWJDic/Parser.html#method-c-new","(args = {})",""],["new","WWWJDic::Splitter","WWWJDic/Splitter.html#method-c-new","(translation)","<p>Creates a <code>Splitter</code> object.\n<p>Usage &mdash; <code>new_splitter = Splitter.new translation_content</code>\n<p>Returns &mdash; a <code>Splitter</code> object. …\n"],["new","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-c-new","(parser)","<p>Creates a <code>WWWJDic</code> object. This constructor should be used through the WWWJDic::breener method only.\n<p>Usage … &mdash; "],["parse","WWWJDic::Parser","WWWJDic/Parser.html#method-i-parse","(method = nil, value = nil)","<p>Provides the duck type for a generic parsing object.\n"],["parse","WWWJDic::Parsers::Dict","WWWJDic/Parsers/Dict.html#method-i-parse","(value = '1')","<p>The parsable duck type interface to every parser usage.\n"],["parse","WWWJDic::Parsers::Display","WWWJDic/Parsers/Display.html#method-i-parse","(value = :display)","<p>The parsable duck type interface to every parser usage.\n"],["parse","WWWJDic::Parsers::Key","WWWJDic/Parsers/Key.html#method-i-parse","(value = :english)","<p>The parsable duck type interface to every parser usage.\n"],["parse","WWWJDic::Parsers::Search","WWWJDic/Parsers/Search.html#method-i-parse","(value = '')","<p>The parsable duck type interface to every parser usage.\n"],["parse","WWWJDic::Parsers::Server","WWWJDic/Parsers/Server.html#method-i-parse","(value = :edrdg)","<p>The parsable duck type interface to every parser usage.\n"],["parser","WWWJDic","WWWJDic.html#method-c-parser","()","<p>Provides the parameters&#39; parsers object.\n"],["raiser_array","WWWJDic::Utils::Raisers","WWWJDic/Utils/Raisers.html#method-i-raiser_array","(name = 'error.value', value = nil, array = nil)","<p>Raises an <code>ArgumentError</code> according to parameters, unless the <code>array</code> contains the exact <code>value</code>.\n"],["raiser_downcase","WWWJDic::Utils::Raisers","WWWJDic/Utils/Raisers.html#method-i-raiser_downcase","(name = 'error.value', value = nil, array = nil)","<p>Raises an <code>ArgumentError</code> according to parameters, unless the <code>array</code> contains a downcased <code>value</code>.\n"],["raiser_to_i","WWWJDic::Utils::Raisers","WWWJDic/Utils/Raisers.html#method-i-raiser_to_i","(name = 'error.value', value = nil, array = nil)","<p>Raises an <code>ArgumentError</code> according to parameters, unless the <code>array</code> contains the number of the <code>value</code>.\n"],["raw_uri","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-raw_uri","(word = nil, args = {})","<p>Create the reference uri for a <code>word</code> translation, according to specified parameters, overriding for raw …\n"],["reset","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-reset","()","<p>Restores the original status cleaning up the (possibly) previously saved URIs restoring the default …\n"],["server","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-server","()","<p>Return the selected server URI\n<p>Returns &mdash; a String with the dictionary full name.\n\n"],["server=","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-server-3D","(server = :edrdg)","<p>Store the Backdoor Entry/API server name, default to EDRDG.Org (:edrdg) instead of Monash (:monash). …\n"],["test_parsable_duck_type","WWWJDic::ParsableDuckType","WWWJDic/ParsableDuckType.html#method-i-test_parsable_duck_type","()","<p>The method that tests the parsable duck type interface and its <code>parse</code> method.\n"],["title","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-title","()",""],["to_s","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-to_s","()",""],["translate","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-translate","(word = nil, args = {}, filename = nil)","<p>Save a file, with specified <code>filename</code>, that contains the current wwwjdic configuration. Uses the internal …\n"],["translation","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-translation","()",""],["uri","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-uri","(word = nil, args = {})","<p>Create the reference uri for a <code>word</code> translation, according to specified parameters.\n<p>Usage &mdash; &lt;tt&gt;new_wwwjdic.uri …\n\n"],["CHANGELOG","","CHANGELOG.html","","<p>Version 15.0.0\n\n<pre>* MAJOR changed key search type default from &quot;exact&quot; to &quot;english&quot;.\n* MAJOR changed Monash ...</pre>\n"],["COPYING","","COPYING_md.html","","<p>GNU GENERAL PUBLIC LICENSE\n<p>Version 3, 29 June 2007\n<p>Copyright (C) 2007 Free Software Foundation, Inc.\nfsf.org ...\n"],["Gemfile","","Gemfile.html","","<p># wwwjdic # © 2014 Marco Bresciani # # This file is part of wwwjdic. # # wwwjdic is free software: you …\n"],["README","","README_md.html","","<p>WWWJDic\n<p><img src=\"https://badgen.net/rubygems/n/wwwjdic\">\n<img src=\"https://badgen.net/rubygems/p/wwwjdic\"> ...\n"],["Rakefile","","Rakefile.html","","<p># wwwjdic # © 2014 Marco Bresciani # # This file is part of wwwjdic. # # wwwjdic is free software: you …\n"],["copyright","","copyright_md.html","","<p>Copyright Notes\n<p>2020-11-10 update.\n<p>wwwjdic\n"]]}}
1
+ var search_data = {"index":{"searchIndex":["object","wwwjdic","parsableducktype","parser","parsers","dict","display","key","search","server","splitter","utils","downloader","downloader","raisers","wwwjdic","breener()","content()","dictionary()","dictionary=()","download_file()","json_translate()","json_uri()","lines()","load_yaml_file()","message()","new()","new()","new()","parse()","parse()","parse()","parse()","parse()","parse()","parser()","raiser_array()","raiser_downcase()","raiser_to_i()","raw_uri()","reset()","server()","server=()","test_ask_translation()","test_ask_uri()","test_dictionary_code()","test_dictionary_name()","test_en_it()","test_get_dictionary()","test_get_translation()","test_invalid_param()","test_invalid_parameter()","test_invalid_server()","test_multilanguage()","test_multiple_languages()","test_no_raise()","test_one_locale()","test_override_custom_params()","test_parsable_duck_type()","test_raise()","test_raise_error_param()","test_raise_invalid_server_error()","test_raiser()","test_return_json()","test_return_test_reference()","test_select_server()","test_server()","test_translation()","test_wrong_code()","test_wrong_name()","title()","to_s()","translate()","translation()","uri()","changelog","copying","gemfile","readme","rakefile","copyright"],"longSearchIndex":["object","wwwjdic","wwwjdic::parsableducktype","wwwjdic::parser","wwwjdic::parsers","wwwjdic::parsers::dict","wwwjdic::parsers::display","wwwjdic::parsers::key","wwwjdic::parsers::search","wwwjdic::parsers::server","wwwjdic::splitter","wwwjdic::utils","wwwjdic::utils::downloader","wwwjdic::utils::downloader::downloader","wwwjdic::utils::raisers","wwwjdic::wwwjdic","wwwjdic::breener()","wwwjdic::splitter#content()","wwwjdic::wwwjdic#dictionary()","wwwjdic::wwwjdic#dictionary=()","wwwjdic::utils::downloader::downloader::download_file()","wwwjdic::wwwjdic#json_translate()","wwwjdic::wwwjdic#json_uri()","wwwjdic::splitter#lines()","object#load_yaml_file()","wwwjdic::splitter#message()","wwwjdic::parser::new()","wwwjdic::splitter::new()","wwwjdic::wwwjdic::new()","wwwjdic::parser#parse()","wwwjdic::parsers::dict#parse()","wwwjdic::parsers::display#parse()","wwwjdic::parsers::key#parse()","wwwjdic::parsers::search#parse()","wwwjdic::parsers::server#parse()","wwwjdic::parser()","wwwjdic::utils::raisers#raiser_array()","wwwjdic::utils::raisers#raiser_downcase()","wwwjdic::utils::raisers#raiser_to_i()","wwwjdic::wwwjdic#raw_uri()","wwwjdic::wwwjdic#reset()","wwwjdic::wwwjdic#server()","wwwjdic::wwwjdic#server=()","object#test_ask_translation()","object#test_ask_uri()","object#test_dictionary_code()","object#test_dictionary_name()","object#test_en_it()","object#test_get_dictionary()","object#test_get_translation()","object#test_invalid_param()","object#test_invalid_parameter()","object#test_invalid_server()","object#test_multilanguage()","object#test_multiple_languages()","object#test_no_raise()","object#test_one_locale()","object#test_override_custom_params()","wwwjdic::parsableducktype#test_parsable_duck_type()","object#test_raise()","object#test_raise_error_param()","object#test_raise_invalid_server_error()","object#test_raiser()","object#test_return_json()","object#test_return_test_reference()","object#test_select_server()","object#test_server()","object#test_translation()","object#test_wrong_code()","object#test_wrong_name()","wwwjdic::splitter#title()","wwwjdic::wwwjdic#to_s()","wwwjdic::wwwjdic#translate()","wwwjdic::splitter#translation()","wwwjdic::wwwjdic#uri()","","","","","",""],"info":[["Object","","Object.html","",""],["WWWJDic","","WWWJDic.html","","<p>Author &mdash; Marco Bresciani\n<p>Copyright &mdash; (C) 2014 Marco Bresciani\n<p>License &mdash; GNU General Public License version 3 …\n"],["WWWJDic::ParsableDuckType","","WWWJDic/ParsableDuckType.html","","<p>This module represents the parsable duck type element for testing purposes.\n<p>Author &mdash; Marco Bresciani\n<p>Copyright … &mdash; "],["WWWJDic::Parser","","WWWJDic/Parser.html","","<p>This class is a simple utility that is used to parse and filter parameters for wwwjdic.\n<p>Author &mdash; Marco Bresciani …\n"],["WWWJDic::Parsers","","WWWJDic/Parsers.html","",""],["WWWJDic::Parsers::Dict","","WWWJDic/Parsers/Dict.html","","<p>This class is an implementation of the Parsable duck type that checks the dictionary type. The only needed …\n"],["WWWJDic::Parsers::Display","","WWWJDic/Parsers/Display.html","","<p>This class is an implementation of the Parsable duck type that checks the display type. The only needed …\n"],["WWWJDic::Parsers::Key","","WWWJDic/Parsers/Key.html","","<p>This class is an implementation of the Parsable duck type that checks the display type. The only needed …\n"],["WWWJDic::Parsers::Search","","WWWJDic/Parsers/Search.html","","<p>This class is an implementation of the Parsable duck type that checks the display type. The only needed …\n"],["WWWJDic::Parsers::Server","","WWWJDic/Parsers/Server.html","","<p>This class is an implementation of the Parsable duck type that checks the display type. The only needed …\n"],["WWWJDic::Splitter","","WWWJDic/Splitter.html","","<p>This class is a simple API to interact with WWWJDic Backboor Entry/API.\n<p>Author &mdash; Marco Bresciani\n<p>Copyright … &mdash; "],["WWWJDic::Utils","","WWWJDic/Utils.html","","<p>This module is a simple collection of useful things and methods that I prefer to keep as DRYer as possible. …\n"],["WWWJDic::Utils::Downloader","","WWWJDic/Utils/Downloader.html","","<p>This module is a simple wrapper container for Peter R. Marreck&#39;s gist.\n<p>Author &mdash; Jon Maken\n<p>License &mdash; 3-clause …\n"],["WWWJDic::Utils::Downloader::Downloader","","WWWJDic/Utils/Downloader/Downloader.html","","<p>An HTTP/HTTPS/FTP file downloader library/CLI based upon MiniPortile&#39;s HTTP implementation.\n<p>Author … &mdash; "],["WWWJDic::Utils::Raisers","","WWWJDic/Utils/Raisers.html","","<p>This module contains some utility method to raise errors according to (possibly) common conditions.\n<p>Author … &mdash; "],["WWWJDic::WWWJDic","","WWWJDic/WWWJDic.html","","<p>This class is a simple API to interact with WWWJDic Backboor Entry/API.\n<p>Author &mdash; Marco Bresciani\n<p>Copyright … &mdash; "],["breener","WWWJDic","WWWJDic.html#method-c-breener","()","<p>Creates a new WWWJDic object (from the verb &#39;to Breen&#39;… :) ).\n<p>Usage &mdash; <p><code>new_wwwjdic = WWWJDic::breener</code> …\n\n"],["content","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-content","()","<p>@return [Array] the arrays of elements containing the answer\n"],["dictionary","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-dictionary","()","<p>Return the default used dictionary string, if any.\n<p>Returns &mdash; a String with the dictionary full name.\n\n"],["dictionary=","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-dictionary-3D","(dict)","<p>Configure the default used dictionary using either code/number or (exact) string.\n<p>Usage &mdash; &lt;tt&gt;new_wwwjdic.dictionary= …\n"],["download_file","WWWJDic::Utils::Downloader::Downloader","WWWJDic/Utils/Downloader/Downloader.html#method-c-download_file","(url, full_path, count = 3)",""],["json_translate","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-json_translate","(word = nil, args = {}, filename = nil)","<p>Save a file, with specified <code>filename</code>, that contains the current wwwjdic configuration, in JSON format. …\n"],["json_uri","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-json_uri","(word = nil, args = {})","<p>Create the reference uri for a <code>word</code> translation, according to specified parameters, with JSON output. …\n"],["lines","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-lines","()",""],["load_yaml_file","Object","Object.html#method-i-load_yaml_file","(locale)",""],["message","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-message","()",""],["new","WWWJDic::Parser","WWWJDic/Parser.html#method-c-new","(args = {})",""],["new","WWWJDic::Splitter","WWWJDic/Splitter.html#method-c-new","(translation)","<p>Creates a <code>Splitter</code> object.\n<p>Usage &mdash; <code>new_splitter = Splitter.new translation_content</code>\n<p>Returns &mdash; a <code>Splitter</code> object. …\n"],["new","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-c-new","(parser)","<p>Creates a <code>WWWJDic</code> object. This constructor should be used through the WWWJDic::breener method only.\n<p>Usage … &mdash; "],["parse","WWWJDic::Parser","WWWJDic/Parser.html#method-i-parse","(method = nil, params = nil)","<p>Provides the duck type for a generic parsing object.\n"],["parse","WWWJDic::Parsers::Dict","WWWJDic/Parsers/Dict.html#method-i-parse","(value = '1')","<p>The parsable duck type interface to every parser usage.\n"],["parse","WWWJDic::Parsers::Display","WWWJDic/Parsers/Display.html#method-i-parse","(value = :display)","<p>The parsable duck type interface to every parser usage.\n"],["parse","WWWJDic::Parsers::Key","WWWJDic/Parsers/Key.html#method-i-parse","(value = :english)","<p>The parsable duck type interface to every parser usage.\n"],["parse","WWWJDic::Parsers::Search","WWWJDic/Parsers/Search.html#method-i-parse","(value = '')","<p>The parsable duck type interface to every parser usage.\n"],["parse","WWWJDic::Parsers::Server","WWWJDic/Parsers/Server.html#method-i-parse","(value = :edrdg)","<p>The parsable duck type interface to every parser usage.\n"],["parser","WWWJDic","WWWJDic.html#method-c-parser","()","<p>Provides the parameters&#39; parsers object.\n"],["raiser_array","WWWJDic::Utils::Raisers","WWWJDic/Utils/Raisers.html#method-i-raiser_array","(name = 'error.value', value = nil, array = nil)","<p>Raises an <code>ArgumentError</code> according to parameters, unless the <code>array</code> contains the exact <code>value</code>.\n"],["raiser_downcase","WWWJDic::Utils::Raisers","WWWJDic/Utils/Raisers.html#method-i-raiser_downcase","(name = 'error.value', value = nil, array = nil)","<p>Raises an <code>ArgumentError</code> according to parameters, unless the <code>array</code> contains a downcased <code>value</code>.\n"],["raiser_to_i","WWWJDic::Utils::Raisers","WWWJDic/Utils/Raisers.html#method-i-raiser_to_i","(name = 'error.value', value = nil, array = nil)","<p>Raises an <code>ArgumentError</code> according to parameters, unless the <code>array</code> contains the number of the <code>value</code>.\n"],["raw_uri","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-raw_uri","(word = nil, args = {})","<p>Create the reference uri for a <code>word</code> translation, according to specified parameters, overriding for raw …\n"],["reset","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-reset","()","<p>Restores the original status cleaning up the (possibly) previously saved URIs restoring the default …\n"],["server","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-server","()","<p>Return the selected server URI\n<p>Returns &mdash; a String with the dictionary full name.\n\n"],["server=","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-server-3D","(server = :edrdg)","<p>Store the Backdoor Entry/API server name, default to EDRDG.Org (:edrdg) instead of Monash (:monash). …\n"],["test_ask_translation","Object","Object.html#method-i-test_ask_translation","()",""],["test_ask_uri","Object","Object.html#method-i-test_ask_uri","()",""],["test_dictionary_code","Object","Object.html#method-i-test_dictionary_code","()",""],["test_dictionary_name","Object","Object.html#method-i-test_dictionary_name","()",""],["test_en_it","Object","Object.html#method-i-test_en_it","()",""],["test_get_dictionary","Object","Object.html#method-i-test_get_dictionary","()",""],["test_get_translation","Object","Object.html#method-i-test_get_translation","()",""],["test_invalid_param","Object","Object.html#method-i-test_invalid_param","()",""],["test_invalid_parameter","Object","Object.html#method-i-test_invalid_parameter","(a_word)",""],["test_invalid_server","Object","Object.html#method-i-test_invalid_server","()",""],["test_multilanguage","Object","Object.html#method-i-test_multilanguage","(a_method)",""],["test_multiple_languages","Object","Object.html#method-i-test_multiple_languages","()",""],["test_no_raise","Object","Object.html#method-i-test_no_raise","()",""],["test_one_locale","Object","Object.html#method-i-test_one_locale","()",""],["test_override_custom_params","Object","Object.html#method-i-test_override_custom_params","(a_word, dict)",""],["test_parsable_duck_type","WWWJDic::ParsableDuckType","WWWJDic/ParsableDuckType.html#method-i-test_parsable_duck_type","()","<p>The method that tests the parsable duck type interface and its <code>parse</code> method.\n"],["test_raise","Object","Object.html#method-i-test_raise","()",""],["test_raise_error_param","Object","Object.html#method-i-test_raise_error_param","(param)",""],["test_raise_invalid_server_error","Object","Object.html#method-i-test_raise_invalid_server_error","(a_server)",""],["test_raiser","Object","Object.html#method-i-test_raiser","()",""],["test_return_json","Object","Object.html#method-i-test_return_json","(a_word, dict)",""],["test_return_test_reference","Object","Object.html#method-i-test_return_test_reference","()",""],["test_select_server","Object","Object.html#method-i-test_select_server","()",""],["test_server","Object","Object.html#method-i-test_server","()",""],["test_translation","Object","Object.html#method-i-test_translation","(locale, translation)",""],["test_wrong_code","Object","Object.html#method-i-test_wrong_code","()",""],["test_wrong_name","Object","Object.html#method-i-test_wrong_name","()",""],["title","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-title","()",""],["to_s","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-to_s","()",""],["translate","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-translate","(word = nil, args = {}, filename = nil)","<p>Save a file, with specified <code>filename</code>, that contains the current wwwjdic configuration. Uses the internal …\n"],["translation","WWWJDic::Splitter","WWWJDic/Splitter.html#method-i-translation","()",""],["uri","WWWJDic::WWWJDic","WWWJDic/WWWJDic.html#method-i-uri","(word = nil, args = {})","<p>Create the reference uri for a <code>word</code> translation, according to specified parameters.\n<p>Usage &mdash; &lt;tt&gt;new_wwwjdic.uri …\n\n"],["CHANGELOG","","CHANGELOG.html","","<p>Version 16.0.0\n\n<pre>* MAJOR update from Ruby &#39;~&gt; 2.7&#39; to Ruby &#39;~&gt; 3.0&#39;.\n* MINOR update IntelliJ IDEA (RubyGem) ...</pre>\n"],["COPYING","","COPYING_md.html","","<p>GNU GENERAL PUBLIC LICENSE\n<p>Version 3, 29 June 2007\n<p>Copyright (C) 2007 Free Software Foundation, Inc.\nfsf.org ...\n"],["Gemfile","","Gemfile.html","","<p># frozen_string_literal: true\n<p># wwwjdic # rubocop:disable Style/AsciiComments # © 2014 Marco Bresciani …\n"],["README","","README_md.html","","<p>WWWJDic\n<p><img src=\"https://badgen.net/rubygems/n/wwwjdic\">\n<img src=\"https://badgen.net/rubygems/v/wwwjdic/latest\"> ...\n"],["Rakefile","","Rakefile.html","","<p># frozen_string_literal: true\n<p># wwwjdic # rubocop:disable Style/AsciiComments # © 2014 Marco Bresciani …\n"],["copyright","","copyright_md.html","","<p>Copyright Notes\n<p>2020-11-10 update.\n<p>wwwjdic\n"]]}}
Binary file
data/html/js/searcher.js CHANGED
@@ -1,229 +1,229 @@
1
- Searcher = function(data) {
2
- this.data = data;
3
- this.handlers = [];
4
- }
5
-
6
- Searcher.prototype = new function() {
7
- // search is performed in chunks of 1000 for non-blocking user input
8
- var CHUNK_SIZE = 1000;
9
- // do not try to find more than 100 results
10
- var MAX_RESULTS = 100;
11
- var huid = 1;
12
- var suid = 1;
13
- var runs = 0;
14
-
15
- this.find = function(query) {
16
- var queries = splitQuery(query);
17
- var regexps = buildRegexps(queries);
18
- var highlighters = buildHilighters(queries);
19
- var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
20
- var _this = this;
21
-
22
- this.currentSuid = state.n;
23
-
24
- if (!query) return;
25
-
26
- var run = function() {
27
- // stop current search thread if new search started
28
- if (state.n != _this.currentSuid) return;
29
-
30
- var results =
31
- performSearch(_this.data, regexps, queries, highlighters, state);
32
- var hasMore = (state.limit > 0 && state.pass < 4);
33
-
34
- triggerResults.call(_this, results, !hasMore);
35
- if (hasMore) {
36
- setTimeout(run, 2);
37
- }
38
- runs++;
39
- };
40
- runs = 0;
41
-
42
- // start search thread
43
- run();
44
- }
45
-
46
- /* ----- Events ------ */
47
- this.ready = function(fn) {
48
- fn.huid = huid;
49
- this.handlers.push(fn);
50
- }
51
-
52
- /* ----- Utilities ------ */
53
- function splitQuery(query) {
54
- return query.split(/(\s+|::?|\(\)?)/).filter(function(string) {
55
- return string.match(/\S/);
56
- });
57
- }
58
-
59
- function buildRegexps(queries) {
60
- return queries.map(function(query) {
61
- return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i');
62
- });
63
- }
64
-
65
- function buildHilighters(queries) {
66
- return queries.map(function(query) {
67
- return query.split('').map(function(l, i) {
68
- return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
69
- }).join('');
70
- });
71
- }
72
-
73
- // function longMatchRegexp(index, longIndex, regexps) {
74
- // for (var i = regexps.length - 1; i >= 0; i--){
75
- // if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
76
- // };
77
- // return true;
78
- // }
79
-
80
-
81
- /* ----- Mathchers ------ */
82
-
83
- /*
84
- * This record matches if the index starts with queries[0] and the record
85
- * matches all of the regexps
86
- */
87
- function matchPassBeginning(index, longIndex, queries, regexps) {
88
- if (index.indexOf(queries[0]) != 0) return false;
89
- for (var i=1, l = regexps.length; i < l; i++) {
90
- if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
91
- return false;
92
- }
93
- return true;
94
- }
95
-
96
- /*
97
- * This record matches if the longIndex starts with queries[0] and the
98
- * longIndex matches all of the regexps
99
- */
100
- function matchPassLongIndex(index, longIndex, queries, regexps) {
101
- if (longIndex.indexOf(queries[0]) != 0) return false;
102
- for (var i=1, l = regexps.length; i < l; i++) {
103
- if (!longIndex.match(regexps[i]))
104
- return false;
105
- }
106
- return true;
107
- }
108
-
109
- /*
110
- * This record matches if the index contains queries[0] and the record
111
- * matches all of the regexps
112
- */
113
- function matchPassContains(index, longIndex, queries, regexps) {
114
- if (index.indexOf(queries[0]) == -1) return false;
115
- for (var i=1, l = regexps.length; i < l; i++) {
116
- if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
117
- return false;
118
- }
119
- return true;
120
- }
121
-
122
- /*
123
- * This record matches if regexps[0] matches the index and the record
124
- * matches all of the regexps
125
- */
126
- function matchPassRegexp(index, longIndex, queries, regexps) {
127
- if (!index.match(regexps[0])) return false;
128
- for (var i=1, l = regexps.length; i < l; i++) {
129
- if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
130
- return false;
131
- }
132
- return true;
133
- }
134
-
135
-
136
- /* ----- Highlighters ------ */
137
- function highlightRegexp(info, queries, regexps, highlighters) {
138
- var result = createResult(info);
139
- for (var i=0, l = regexps.length; i < l; i++) {
140
- result.title = result.title.replace(regexps[i], highlighters[i]);
141
- result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
142
- }
143
- return result;
144
- }
145
-
146
- function hltSubstring(string, pos, length) {
147
- return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
148
- }
149
-
150
- function highlightQuery(info, queries, regexps, highlighters) {
151
- var result = createResult(info);
152
- var pos = 0;
153
- var lcTitle = result.title.toLowerCase();
154
-
155
- pos = lcTitle.indexOf(queries[0]);
156
- if (pos != -1) {
157
- result.title = hltSubstring(result.title, pos, queries[0].length);
158
- }
159
-
160
- result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
161
- for (var i=1, l = regexps.length; i < l; i++) {
162
- result.title = result.title.replace(regexps[i], highlighters[i]);
163
- result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
164
- }
165
- return result;
166
- }
167
-
168
- function createResult(info) {
169
- var result = {};
170
- result.title = info[0];
171
- result.namespace = info[1];
172
- result.path = info[2];
173
- result.params = info[3];
174
- result.snippet = info[4];
175
- result.badge = info[6];
176
- return result;
177
- }
178
-
179
- /* ----- Searching ------ */
180
- function performSearch(data, regexps, queries, highlighters, state) {
181
- var searchIndex = data.searchIndex;
182
- var longSearchIndex = data.longSearchIndex;
183
- var info = data.info;
184
- var result = [];
185
- var i = state.from;
186
- var l = searchIndex.length;
187
- var togo = CHUNK_SIZE;
188
- var matchFunc, hltFunc;
189
-
190
- while (state.pass < 4 && state.limit > 0 && togo > 0) {
191
- if (state.pass == 0) {
192
- matchFunc = matchPassBeginning;
193
- hltFunc = highlightQuery;
194
- } else if (state.pass == 1) {
195
- matchFunc = matchPassLongIndex;
196
- hltFunc = highlightQuery;
197
- } else if (state.pass == 2) {
198
- matchFunc = matchPassContains;
199
- hltFunc = highlightQuery;
200
- } else if (state.pass == 3) {
201
- matchFunc = matchPassRegexp;
202
- hltFunc = highlightRegexp;
203
- }
204
-
205
- for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
206
- if (info[i].n == state.n) continue;
207
- if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
208
- info[i].n = state.n;
209
- result.push(hltFunc(info[i], queries, regexps, highlighters));
210
- state.limit--;
211
- }
212
- }
213
- if (searchIndex.length <= i) {
214
- state.pass++;
215
- i = state.from = 0;
216
- } else {
217
- state.from = i;
218
- }
219
- }
220
- return result;
221
- }
222
-
223
- function triggerResults(results, isLast) {
224
- this.handlers.forEach(function(fn) {
225
- fn.call(this, results, isLast)
226
- });
227
- }
228
- }
229
-
1
+ Searcher = function(data) {
2
+ this.data = data;
3
+ this.handlers = [];
4
+ }
5
+
6
+ Searcher.prototype = new function() {
7
+ // search is performed in chunks of 1000 for non-blocking user input
8
+ var CHUNK_SIZE = 1000;
9
+ // do not try to find more than 100 results
10
+ var MAX_RESULTS = 100;
11
+ var huid = 1;
12
+ var suid = 1;
13
+ var runs = 0;
14
+
15
+ this.find = function(query) {
16
+ var queries = splitQuery(query);
17
+ var regexps = buildRegexps(queries);
18
+ var highlighters = buildHilighters(queries);
19
+ var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
20
+ var _this = this;
21
+
22
+ this.currentSuid = state.n;
23
+
24
+ if (!query) return;
25
+
26
+ var run = function() {
27
+ // stop current search thread if new search started
28
+ if (state.n != _this.currentSuid) return;
29
+
30
+ var results =
31
+ performSearch(_this.data, regexps, queries, highlighters, state);
32
+ var hasMore = (state.limit > 0 && state.pass < 4);
33
+
34
+ triggerResults.call(_this, results, !hasMore);
35
+ if (hasMore) {
36
+ setTimeout(run, 2);
37
+ }
38
+ runs++;
39
+ };
40
+ runs = 0;
41
+
42
+ // start search thread
43
+ run();
44
+ }
45
+
46
+ /* ----- Events ------ */
47
+ this.ready = function(fn) {
48
+ fn.huid = huid;
49
+ this.handlers.push(fn);
50
+ }
51
+
52
+ /* ----- Utilities ------ */
53
+ function splitQuery(query) {
54
+ return query.split(/(\s+|::?|\(\)?)/).filter(function(string) {
55
+ return string.match(/\S/);
56
+ });
57
+ }
58
+
59
+ function buildRegexps(queries) {
60
+ return queries.map(function(query) {
61
+ return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i');
62
+ });
63
+ }
64
+
65
+ function buildHilighters(queries) {
66
+ return queries.map(function(query) {
67
+ return query.split('').map(function(l, i) {
68
+ return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
69
+ }).join('');
70
+ });
71
+ }
72
+
73
+ // function longMatchRegexp(index, longIndex, regexps) {
74
+ // for (var i = regexps.length - 1; i >= 0; i--){
75
+ // if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
76
+ // };
77
+ // return true;
78
+ // }
79
+
80
+
81
+ /* ----- Mathchers ------ */
82
+
83
+ /*
84
+ * This record matches if the index starts with queries[0] and the record
85
+ * matches all of the regexps
86
+ */
87
+ function matchPassBeginning(index, longIndex, queries, regexps) {
88
+ if (index.indexOf(queries[0]) != 0) return false;
89
+ for (var i=1, l = regexps.length; i < l; i++) {
90
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
91
+ return false;
92
+ };
93
+ return true;
94
+ }
95
+
96
+ /*
97
+ * This record matches if the longIndex starts with queries[0] and the
98
+ * longIndex matches all of the regexps
99
+ */
100
+ function matchPassLongIndex(index, longIndex, queries, regexps) {
101
+ if (longIndex.indexOf(queries[0]) != 0) return false;
102
+ for (var i=1, l = regexps.length; i < l; i++) {
103
+ if (!longIndex.match(regexps[i]))
104
+ return false;
105
+ };
106
+ return true;
107
+ }
108
+
109
+ /*
110
+ * This record matches if the index contains queries[0] and the record
111
+ * matches all of the regexps
112
+ */
113
+ function matchPassContains(index, longIndex, queries, regexps) {
114
+ if (index.indexOf(queries[0]) == -1) return false;
115
+ for (var i=1, l = regexps.length; i < l; i++) {
116
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
117
+ return false;
118
+ };
119
+ return true;
120
+ }
121
+
122
+ /*
123
+ * This record matches if regexps[0] matches the index and the record
124
+ * matches all of the regexps
125
+ */
126
+ function matchPassRegexp(index, longIndex, queries, regexps) {
127
+ if (!index.match(regexps[0])) return false;
128
+ for (var i=1, l = regexps.length; i < l; i++) {
129
+ if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
130
+ return false;
131
+ };
132
+ return true;
133
+ }
134
+
135
+
136
+ /* ----- Highlighters ------ */
137
+ function highlightRegexp(info, queries, regexps, highlighters) {
138
+ var result = createResult(info);
139
+ for (var i=0, l = regexps.length; i < l; i++) {
140
+ result.title = result.title.replace(regexps[i], highlighters[i]);
141
+ result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
142
+ };
143
+ return result;
144
+ }
145
+
146
+ function hltSubstring(string, pos, length) {
147
+ return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
148
+ }
149
+
150
+ function highlightQuery(info, queries, regexps, highlighters) {
151
+ var result = createResult(info);
152
+ var pos = 0;
153
+ var lcTitle = result.title.toLowerCase();
154
+
155
+ pos = lcTitle.indexOf(queries[0]);
156
+ if (pos != -1) {
157
+ result.title = hltSubstring(result.title, pos, queries[0].length);
158
+ }
159
+
160
+ result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
161
+ for (var i=1, l = regexps.length; i < l; i++) {
162
+ result.title = result.title.replace(regexps[i], highlighters[i]);
163
+ result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
164
+ };
165
+ return result;
166
+ }
167
+
168
+ function createResult(info) {
169
+ var result = {};
170
+ result.title = info[0];
171
+ result.namespace = info[1];
172
+ result.path = info[2];
173
+ result.params = info[3];
174
+ result.snippet = info[4];
175
+ result.badge = info[6];
176
+ return result;
177
+ }
178
+
179
+ /* ----- Searching ------ */
180
+ function performSearch(data, regexps, queries, highlighters, state) {
181
+ var searchIndex = data.searchIndex;
182
+ var longSearchIndex = data.longSearchIndex;
183
+ var info = data.info;
184
+ var result = [];
185
+ var i = state.from;
186
+ var l = searchIndex.length;
187
+ var togo = CHUNK_SIZE;
188
+ var matchFunc, hltFunc;
189
+
190
+ while (state.pass < 4 && state.limit > 0 && togo > 0) {
191
+ if (state.pass == 0) {
192
+ matchFunc = matchPassBeginning;
193
+ hltFunc = highlightQuery;
194
+ } else if (state.pass == 1) {
195
+ matchFunc = matchPassLongIndex;
196
+ hltFunc = highlightQuery;
197
+ } else if (state.pass == 2) {
198
+ matchFunc = matchPassContains;
199
+ hltFunc = highlightQuery;
200
+ } else if (state.pass == 3) {
201
+ matchFunc = matchPassRegexp;
202
+ hltFunc = highlightRegexp;
203
+ }
204
+
205
+ for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
206
+ if (info[i].n == state.n) continue;
207
+ if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
208
+ info[i].n = state.n;
209
+ result.push(hltFunc(info[i], queries, regexps, highlighters));
210
+ state.limit--;
211
+ }
212
+ };
213
+ if (searchIndex.length <= i) {
214
+ state.pass++;
215
+ i = state.from = 0;
216
+ } else {
217
+ state.from = i;
218
+ }
219
+ }
220
+ return result;
221
+ }
222
+
223
+ function triggerResults(results, isLast) {
224
+ this.handlers.forEach(function(fn) {
225
+ fn.call(this, results, isLast)
226
+ });
227
+ }
228
+ }
229
+