From b11fcfb7cfda6edce542970f72c45f0b737a389c Mon Sep 17 00:00:00 2001 From: abap34 Date: Sun, 3 Mar 2024 01:34:11 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=A8=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E3=81=A7=E3=81=8D=E3=82=8B=E5=A0=B4=E5=90=88=20pyodid?= =?UTF-8?q?e=20=E3=81=AE=E3=83=AD=E3=83=BC=E3=83=89=E3=82=92=E3=82=B9?= =?UTF-8?q?=E3=82=AD=E3=83=83=E3=83=97=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast.hpp | 16 ++++++++++++++++ src/template.html | 3 --- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/ast.hpp b/src/ast.hpp index f71438c..26a4e84 100644 --- a/src/ast.hpp +++ b/src/ast.hpp @@ -14,6 +14,11 @@ namespace almo { // - syntax_theme: Highlight.jsのテーマ std::map meta_data; + // レスポンス時間短縮のため、pyodideが不要なら読み込みをスキップするためのフラグ. + bool loaded_pyodide = false; + + std::string pyodide_loader = ""; + // 各ノードに対して一意なIDを生成する用の関数オブジェクト. 呼ぶと前に呼ばれた時の値 + 1 が返る. struct UUID_gen { std::string operator()() { @@ -386,6 +391,7 @@ namespace almo { // Highlight.js によって正確にハイライトするために、 にクラスを付与する。 std::string to_html() const override { + loaded_pyodide = true; return "
" + code + "
"; } @@ -552,6 +558,11 @@ namespace almo { std::string output = title_h3 + editor_div + ace_editor + sample_in_area + sample_out_area + expect_out_area + define_data + test_run_button + submit_button + judge_code; + if (!loaded_pyodide) { + output = pyodide_loader + output; + loaded_pyodide = true; + } + return output; } @@ -613,6 +624,11 @@ namespace almo { std::string output = editor_div + ace_editor + out_area + plot_area + run_button; + if (!loaded_pyodide) { + output = pyodide_loader + output; + loaded_pyodide = true; + } + return output; } diff --git a/src/template.html b/src/template.html index ea1d251..7c53992 100644 --- a/src/template.html +++ b/src/template.html @@ -30,8 +30,6 @@ - - @@ -40,7 +38,6 @@ - {{style}} From b1276cc8fd7eb9cdc97d8f030d11043f172a4c80 Mon Sep 17 00:00:00 2001 From: abap34 Date: Sun, 3 Mar 2024 01:42:06 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E5=A0=B4?= =?UTF-8?q?=E5=90=88,=20runner=20=E8=87=AA=E4=BD=93=E3=81=8C=E5=9F=8B?= =?UTF-8?q?=E3=82=81=E8=BE=BC=E3=81=BE=E3=82=8C=E3=81=AA=E3=81=84=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast.hpp | 11 ++--------- src/render.hpp | 8 ++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ast.hpp b/src/ast.hpp index 26a4e84..84cadd9 100644 --- a/src/ast.hpp +++ b/src/ast.hpp @@ -391,7 +391,6 @@ namespace almo { // Highlight.js によって正確にハイライトするために、 にクラスを付与する。 std::string to_html() const override { - loaded_pyodide = true; return "
" + code + "
"; } @@ -558,10 +557,7 @@ namespace almo { std::string output = title_h3 + editor_div + ace_editor + sample_in_area + sample_out_area + expect_out_area + define_data + test_run_button + submit_button + judge_code; - if (!loaded_pyodide) { - output = pyodide_loader + output; - loaded_pyodide = true; - } + loaded_pyodide = true; return output; } @@ -624,10 +620,7 @@ namespace almo { std::string output = editor_div + ace_editor + out_area + plot_area + run_button; - if (!loaded_pyodide) { - output = pyodide_loader + output; - loaded_pyodide = true; - } + loaded_pyodide = true; return output; } diff --git a/src/render.hpp b/src/render.hpp index f0609d8..25be649 100644 --- a/src/render.hpp +++ b/src/render.hpp @@ -60,6 +60,14 @@ namespace almo { } std::string runner = ""; + + if (loaded_pyodide) { + // runnner の先頭に  pyodide を挿入 + runner = pyodide_loader + runner; + } else { + runner = ""; + } + std::string sidebar_builder = ""; // runner を挿入 From 64a4acb35444ed55039f1078d872d4b71b4b3b72 Mon Sep 17 00:00:00 2001 From: abap34 Date: Sun, 3 Mar 2024 01:47:38 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3?= =?UTF-8?q?=E3=83=84=E3=81=AE=E5=8F=8E=E9=9B=86=E3=82=82=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=A6=E3=81=97=E3=81=BE=E3=81=A3=E3=81=9F?= =?UTF-8?q?=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/runner.js | 4 +--- src/template.html | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/runner.js b/src/runner.js index 4389652..57da4cd 100644 --- a/src/runner.js +++ b/src/runner.js @@ -1,5 +1,4 @@ - - + all_sample_input = {} all_sample_output = {} @@ -11,7 +10,6 @@ use_libs = [] judge_types = {} problem_status = {} -page_contents = [] const pyodidePromise = loadPyodide({ stdin: stdin_func, diff --git a/src/template.html b/src/template.html index 7c53992..8a32572 100644 --- a/src/template.html +++ b/src/template.html @@ -42,6 +42,10 @@ {{style}} + + {{runner}} From c2934720d16682f7e7adc29ff27ac656a315d59d Mon Sep 17 00:00:00 2001 From: abap34 Date: Sun, 3 Mar 2024 01:47:58 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E3=82=B9=E3=82=AD=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=9D=E3=82=8C?= =?UTF-8?q?=E3=81=8C=E3=83=86=E3=83=B3=E3=83=97=E3=83=AC=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=81=AB=E6=98=8E=E7=A4=BA=E7=9A=84=E3=81=AB=E5=9F=8B=E3=82=81?= =?UTF-8?q?=E8=BE=BC=E3=81=BE=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/render.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/render.hpp b/src/render.hpp index 25be649..049c0ea 100644 --- a/src/render.hpp +++ b/src/render.hpp @@ -65,7 +65,7 @@ namespace almo { // runnner の先頭に  pyodide を挿入 runner = pyodide_loader + runner; } else { - runner = ""; + runner = ""; } std::string sidebar_builder = ""; @@ -96,11 +96,10 @@ namespace almo { } std::string render(Block ast, std::map meta_data) { - - std::string html_template = load_html_template(meta_data["template_file"], meta_data["css_setting"]); - std::string content = ast.render(); - + + std::string html_template = load_html_template(meta_data["template_file"], meta_data["css_setting"]); + std::string output_html = replace_template(html_template, meta_data, content); return output_html;