diff --git a/totrans/bd-sgl-pg-webapp-mtr_00.yaml b/data/bd-sgl-pg-webapp-mtr_00.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_00.yaml rename to data/bd-sgl-pg-webapp-mtr_00.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_01.yaml b/data/bd-sgl-pg-webapp-mtr_01.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_01.yaml rename to data/bd-sgl-pg-webapp-mtr_01.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_02.yaml b/data/bd-sgl-pg-webapp-mtr_02.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_02.yaml rename to data/bd-sgl-pg-webapp-mtr_02.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_03.yaml b/data/bd-sgl-pg-webapp-mtr_03.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_03.yaml rename to data/bd-sgl-pg-webapp-mtr_03.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_04.yaml b/data/bd-sgl-pg-webapp-mtr_04.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_04.yaml rename to data/bd-sgl-pg-webapp-mtr_04.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_05.yaml b/data/bd-sgl-pg-webapp-mtr_05.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_05.yaml rename to data/bd-sgl-pg-webapp-mtr_05.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_06.yaml b/data/bd-sgl-pg-webapp-mtr_06.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_06.yaml rename to data/bd-sgl-pg-webapp-mtr_06.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_07.yaml b/data/bd-sgl-pg-webapp-mtr_07.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_07.yaml rename to data/bd-sgl-pg-webapp-mtr_07.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_08.yaml b/data/bd-sgl-pg-webapp-mtr_08.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_08.yaml rename to data/bd-sgl-pg-webapp-mtr_08.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_09.yaml b/data/bd-sgl-pg-webapp-mtr_09.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_09.yaml rename to data/bd-sgl-pg-webapp-mtr_09.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_10.yaml b/data/bd-sgl-pg-webapp-mtr_10.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_10.yaml rename to data/bd-sgl-pg-webapp-mtr_10.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_11.yaml b/data/bd-sgl-pg-webapp-mtr_11.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_11.yaml rename to data/bd-sgl-pg-webapp-mtr_11.yaml diff --git a/totrans/bd-sgl-pg-webapp-mtr_12.yaml b/data/bd-sgl-pg-webapp-mtr_12.yaml similarity index 100% rename from totrans/bd-sgl-pg-webapp-mtr_12.yaml rename to data/bd-sgl-pg-webapp-mtr_12.yaml diff --git a/totrans/deno-web-dev_00.yaml b/data/deno-web-dev_00.yaml similarity index 100% rename from totrans/deno-web-dev_00.yaml rename to data/deno-web-dev_00.yaml diff --git a/totrans/deno-web-dev_01.yaml b/data/deno-web-dev_01.yaml similarity index 100% rename from totrans/deno-web-dev_01.yaml rename to data/deno-web-dev_01.yaml diff --git a/totrans/deno-web-dev_02.yaml b/data/deno-web-dev_02.yaml similarity index 100% rename from totrans/deno-web-dev_02.yaml rename to data/deno-web-dev_02.yaml diff --git a/totrans/deno-web-dev_03.yaml b/data/deno-web-dev_03.yaml similarity index 100% rename from totrans/deno-web-dev_03.yaml rename to data/deno-web-dev_03.yaml diff --git a/totrans/deno-web-dev_04.yaml b/data/deno-web-dev_04.yaml similarity index 100% rename from totrans/deno-web-dev_04.yaml rename to data/deno-web-dev_04.yaml diff --git a/totrans/deno-web-dev_05.yaml b/data/deno-web-dev_05.yaml similarity index 100% rename from totrans/deno-web-dev_05.yaml rename to data/deno-web-dev_05.yaml diff --git a/totrans/deno-web-dev_06.yaml b/data/deno-web-dev_06.yaml similarity index 100% rename from totrans/deno-web-dev_06.yaml rename to data/deno-web-dev_06.yaml diff --git a/totrans/deno-web-dev_07.yaml b/data/deno-web-dev_07.yaml similarity index 100% rename from totrans/deno-web-dev_07.yaml rename to data/deno-web-dev_07.yaml diff --git a/totrans/deno-web-dev_08.yaml b/data/deno-web-dev_08.yaml similarity index 100% rename from totrans/deno-web-dev_08.yaml rename to data/deno-web-dev_08.yaml diff --git a/totrans/deno-web-dev_09.yaml b/data/deno-web-dev_09.yaml similarity index 100% rename from totrans/deno-web-dev_09.yaml rename to data/deno-web-dev_09.yaml diff --git a/totrans/deno-web-dev_10.yaml b/data/deno-web-dev_10.yaml similarity index 100% rename from totrans/deno-web-dev_10.yaml rename to data/deno-web-dev_10.yaml diff --git a/totrans/dev-win-store-app-h5-js_00.yaml b/data/dev-win-store-app-h5-js_00.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_00.yaml rename to data/dev-win-store-app-h5-js_00.yaml diff --git a/totrans/dev-win-store-app-h5-js_01.yaml b/data/dev-win-store-app-h5-js_01.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_01.yaml rename to data/dev-win-store-app-h5-js_01.yaml diff --git a/totrans/dev-win-store-app-h5-js_02.yaml b/data/dev-win-store-app-h5-js_02.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_02.yaml rename to data/dev-win-store-app-h5-js_02.yaml diff --git a/totrans/dev-win-store-app-h5-js_03.yaml b/data/dev-win-store-app-h5-js_03.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_03.yaml rename to data/dev-win-store-app-h5-js_03.yaml diff --git a/totrans/dev-win-store-app-h5-js_04.yaml b/data/dev-win-store-app-h5-js_04.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_04.yaml rename to data/dev-win-store-app-h5-js_04.yaml diff --git a/totrans/dev-win-store-app-h5-js_05.yaml b/data/dev-win-store-app-h5-js_05.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_05.yaml rename to data/dev-win-store-app-h5-js_05.yaml diff --git a/totrans/dev-win-store-app-h5-js_06.yaml b/data/dev-win-store-app-h5-js_06.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_06.yaml rename to data/dev-win-store-app-h5-js_06.yaml diff --git a/totrans/dev-win-store-app-h5-js_07.yaml b/data/dev-win-store-app-h5-js_07.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_07.yaml rename to data/dev-win-store-app-h5-js_07.yaml diff --git a/totrans/dev-win-store-app-h5-js_08.yaml b/data/dev-win-store-app-h5-js_08.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_08.yaml rename to data/dev-win-store-app-h5-js_08.yaml diff --git a/totrans/dev-win-store-app-h5-js_09.yaml b/data/dev-win-store-app-h5-js_09.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_09.yaml rename to data/dev-win-store-app-h5-js_09.yaml diff --git a/totrans/dev-win-store-app-h5-js_10.yaml b/data/dev-win-store-app-h5-js_10.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_10.yaml rename to data/dev-win-store-app-h5-js_10.yaml diff --git a/totrans/dev-win-store-app-h5-js_11.yaml b/data/dev-win-store-app-h5-js_11.yaml similarity index 100% rename from totrans/dev-win-store-app-h5-js_11.yaml rename to data/dev-win-store-app-h5-js_11.yaml diff --git a/totrans/gt-mtr-js-fw_0.yaml b/data/gt-mtr-js-fw_0.yaml similarity index 100% rename from totrans/gt-mtr-js-fw_0.yaml rename to data/gt-mtr-js-fw_0.yaml diff --git a/totrans/gt-mtr-js-fw_1.yaml b/data/gt-mtr-js-fw_1.yaml similarity index 100% rename from totrans/gt-mtr-js-fw_1.yaml rename to data/gt-mtr-js-fw_1.yaml diff --git a/totrans/gt-mtr-js-fw_2.yaml b/data/gt-mtr-js-fw_2.yaml similarity index 100% rename from totrans/gt-mtr-js-fw_2.yaml rename to data/gt-mtr-js-fw_2.yaml diff --git a/totrans/gt-mtr-js-fw_3.yaml b/data/gt-mtr-js-fw_3.yaml similarity index 100% rename from totrans/gt-mtr-js-fw_3.yaml rename to data/gt-mtr-js-fw_3.yaml diff --git a/totrans/gt-mtr-js-fw_4.yaml b/data/gt-mtr-js-fw_4.yaml similarity index 100% rename from totrans/gt-mtr-js-fw_4.yaml rename to data/gt-mtr-js-fw_4.yaml diff --git a/totrans/gt-mtr-js-fw_5.yaml b/data/gt-mtr-js-fw_5.yaml similarity index 100% rename from totrans/gt-mtr-js-fw_5.yaml rename to data/gt-mtr-js-fw_5.yaml diff --git a/totrans/gt-mtr-js-fw_6.yaml b/data/gt-mtr-js-fw_6.yaml similarity index 100% rename from totrans/gt-mtr-js-fw_6.yaml rename to data/gt-mtr-js-fw_6.yaml diff --git a/totrans/gt-mtr-js-fw_7.yaml b/data/gt-mtr-js-fw_7.yaml similarity index 100% rename from totrans/gt-mtr-js-fw_7.yaml rename to data/gt-mtr-js-fw_7.yaml diff --git a/totrans/ins-test-qunit_0.yaml b/data/ins-test-qunit_0.yaml similarity index 100% rename from totrans/ins-test-qunit_0.yaml rename to data/ins-test-qunit_0.yaml diff --git a/totrans/ins-test-qunit_1.yaml b/data/ins-test-qunit_1.yaml similarity index 100% rename from totrans/ins-test-qunit_1.yaml rename to data/ins-test-qunit_1.yaml diff --git a/totrans/js-dnet-dev_00.yaml b/data/js-dnet-dev_00.yaml similarity index 100% rename from totrans/js-dnet-dev_00.yaml rename to data/js-dnet-dev_00.yaml diff --git a/totrans/js-dnet-dev_01.yaml b/data/js-dnet-dev_01.yaml similarity index 100% rename from totrans/js-dnet-dev_01.yaml rename to data/js-dnet-dev_01.yaml diff --git a/totrans/js-dnet-dev_02.yaml b/data/js-dnet-dev_02.yaml similarity index 100% rename from totrans/js-dnet-dev_02.yaml rename to data/js-dnet-dev_02.yaml diff --git a/totrans/js-dnet-dev_03.yaml b/data/js-dnet-dev_03.yaml similarity index 100% rename from totrans/js-dnet-dev_03.yaml rename to data/js-dnet-dev_03.yaml diff --git a/totrans/js-dnet-dev_04.yaml b/data/js-dnet-dev_04.yaml similarity index 100% rename from totrans/js-dnet-dev_04.yaml rename to data/js-dnet-dev_04.yaml diff --git a/totrans/js-dnet-dev_05.yaml b/data/js-dnet-dev_05.yaml similarity index 100% rename from totrans/js-dnet-dev_05.yaml rename to data/js-dnet-dev_05.yaml diff --git a/totrans/js-dnet-dev_06.yaml b/data/js-dnet-dev_06.yaml similarity index 100% rename from totrans/js-dnet-dev_06.yaml rename to data/js-dnet-dev_06.yaml diff --git a/totrans/js-dnet-dev_07.yaml b/data/js-dnet-dev_07.yaml similarity index 100% rename from totrans/js-dnet-dev_07.yaml rename to data/js-dnet-dev_07.yaml diff --git a/totrans/js-dnet-dev_08.yaml b/data/js-dnet-dev_08.yaml similarity index 100% rename from totrans/js-dnet-dev_08.yaml rename to data/js-dnet-dev_08.yaml diff --git a/totrans/js-dnet-dev_09.yaml b/data/js-dnet-dev_09.yaml similarity index 100% rename from totrans/js-dnet-dev_09.yaml rename to data/js-dnet-dev_09.yaml diff --git a/totrans/js-dnet-dev_10.yaml b/data/js-dnet-dev_10.yaml similarity index 100% rename from totrans/js-dnet-dev_10.yaml rename to data/js-dnet-dev_10.yaml diff --git a/totrans/js-json-cb_00.yaml b/data/js-json-cb_00.yaml similarity index 100% rename from totrans/js-json-cb_00.yaml rename to data/js-json-cb_00.yaml diff --git a/totrans/js-json-cb_01.yaml b/data/js-json-cb_01.yaml similarity index 100% rename from totrans/js-json-cb_01.yaml rename to data/js-json-cb_01.yaml diff --git a/totrans/js-json-cb_02.yaml b/data/js-json-cb_02.yaml similarity index 100% rename from totrans/js-json-cb_02.yaml rename to data/js-json-cb_02.yaml diff --git a/totrans/js-json-cb_03.yaml b/data/js-json-cb_03.yaml similarity index 100% rename from totrans/js-json-cb_03.yaml rename to data/js-json-cb_03.yaml diff --git a/totrans/js-json-cb_04.yaml b/data/js-json-cb_04.yaml similarity index 100% rename from totrans/js-json-cb_04.yaml rename to data/js-json-cb_04.yaml diff --git a/totrans/js-json-cb_05.yaml b/data/js-json-cb_05.yaml similarity index 100% rename from totrans/js-json-cb_05.yaml rename to data/js-json-cb_05.yaml diff --git a/totrans/js-json-cb_06.yaml b/data/js-json-cb_06.yaml similarity index 100% rename from totrans/js-json-cb_06.yaml rename to data/js-json-cb_06.yaml diff --git a/totrans/js-json-cb_07.yaml b/data/js-json-cb_07.yaml similarity index 100% rename from totrans/js-json-cb_07.yaml rename to data/js-json-cb_07.yaml diff --git a/totrans/js-json-cb_08.yaml b/data/js-json-cb_08.yaml similarity index 100% rename from totrans/js-json-cb_08.yaml rename to data/js-json-cb_08.yaml diff --git a/totrans/js-json-cb_09.yaml b/data/js-json-cb_09.yaml similarity index 100% rename from totrans/js-json-cb_09.yaml rename to data/js-json-cb_09.yaml diff --git a/totrans/js-json-cb_10.yaml b/data/js-json-cb_10.yaml similarity index 100% rename from totrans/js-json-cb_10.yaml rename to data/js-json-cb_10.yaml diff --git a/totrans/js-prms-ess_0.yaml b/data/js-prms-ess_0.yaml similarity index 100% rename from totrans/js-prms-ess_0.yaml rename to data/js-prms-ess_0.yaml diff --git a/totrans/js-prms-ess_1.yaml b/data/js-prms-ess_1.yaml similarity index 100% rename from totrans/js-prms-ess_1.yaml rename to data/js-prms-ess_1.yaml diff --git a/totrans/js-prms-ess_2.yaml b/data/js-prms-ess_2.yaml similarity index 100% rename from totrans/js-prms-ess_2.yaml rename to data/js-prms-ess_2.yaml diff --git a/totrans/js-prms-ess_3.yaml b/data/js-prms-ess_3.yaml similarity index 100% rename from totrans/js-prms-ess_3.yaml rename to data/js-prms-ess_3.yaml diff --git a/totrans/js-prms-ess_4.yaml b/data/js-prms-ess_4.yaml similarity index 100% rename from totrans/js-prms-ess_4.yaml rename to data/js-prms-ess_4.yaml diff --git a/totrans/js-prms-ess_5.yaml b/data/js-prms-ess_5.yaml similarity index 100% rename from totrans/js-prms-ess_5.yaml rename to data/js-prms-ess_5.yaml diff --git a/totrans/js-prms-ess_6.yaml b/data/js-prms-ess_6.yaml similarity index 100% rename from totrans/js-prms-ess_6.yaml rename to data/js-prms-ess_6.yaml diff --git a/totrans/js-scl_00.yaml b/data/js-scl_00.yaml similarity index 100% rename from totrans/js-scl_00.yaml rename to data/js-scl_00.yaml diff --git a/totrans/js-scl_01.yaml b/data/js-scl_01.yaml similarity index 100% rename from totrans/js-scl_01.yaml rename to data/js-scl_01.yaml diff --git a/totrans/js-scl_02.yaml b/data/js-scl_02.yaml similarity index 100% rename from totrans/js-scl_02.yaml rename to data/js-scl_02.yaml diff --git a/totrans/js-scl_03.yaml b/data/js-scl_03.yaml similarity index 100% rename from totrans/js-scl_03.yaml rename to data/js-scl_03.yaml diff --git a/totrans/js-scl_04.yaml b/data/js-scl_04.yaml similarity index 100% rename from totrans/js-scl_04.yaml rename to data/js-scl_04.yaml diff --git a/totrans/js-scl_05.yaml b/data/js-scl_05.yaml similarity index 100% rename from totrans/js-scl_05.yaml rename to data/js-scl_05.yaml diff --git a/totrans/js-scl_06.yaml b/data/js-scl_06.yaml similarity index 100% rename from totrans/js-scl_06.yaml rename to data/js-scl_06.yaml diff --git a/totrans/js-scl_07.yaml b/data/js-scl_07.yaml similarity index 100% rename from totrans/js-scl_07.yaml rename to data/js-scl_07.yaml diff --git a/totrans/js-scl_08.yaml b/data/js-scl_08.yaml similarity index 100% rename from totrans/js-scl_08.yaml rename to data/js-scl_08.yaml diff --git a/totrans/js-scl_09.yaml b/data/js-scl_09.yaml similarity index 100% rename from totrans/js-scl_09.yaml rename to data/js-scl_09.yaml diff --git a/totrans/js-scl_10.yaml b/data/js-scl_10.yaml similarity index 100% rename from totrans/js-scl_10.yaml rename to data/js-scl_10.yaml diff --git a/totrans/js-test-bgd_0.yaml b/data/js-test-bgd_0.yaml similarity index 100% rename from totrans/js-test-bgd_0.yaml rename to data/js-test-bgd_0.yaml diff --git a/totrans/js-test-bgd_1.yaml b/data/js-test-bgd_1.yaml similarity index 100% rename from totrans/js-test-bgd_1.yaml rename to data/js-test-bgd_1.yaml diff --git a/totrans/js-test-bgd_2.yaml b/data/js-test-bgd_2.yaml similarity index 100% rename from totrans/js-test-bgd_2.yaml rename to data/js-test-bgd_2.yaml diff --git a/totrans/js-test-bgd_3.yaml b/data/js-test-bgd_3.yaml similarity index 100% rename from totrans/js-test-bgd_3.yaml rename to data/js-test-bgd_3.yaml diff --git a/totrans/js-test-bgd_4.yaml b/data/js-test-bgd_4.yaml similarity index 100% rename from totrans/js-test-bgd_4.yaml rename to data/js-test-bgd_4.yaml diff --git a/totrans/js-test-bgd_5.yaml b/data/js-test-bgd_5.yaml similarity index 100% rename from totrans/js-test-bgd_5.yaml rename to data/js-test-bgd_5.yaml diff --git a/totrans/js-test-bgd_6.yaml b/data/js-test-bgd_6.yaml similarity index 100% rename from totrans/js-test-bgd_6.yaml rename to data/js-test-bgd_6.yaml diff --git a/totrans/js-test-bgd_7.yaml b/data/js-test-bgd_7.yaml similarity index 100% rename from totrans/js-test-bgd_7.yaml rename to data/js-test-bgd_7.yaml diff --git a/totrans/js-test-bgd_8.yaml b/data/js-test-bgd_8.yaml similarity index 100% rename from totrans/js-test-bgd_8.yaml rename to data/js-test-bgd_8.yaml diff --git a/totrans/js-ulk_00.yaml b/data/js-ulk_00.yaml similarity index 100% rename from totrans/js-ulk_00.yaml rename to data/js-ulk_00.yaml diff --git a/totrans/js-ulk_01.yaml b/data/js-ulk_01.yaml similarity index 100% rename from totrans/js-ulk_01.yaml rename to data/js-ulk_01.yaml diff --git a/totrans/js-ulk_02.yaml b/data/js-ulk_02.yaml similarity index 100% rename from totrans/js-ulk_02.yaml rename to data/js-ulk_02.yaml diff --git a/totrans/js-ulk_03.yaml b/data/js-ulk_03.yaml similarity index 100% rename from totrans/js-ulk_03.yaml rename to data/js-ulk_03.yaml diff --git a/totrans/js-ulk_04.yaml b/data/js-ulk_04.yaml similarity index 100% rename from totrans/js-ulk_04.yaml rename to data/js-ulk_04.yaml diff --git a/totrans/js-ulk_05.yaml b/data/js-ulk_05.yaml similarity index 100% rename from totrans/js-ulk_05.yaml rename to data/js-ulk_05.yaml diff --git a/totrans/js-ulk_06.yaml b/data/js-ulk_06.yaml similarity index 100% rename from totrans/js-ulk_06.yaml rename to data/js-ulk_06.yaml diff --git a/totrans/js-ulk_07.yaml b/data/js-ulk_07.yaml similarity index 100% rename from totrans/js-ulk_07.yaml rename to data/js-ulk_07.yaml diff --git a/totrans/js-ulk_08.yaml b/data/js-ulk_08.yaml similarity index 100% rename from totrans/js-ulk_08.yaml rename to data/js-ulk_08.yaml diff --git a/totrans/js-ulk_09.yaml b/data/js-ulk_09.yaml similarity index 100% rename from totrans/js-ulk_09.yaml rename to data/js-ulk_09.yaml diff --git a/totrans/lrn-aurelia_00.yaml b/data/lrn-aurelia_00.yaml similarity index 100% rename from totrans/lrn-aurelia_00.yaml rename to data/lrn-aurelia_00.yaml diff --git a/totrans/lrn-aurelia_01.yaml b/data/lrn-aurelia_01.yaml similarity index 100% rename from totrans/lrn-aurelia_01.yaml rename to data/lrn-aurelia_01.yaml diff --git a/totrans/lrn-aurelia_02.yaml b/data/lrn-aurelia_02.yaml similarity index 100% rename from totrans/lrn-aurelia_02.yaml rename to data/lrn-aurelia_02.yaml diff --git a/totrans/lrn-aurelia_03.yaml b/data/lrn-aurelia_03.yaml similarity index 100% rename from totrans/lrn-aurelia_03.yaml rename to data/lrn-aurelia_03.yaml diff --git a/totrans/lrn-aurelia_04.yaml b/data/lrn-aurelia_04.yaml similarity index 100% rename from totrans/lrn-aurelia_04.yaml rename to data/lrn-aurelia_04.yaml diff --git a/totrans/lrn-aurelia_05.yaml b/data/lrn-aurelia_05.yaml similarity index 100% rename from totrans/lrn-aurelia_05.yaml rename to data/lrn-aurelia_05.yaml diff --git a/totrans/lrn-aurelia_06.yaml b/data/lrn-aurelia_06.yaml similarity index 100% rename from totrans/lrn-aurelia_06.yaml rename to data/lrn-aurelia_06.yaml diff --git a/totrans/lrn-aurelia_07.yaml b/data/lrn-aurelia_07.yaml similarity index 100% rename from totrans/lrn-aurelia_07.yaml rename to data/lrn-aurelia_07.yaml diff --git a/totrans/lrn-aurelia_08.yaml b/data/lrn-aurelia_08.yaml similarity index 100% rename from totrans/lrn-aurelia_08.yaml rename to data/lrn-aurelia_08.yaml diff --git a/totrans/lrn-aurelia_09.yaml b/data/lrn-aurelia_09.yaml similarity index 100% rename from totrans/lrn-aurelia_09.yaml rename to data/lrn-aurelia_09.yaml diff --git a/totrans/lrn-aurelia_10.yaml b/data/lrn-aurelia_10.yaml similarity index 100% rename from totrans/lrn-aurelia_10.yaml rename to data/lrn-aurelia_10.yaml diff --git a/totrans/lrn-aurelia_11.yaml b/data/lrn-aurelia_11.yaml similarity index 100% rename from totrans/lrn-aurelia_11.yaml rename to data/lrn-aurelia_11.yaml diff --git a/totrans/lrn-aurelia_12.yaml b/data/lrn-aurelia_12.yaml similarity index 100% rename from totrans/lrn-aurelia_12.yaml rename to data/lrn-aurelia_12.yaml diff --git a/totrans/lrn-aurelia_13.yaml b/data/lrn-aurelia_13.yaml similarity index 100% rename from totrans/lrn-aurelia_13.yaml rename to data/lrn-aurelia_13.yaml diff --git a/totrans/ms-js-hiperf_00.yaml b/data/ms-js-hiperf_00.yaml similarity index 100% rename from totrans/ms-js-hiperf_00.yaml rename to data/ms-js-hiperf_00.yaml diff --git a/totrans/ms-js-hiperf_01.yaml b/data/ms-js-hiperf_01.yaml similarity index 100% rename from totrans/ms-js-hiperf_01.yaml rename to data/ms-js-hiperf_01.yaml diff --git a/totrans/ms-js-hiperf_02.yaml b/data/ms-js-hiperf_02.yaml similarity index 100% rename from totrans/ms-js-hiperf_02.yaml rename to data/ms-js-hiperf_02.yaml diff --git a/totrans/ms-js-hiperf_03.yaml b/data/ms-js-hiperf_03.yaml similarity index 100% rename from totrans/ms-js-hiperf_03.yaml rename to data/ms-js-hiperf_03.yaml diff --git a/totrans/ms-js-hiperf_04.yaml b/data/ms-js-hiperf_04.yaml similarity index 100% rename from totrans/ms-js-hiperf_04.yaml rename to data/ms-js-hiperf_04.yaml diff --git a/totrans/ms-js-hiperf_05.yaml b/data/ms-js-hiperf_05.yaml similarity index 100% rename from totrans/ms-js-hiperf_05.yaml rename to data/ms-js-hiperf_05.yaml diff --git a/totrans/ms-js-hiperf_06.yaml b/data/ms-js-hiperf_06.yaml similarity index 100% rename from totrans/ms-js-hiperf_06.yaml rename to data/ms-js-hiperf_06.yaml diff --git a/totrans/ms-js-hiperf_07.yaml b/data/ms-js-hiperf_07.yaml similarity index 100% rename from totrans/ms-js-hiperf_07.yaml rename to data/ms-js-hiperf_07.yaml diff --git a/totrans/ms-js-hiperf_08.yaml b/data/ms-js-hiperf_08.yaml similarity index 100% rename from totrans/ms-js-hiperf_08.yaml rename to data/ms-js-hiperf_08.yaml diff --git a/totrans/ms-js-hiperf_09.yaml b/data/ms-js-hiperf_09.yaml similarity index 100% rename from totrans/ms-js-hiperf_09.yaml rename to data/ms-js-hiperf_09.yaml diff --git a/totrans/ms-js-hiperf_10.yaml b/data/ms-js-hiperf_10.yaml similarity index 100% rename from totrans/ms-js-hiperf_10.yaml rename to data/ms-js-hiperf_10.yaml diff --git a/totrans/ms-js-prms_00.yaml b/data/ms-js-prms_00.yaml similarity index 100% rename from totrans/ms-js-prms_00.yaml rename to data/ms-js-prms_00.yaml diff --git a/totrans/ms-js-prms_01.yaml b/data/ms-js-prms_01.yaml similarity index 100% rename from totrans/ms-js-prms_01.yaml rename to data/ms-js-prms_01.yaml diff --git a/totrans/ms-js-prms_02.yaml b/data/ms-js-prms_02.yaml similarity index 100% rename from totrans/ms-js-prms_02.yaml rename to data/ms-js-prms_02.yaml diff --git a/totrans/ms-js-prms_03.yaml b/data/ms-js-prms_03.yaml similarity index 100% rename from totrans/ms-js-prms_03.yaml rename to data/ms-js-prms_03.yaml diff --git a/totrans/ms-js-prms_04.yaml b/data/ms-js-prms_04.yaml similarity index 100% rename from totrans/ms-js-prms_04.yaml rename to data/ms-js-prms_04.yaml diff --git a/totrans/ms-js-prms_05.yaml b/data/ms-js-prms_05.yaml similarity index 100% rename from totrans/ms-js-prms_05.yaml rename to data/ms-js-prms_05.yaml diff --git a/totrans/ms-js-prms_06.yaml b/data/ms-js-prms_06.yaml similarity index 100% rename from totrans/ms-js-prms_06.yaml rename to data/ms-js-prms_06.yaml diff --git a/totrans/ms-js-prms_07.yaml b/data/ms-js-prms_07.yaml similarity index 100% rename from totrans/ms-js-prms_07.yaml rename to data/ms-js-prms_07.yaml diff --git a/totrans/ms-js-prms_08.yaml b/data/ms-js-prms_08.yaml similarity index 100% rename from totrans/ms-js-prms_08.yaml rename to data/ms-js-prms_08.yaml diff --git a/totrans/ms-js-prms_09.yaml b/data/ms-js-prms_09.yaml similarity index 100% rename from totrans/ms-js-prms_09.yaml rename to data/ms-js-prms_09.yaml diff --git a/totrans/ms-js_00.yaml b/data/ms-js_00.yaml similarity index 100% rename from totrans/ms-js_00.yaml rename to data/ms-js_00.yaml diff --git a/totrans/ms-js_02.yaml b/data/ms-js_02.yaml similarity index 100% rename from totrans/ms-js_02.yaml rename to data/ms-js_02.yaml diff --git a/totrans/ms-js_03.yaml b/data/ms-js_03.yaml similarity index 100% rename from totrans/ms-js_03.yaml rename to data/ms-js_03.yaml diff --git a/totrans/ms-js_04.yaml b/data/ms-js_04.yaml similarity index 100% rename from totrans/ms-js_04.yaml rename to data/ms-js_04.yaml diff --git a/totrans/ms-js_05.yaml b/data/ms-js_05.yaml similarity index 100% rename from totrans/ms-js_05.yaml rename to data/ms-js_05.yaml diff --git a/totrans/ms-js_06.yaml b/data/ms-js_06.yaml similarity index 100% rename from totrans/ms-js_06.yaml rename to data/ms-js_06.yaml diff --git a/totrans/ms-js_07.yaml b/data/ms-js_07.yaml similarity index 100% rename from totrans/ms-js_07.yaml rename to data/ms-js_07.yaml diff --git a/totrans/ms-js_08.yaml b/data/ms-js_08.yaml similarity index 100% rename from totrans/ms-js_08.yaml rename to data/ms-js_08.yaml diff --git a/totrans/ms-js_09.yaml b/data/ms-js_09.yaml similarity index 100% rename from totrans/ms-js_09.yaml rename to data/ms-js_09.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_00.yaml b/data/sencha-tch2-mobi-js-fw_00.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_00.yaml rename to data/sencha-tch2-mobi-js-fw_00.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_01.yaml b/data/sencha-tch2-mobi-js-fw_01.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_01.yaml rename to data/sencha-tch2-mobi-js-fw_01.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_02.yaml b/data/sencha-tch2-mobi-js-fw_02.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_02.yaml rename to data/sencha-tch2-mobi-js-fw_02.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_03.yaml b/data/sencha-tch2-mobi-js-fw_03.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_03.yaml rename to data/sencha-tch2-mobi-js-fw_03.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_04.yaml b/data/sencha-tch2-mobi-js-fw_04.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_04.yaml rename to data/sencha-tch2-mobi-js-fw_04.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_05.yaml b/data/sencha-tch2-mobi-js-fw_05.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_05.yaml rename to data/sencha-tch2-mobi-js-fw_05.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_06.yaml b/data/sencha-tch2-mobi-js-fw_06.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_06.yaml rename to data/sencha-tch2-mobi-js-fw_06.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_07.yaml b/data/sencha-tch2-mobi-js-fw_07.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_07.yaml rename to data/sencha-tch2-mobi-js-fw_07.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_08.yaml b/data/sencha-tch2-mobi-js-fw_08.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_08.yaml rename to data/sencha-tch2-mobi-js-fw_08.yaml diff --git a/totrans/sencha-tch2-mobi-js-fw_09.yaml b/data/sencha-tch2-mobi-js-fw_09.yaml similarity index 100% rename from totrans/sencha-tch2-mobi-js-fw_09.yaml rename to data/sencha-tch2-mobi-js-fw_09.yaml diff --git a/totrans/soc-dtvis-j5-js_0.yaml b/data/soc-dtvis-j5-js_0.yaml similarity index 100% rename from totrans/soc-dtvis-j5-js_0.yaml rename to data/soc-dtvis-j5-js_0.yaml diff --git a/totrans/soc-dtvis-j5-js_1.yaml b/data/soc-dtvis-j5-js_1.yaml similarity index 100% rename from totrans/soc-dtvis-j5-js_1.yaml rename to data/soc-dtvis-j5-js_1.yaml diff --git a/totrans/soc-dtvis-j5-js_2.yaml b/data/soc-dtvis-j5-js_2.yaml similarity index 100% rename from totrans/soc-dtvis-j5-js_2.yaml rename to data/soc-dtvis-j5-js_2.yaml diff --git a/totrans/soc-dtvis-j5-js_3.yaml b/data/soc-dtvis-j5-js_3.yaml similarity index 100% rename from totrans/soc-dtvis-j5-js_3.yaml rename to data/soc-dtvis-j5-js_3.yaml diff --git a/totrans/soc-dtvis-j5-js_4.yaml b/data/soc-dtvis-j5-js_4.yaml similarity index 100% rename from totrans/soc-dtvis-j5-js_4.yaml rename to data/soc-dtvis-j5-js_4.yaml diff --git a/totrans/soc-dtvis-j5-js_5.yaml b/data/soc-dtvis-j5-js_5.yaml similarity index 100% rename from totrans/soc-dtvis-j5-js_5.yaml rename to data/soc-dtvis-j5-js_5.yaml diff --git a/totrans/soc-dtvis-j5-js_6.yaml b/data/soc-dtvis-j5-js_6.yaml similarity index 100% rename from totrans/soc-dtvis-j5-js_6.yaml rename to data/soc-dtvis-j5-js_6.yaml diff --git a/totrans/soc-dtvis-j5-js_7.yaml b/data/soc-dtvis-j5-js_7.yaml similarity index 100% rename from totrans/soc-dtvis-j5-js_7.yaml rename to data/soc-dtvis-j5-js_7.yaml diff --git a/totrans/soc-dtvis-j5-js_8.yaml b/data/soc-dtvis-j5-js_8.yaml similarity index 100% rename from totrans/soc-dtvis-j5-js_8.yaml rename to data/soc-dtvis-j5-js_8.yaml diff --git a/totrans/tnk-js_0.yaml b/data/tnk-js_0.yaml similarity index 100% rename from totrans/tnk-js_0.yaml rename to data/tnk-js_0.yaml diff --git a/totrans/tnk-js_1.yaml b/data/tnk-js_1.yaml similarity index 100% rename from totrans/tnk-js_1.yaml rename to data/tnk-js_1.yaml diff --git a/docs/bd-sgl-pg-webapp-mtr/SUMMARY.md b/docs/bd-sgl-pg-webapp-mtr/SUMMARY.md new file mode 100644 index 0000000..907f42b --- /dev/null +++ b/docs/bd-sgl-pg-webapp-mtr/SUMMARY.md @@ -0,0 +1,13 @@ ++ [序言](bd-sgl-pg-webapp-mtr_00.md) ++ [第一章. 开始使用 Meteor](bd-sgl-pg-webapp-mtr_01.md) ++ [第二章. 构建 HTML 模板](bd-sgl-pg-webapp-mtr_02.md) ++ [第三章。存储数据和处理集合](bd-sgl-pg-webapp-mtr_03.md) ++ [第四章。控制数据流](bd-sgl-pg-webapp-mtr_04.md) ++ [第五章。使用路由使我们的应用具有灵活性](bd-sgl-pg-webapp-mtr_05.md) ++ [第六章。使用会话保持状态](bd-sgl-pg-webapp-mtr_06.md) ++ [第七章。用户和权限](bd-sgl-pg-webapp-mtr_07.md) ++ [第八章。使用允许和拒绝规则进行安全设置](bd-sgl-pg-webapp-mtr_08.md) ++ [第九章。高级响应式](bd-sgl-pg-webapp-mtr_09.md) ++ [第十章 部署我们的应用程序](bd-sgl-pg-webapp-mtr_10.md) ++ [第十一章。构建我们自己的包](bd-sgl-pg-webapp-mtr_11.md) ++ [第十二章. Meteor 中的测试](bd-sgl-pg-webapp-mtr_12.md) \ No newline at end of file diff --git a/docs/bd-sgl-pg-webapp-mtr/bd-sgl-pg-webapp-mtr_00.md b/docs/bd-sgl-pg-webapp-mtr/bd-sgl-pg-webapp-mtr_00.md new file mode 100644 index 0000000..34bbad8 --- /dev/null +++ b/docs/bd-sgl-pg-webapp-mtr/bd-sgl-pg-webapp-mtr_00.md @@ -0,0 +1,144 @@ +# 序言 + +感谢您购买这本书。您为前端和 JavaScript 技术的新一步做出了明智的选择。Meteor 框架不仅仅是为了简化事情而出现的另一个库。它为 Web 服务器、客户端逻辑和模板提供了一个完整的解决方案。此外,它还包含了一个完整的构建过程,这将使通过块状方式为 Web 工作变得更快。多亏了 Meteor,链接您的脚本和样式已经成为过去,因为自动构建过程会为您处理所有事情。这确实是一个很大的改变,但您很快就会喜欢上它,因为它使扩展应用程序的速度与创建新文件一样快。 + +Meteor 旨在创建单页应用程序,其中实时是默认值。它负责数据同步和 DOM 的更新。如果数据发生变化,您的屏幕将进行更新。这两个基本概念构成了我们作为网页开发者所做的很多工作,而 Meteor 则无需编写任何额外的代码即可实现。 + +在我看来,Meteor 在现代网页开发中是一个完整的游戏改变者。它将以下模式作为默认值引入: + ++ 胖客户端:所有的逻辑都存在于客户端。HTML 仅在初始页面加载时发送 + ++ 在客户端和服务器上使用相同的 JavaScript 和 API + ++ 实时:数据自动同步到所有客户端 + ++ 一种“无处不在的数据库”方法,允许在客户端进行数据库查询 + ++ 作为 Web 服务器通信默认的发布/订阅模式 + +一旦你使用了我所介绍的所有这些新概念,你很难回到过去那种只花费时间准备应用程序结构,而链接文件或将它们封装为 Require.js 模块,编写端点以及编写请求和发送数据上下的代码的老方法。 + +在阅读这本书的过程中,您将逐步介绍这些概念以及它们是如何相互连接的。我们将建立一个带有后端编辑帖子的博客。博客是一个很好的例子,因为它使用了帖子列表、每个帖子的不同路由以及一个管理界面来添加新帖子,为我们提供了全面理解 Meteor 所需的所有内容。 + +# 本书涵盖内容 + +第一章,*Meteor 入门*,描述了安装和运行 Meteor 所需的步骤,同时还详细介绍了 Meteor 项目的文件结构,特别是我们将要构建的 Meteor 项目。 + +第二章,*构建 HTML 模板*,展示了如何使用 handlebar 这样的语法构建反应式模板,以及如何在其中显示数据是多么简单。 + +第三章,*存储数据和处理集合*,涵盖了服务器和客户端的数据库使用。 + +第四章, *数据流控制*, 介绍了 Meteor 的发布/订阅模式,该模式用于在服务器和客户端之间同步数据。 + +第五章, *使用路由使我们的应用具有多样性*, 教我们如何设置路由,以及如何让我们的应用表现得像一个真正的网站。 + +第六章, *使用会话保持状态*, 讨论了响应式会话对象及其使用方法。 + +第七章, *用户和权限*, 描述了用户的创建以及登录过程是如何工作的。此时,我们将为我们的博客创建后端部分。 + +第八章, *使用 Allow 和 Deny 规则进行安全控制*, 介绍了如何限制数据流仅对某些用户开放,以防止所有人对我们的数据库进行更改。 + +第九章, *高级响应性*, 展示了如何构建我们自己的自定义响应式对象,该对象可以根据时间间隔重新运行一个函数。 + +第十章, *部署我们的应用*, 介绍了如何使用 Meteor 自己的部署服务以及在自己的基础设施上部署应用。 + +第十一章, *构建我们自己的包*, 描述了如何编写一个包并将其发布到 Atmosphere,供所有人使用。 + +第十二章, *Meteor 中的测试*, 展示了如何使用 Meteor 自带的 tinytest 包进行包测试,以及如何使用第三方工具测试 Meteor 应用程序本身。 + +附录, 包含 Meteor 命令列表以及 iron:router 钩子及其描述。 + +# 本书需要的软件 + +为了跟随章节中的示例,你需要一个文本编辑器来编写代码。我强烈推荐 Sublime Text 作为你的集成开发环境,因为它有几乎涵盖每个任务的可扩展插件。 + +你还需要一个现代浏览器来查看你的结果。由于许多示例使用浏览器控制台来更改数据库以及查看代码片段的结果,我推荐使用 Google Chrome。其开发者工具网络检查器拥有一个 web 开发者需要的所有工具,以便轻松地工作和服务器调试网站。 + +此外,你可以使用 Git 和 GitHub 来存储你每一步的成功,以及为了回到代码的先前版本。 + +每个章节的代码示例也将发布在 GitHub 上,地址为[`github.com/frozeman/book-building-single-page-web-apps-with-meteor`](https://github.com/frozeman/book-building-single-page-web-apps-with-meteor),该仓库中的每个提交都与书中的一个章节相对应,为你提供了一种直观的方式来查看在每个步骤中添加和移除了哪些内容。 + +# 本书适合对象 + +这本书适合希望进入单页、实时应用新范式的 Web 开发者。你不需要成为 JavaScript 专业人士就能跟随书中的内容,但扎实的基本知识会让你发现这本书是个宝贵的伴侣。 + +如果你听说过 Meteor 但还没有使用过,这本书绝对适合你。它会教你所有你需要理解并成功使用 Meteor 的知识。如果你之前使用过 Meteor 但想要更深入的了解,那么最后一章将帮助你提高对自定义反应式对象和编写包的理解。目前 Meteor 社区中涉及最少的主题可能是测试,因此通过阅读最后一章,你将很容易理解如何使用自动化测试使你的应用更加健壮。 + +# 约定 + +在这本书中,你会发现多种用于区分不同信息类型的文本样式。以下是这些样式的几个示例及其含义解释。 + +文本中的代码词汇、数据库表名、文件夹名、文件名、文件扩展名、路径名、假 URL、用户输入和 Twitter 处理显示如下:"With Meteor, we never have to link files with the ` +
+ Hello World + +``` + +当我们希望引起你对代码块中特定部分的关注时,相关行或项目以粗体显示: + +```js + +``` + +任何命令行输入或输出如下所示: + +```js +$ cd my/developer/folder +$ meteor create my-meteor-blog + +``` + +**新术语**和**重要词汇**以粗体显示。例如,你在屏幕上看到的、在菜单或对话框中出现的词汇,在文本中显示为这样:"However, now when we go to our browser, we will still see **Hello World**." + +### 注意 + +警告或重要说明以这样的盒子形式出现。 + +### 提示 + +技巧和建议以这样的形式出现。 + +# 读者反馈 + +我们的读者的反馈总是受欢迎的。告诉我们你对这本书的看法——你喜欢或可能不喜欢的地方。读者反馈对我们开发您真正能从中获得最大收益的书很重要。 + +发送一般反馈,只需发送电子邮件至`{{someNested.text}}
+ ``` + +这现在将显示`someText`和`someNested.text`,后者是由我们的助手函数返回的。 + +## 使用`{{#with}}`块助手 + +设置数据上下文的一种另一种方法是使用`{{#with}}`块助手。以下代码片段与之前使用助手函数的包含助手具有相同的结果: + +```js +{{#with dataContextHelper}} + {{> contextExample}} +{{/with}} +``` + +我们甚至在浏览器中得到同样的结果,当我们不使用子模板,只是将`contextExample`模板的内容添加到`{{#with}}`块助手中,如下所示: + +```js +{{#with dataContextHelper}} +{{someText}}
+{{someNested.text}}
+{{/with}} +``` + +# 模板助手和模板回调中的"this" + +在 Meteor 中,模板助手中的`this`在模板回调(如`created()`、`rendered()`和`destroyed()`)中的使用方式不同。 + +如前所述,模板有三个回调函数,在模板的不同状态下触发: + ++ `created`:当模板初始化但尚未插入 DOM 时触发 + ++ `rendered`:当模板及其所有子模板附加到 DOM 时触发 + ++ `destroyed`:当模板从 DOM 中移除并在模板实例被销毁之前触发 + +在这些回调函数中,`this` 指的是当前模板实例。实例对象可以访问模板的 DOM 并带有以下方法: + ++ `this.$(selectorString)`:这个方法找到所有匹配 `selectorString` 的元素,并返回这些元素的 jQuery 对象。 + ++ `this.findAll(selectorString)`:这个方法找到所有匹配 `selectorString` 的元素,但返回普通的 DOM 元素。 + ++ `this.find(selectorString)`:这个方法找到匹配 `selectorString` 的第一个元素,并返回一个普通的 DOM 元素。 + ++ `this.firstNode`:这个对象包含模板中的第一个元素。 + ++ `this.lastNode`:这个对象包含模板中的最后一个元素。 + ++ `this.data`:这个对象包含模板的数据上下文 + ++ `this.autorun(runFunc)`:一个在模板实例被销毁时停止的反应式 `Tracker.autorun()` 函数。 + ++ `this.view`:这个对象包含这个模板的 `Blaze.View` 实例。`Blaze.View` 是反应式模板的构建块。 + +在辅助函数内部,`this` 仅指向当前的数据上下文。 + +为了使这些不同的行为变得可见,我们将查看一些示例: + ++ 当我们想要访问模板的 DOM 时,我们必须在渲染回调中进行,因为只有在这一点上,模板元素才会出现在 DOM 中。为了看到它的工作原理,我们按照以下方式编辑我们的 `home.js` 文件: + + ```js + Template.home.rendered = function(){ + console.log('Rendered the home template'); + + this.$('p').html('We just replaced that text!'); + }; + ``` + + 这将用我们设置的字符串替换由 `{{#markdown}}` 块辅助函数创建的第一个 `` 标签。现在当我们检查浏览器时,我们会发现包含我们博客介绍文本的第一个 `
` 标签已经被替换。 + ++ 对于下一个示例,我们需要为我们的 `contextExample` 模板创建一个额外的模板 JavaScript 文件。为此,我们在 `templates` 文件夹中创建一个名为 `examples.js` 的新文件,并使用以下代码片段保存它: + + ```js + Template.contextExample.rendered = function(){ + console.log('Rendered Context Example', this.data); + }; + + Template.contextExample.helpers({ + logContext: function(){ + console.log('Context Log Helper', this); + } + }); + ``` + + 这将把渲染回调以及一个名为 `logContext` 的辅助函数添加到我们的 `contextExample` 模板辅助函数中。为了使这个辅助函数运行,我们还需要将其添加到我们的 `contextExample` 模板中,如下所示: + + ```js +
{{logContext}}
+ ``` + +当我们现在回到浏览器的控制台时,我们会发现数据上下文对象已经被返回给所有我们的已渲染的 `contextTemplates` 模板的 `rendered` 回调和辅助函数。我们还可以看到辅助函数将在渲染回调之前运行。 + +### 注意 + +如果您需要从模板辅助函数内部访问模板的实例,您可以使用 `Template.instance()` 来获取它。 + +现在让我们使用事件使我们的模板变得交互式。 + +# 添加事件 + +为了使我们的模板更具动态性,我们将添加一个简单的事件,这将使之前创建的 `logContext` 辅助函数重新反应式地运行。 + +首先,然而,我们需要在我们的 `contextExample` 模板中添加一个按钮: + +```js + +``` + +为了捕获点击事件,打开 `examples.js` 并添加以下 `event` 函数: + +```js +Template.contextExample.events({ + 'click button': function(e, template){ + Session.set('randomNumber', Math.random(0,99)); + } +}); +``` + +这将设置一个名为 `randomNumber` 的会话变量到一个随机数。 + +### 注意 + +在下一章中,我们将深入讨论会话。现在,我们只需要知道当会话变量发生变化时,所有使用`Session.get('myVariable')`获取该会话变量的函数将重新运行。 + +为了看到这个效果,我们将向`logContext`助手添加一个`Session.get()`调用,并像以下方式返回先前设置的随机数: + +```js +Template.contextExample.helpers({ + logContext: function(){ + console.log('Context Log Helper',this); + + return Session.get('randomNumber'); + } +}); +``` + +如果我们打开浏览器,我们会看到**获取一些随机数**按钮。当我们点击它时,我们会看到一个随机数出现在按钮上方。 + +### 注意 + +当我们在我们`home`模板中多次使用`contextTemplates`模板时,我们会发现该模板助手每次都会显示相同的随机数。这是因为会话对象将重新运行其所有依赖项,其中所有依赖项都是`logHelper`助手的实例。 + +既然我们已经介绍了模板助手,那么让我们创建一个自定义的块助手。 + +# 块助手 + +```js +example.html file: +``` + +```js + +Content goes here: {{> Template.contentBlock}}
+ {{else}} +Else content here: {{> Template.elseBlock}}
+ {{/if}} +