From ac406bdbf0d4b275ed8d1c48e29d0cb69e4d1800 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 23 May 2017 20:54:03 -0700 Subject: add debug info checkbox --- ext/bg/js/options.js | 2 ++ ext/bg/js/util.js | 1 + 2 files changed, 3 insertions(+) (limited to 'ext/bg/js') diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 1ea6ed68..1b675da2 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -30,6 +30,7 @@ function formRead() { optionsNew.general.audioVolume = $('#audio-playback-volume').val(); optionsNew.general.groupResults = $('#group-terms-results').prop('checked'); optionsNew.general.softKatakana = $('#soft-katakana-search').prop('checked'); + optionsNew.general.debugInfo = $('#show-debug-info').prop('checked'); optionsNew.general.showAdvanced = $('#show-advanced-options').prop('checked'); optionsNew.general.maxResults = parseInt($('#max-displayed-results').val(), 10); optionsNew.general.popupWidth = parseInt($('#popup-width').val(), 10); @@ -118,6 +119,7 @@ $(document).ready(() => { $('#audio-playback-volume').val(options.general.audioVolume); $('#group-terms-results').prop('checked', options.general.groupResults); $('#soft-katakana-search').prop('checked', options.general.softKatakana); + $('#show-debug-info').prop('checked', options.general.debugInfo); $('#show-advanced-options').prop('checked', options.general.showAdvanced); $('#max-displayed-results').val(options.general.maxResults); $('#popup-width').val(options.general.popupWidth); diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 09337c63..74e1f49e 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -99,6 +99,7 @@ function optionsSetDefaults(options) { audioVolume: 100, groupResults: true, softKatakana: true, + debugInfo: false, maxResults: 32, showAdvanced: false, popupWidth: 400, -- cgit v1.2.3 From 5de9ac17122002fa8727fd089679394f54af442f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 23 May 2017 21:27:20 -0700 Subject: add debug logging --- ext/bg/js/templates.js | 62 +++++++++++++++++++++++++++++++++++-------------- ext/bg/js/util.js | 6 +++++ ext/bg/options.html | 2 +- ext/mixed/js/display.js | 6 +++-- tmpl/kanji.html | 6 ++++- tmpl/terms.html | 6 ++++- 6 files changed, 65 insertions(+), 23 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index d093b177..d2e5435e 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -328,7 +328,9 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " \n\n
\n" + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.program(15, data, 0),"data":data})) != null ? stack1 : "") - + "
\n\n"; + + " \n\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n"; },"2":function(container,depth0,helpers,partials,data) { return " \n"; },"4":function(container,depth0,helpers,partials,data) { @@ -378,25 +380,36 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia var stack1; return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0)); -},"18":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"18":function(container,depth0,helpers,partials,data) { + var stack1, helper, options, buffer = + "
";
+  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper));
+  if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
+  if (stack1 != null) { buffer += stack1; }
+  return buffer + "
\n"; +},"19":function(container,depth0,helpers,partials,data) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(19, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"19":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); +},"21":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.first),{"name":"unless","hash":{},"fn":container.program(20, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(22, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"22":function(container,depth0,helpers,partials,data,blockParams,depths) { + var stack1; + + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.first),{"name":"unless","hash":{},"fn":container.program(23, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" - + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"20":function(container,depth0,helpers,partials,data) { + + ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); +},"23":function(container,depth0,helpers,partials,data) { return "
"; -},"22":function(container,depth0,helpers,partials,data) { +},"25":function(container,depth0,helpers,partials,data) { return "

No results found.

\n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0, blockParams, depths),"inverse":container.program(22, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(21, data, 0, blockParams, depths),"inverse":container.program(25, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; @@ -482,7 +495,9 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reasons : depth0),{"name":"if","hash":{},"fn":container.program(22, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n
\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.grouped : depth0),{"name":"if","hash":{},"fn":container.program(26, data, 0),"inverse":container.program(32, data, 0),"data":data})) != null ? stack1 : "") - + "
\n\n"; + + " \n\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n"; },"13":function(container,depth0,helpers,partials,data) { return " \n \n"; },"15":function(container,depth0,helpers,partials,data) { @@ -547,25 +562,36 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia var stack1; return ((stack1 = container.invokePartial(partials.definition,depth0,{"name":"definition","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"34":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"34":function(container,depth0,helpers,partials,data) { + var stack1, helper, options, buffer = + "
";
+  stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(35, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper));
+  if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
+  if (stack1 != null) { buffer += stack1; }
+  return buffer + "
\n"; +},"35":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : ""); +},"37":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(35, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"35":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(38, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"38":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.first),{"name":"unless","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.first),{"name":"unless","hash":{},"fn":container.program(39, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" - + ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"36":function(container,depth0,helpers,partials,data) { + + ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); +},"39":function(container,depth0,helpers,partials,data) { return "
"; -},"38":function(container,depth0,helpers,partials,data) { +},"41":function(container,depth0,helpers,partials,data) { return "

No results found.

\n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0, blockParams, depths),"inverse":container.program(38, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(37, data, 0, blockParams, depths),"inverse":container.program(41, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 74e1f49e..64c79ab5 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -504,6 +504,11 @@ function jsonLoadDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { * Helpers */ +function handlebarsDumpObject(options) { + const dump = JSON.stringify(options.fn(this), null, 4); + return Handlebars.Utils.escapeExpression(dump); +} + function handlebarsKanjiLinks(options) { let result = ''; for (const c of options.fn(this)) { @@ -523,6 +528,7 @@ function handlebarsMultiLine(options) { function handlebarsRegister() { Handlebars.partials = Handlebars.templates; + Handlebars.registerHelper('dumpObject', handlebarsDumpObject); Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks); Handlebars.registerHelper('multiLine', handlebarsMultiLine); } diff --git a/ext/bg/options.html b/ext/bg/options.html index 97dcd736..434241e3 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -50,7 +50,7 @@ diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 0167c605..7982c69f 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -69,7 +69,8 @@ class Display { definitions, addable: options.anki.enable, grouped: options.general.groupResults, - playback: options.general.audioSource !== 'disabled' + playback: options.general.audioSource !== 'disabled', + debug: options.general.debugInfo }; if (context) { @@ -106,7 +107,8 @@ class Display { const params = { definitions, source: context && context.source, - addable: options.anki.enable + addable: options.anki.enable, + debug: options.general.debugInfo }; if (context) { diff --git a/tmpl/kanji.html b/tmpl/kanji.html index acd79036..a2f78aff 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -50,13 +50,17 @@
{{#multiLine}}{{glossary.[0]}}{{/multiLine}}
{{/if}} + + {{#if debug}} +
{{#dumpObject}}{{{.}}}{{/dumpObject}}
+ {{/if}} {{/inline}} {{#if definitions}} {{#each definitions}} {{#unless @first}}
{{/unless}} -{{> kanji addable=../addable source=../source root=../root}} +{{> kanji debug=../debug addable=../addable source=../source root=../root}} {{/each}} {{else}}

No results found.

diff --git a/tmpl/terms.html b/tmpl/terms.html index dc50efe2..80735974 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -59,13 +59,17 @@ {{> definition}} {{/if}} + + {{#if debug}} +
{{#dumpObject}}{{{.}}}{{/dumpObject}}
+ {{/if}} {{/inline}} {{#if definitions}} {{#each definitions}} {{#unless @first}}
{{/unless}} -{{> term grouped=../grouped addable=../addable playback=../playback}} +{{> term debug=../debug grouped=../grouped addable=../addable playback=../playback}} {{/each}} {{else}}

No results found.

-- cgit v1.2.3 From 0efab9773d0cc6586eb4a1f271821795b6d07f5c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 24 May 2017 19:13:56 -0700 Subject: options debugging code --- ext/bg/js/options.js | 9 +++++++++ ext/bg/js/util.js | 6 +++++- ext/bg/options.html | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 1b675da2..4eafd9ef 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -86,6 +86,15 @@ function updateVisibility(options) { } else { advanced.hide(); } + + const debug = $('#debug'); + if (options.general.debugInfo) { + const text = JSON.stringify(options, null, 4); + debug.html(handlebarsEscape(text)); + debug.show(); + } else { + debug.hide(); + } } function onOptionsChanged(e) { diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 64c79ab5..593e7d03 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -504,9 +504,13 @@ function jsonLoadDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { * Helpers */ +function handlebarsEscape(text) { + return Handlebars.Utils.escapeExpression(text); +} + function handlebarsDumpObject(options) { const dump = JSON.stringify(options.fn(this), null, 4); - return Handlebars.Utils.escapeExpression(dump); + return handlebarsEscape(dump); } function handlebarsKanjiLinks(options) { diff --git a/ext/bg/options.html b/ext/bg/options.html index 434241e3..8281c317 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -8,6 +8,7 @@