1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Html: Move get_elem_val to xo.elem

This commit is contained in:
gnosygnu
2017-02-22 09:41:37 -05:00
parent 5bd3371802
commit 12848b7cf5
896 changed files with 69011 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*;
import gplx.xowa.guis.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
public class Xoh_head_mgr_tst {
@Before public void init() {fxt.Clear();} private Xoh_head_mgr_fxt fxt = new Xoh_head_mgr_fxt();
@Test public void Css() {
fxt.Mgr().Itm__css().Enabled_y_();
fxt.Test_write(String_.Concat_lines_nl_skip_last
( ""
, " <style type=\"text/css\">"
, " .xowa-missing-category-entry {color: red;}"
, " </style>"
));
}
@Test public void Toc() {
fxt.Init_msg(Xoh_head_itm__toc.Key_showtoc, "Sh\"ow");
fxt.Init_msg(Xoh_head_itm__toc.Key_hidetoc, "Hi'de");
fxt.Mgr().Itm__toc().Enabled_y_();
fxt.Test_write(String_.Concat_lines_nl_skip_last
( ""
, " <script type='text/javascript'>"
, " var xowa_global_values = {"
, " 'toc-enabled' : true,"
, " 'mw_hidetoc' : '0',"
, " 'showtoc' : 'Sh\"ow',"
, " 'hidetoc' : 'Hi\\'de',"
, " }"
, " </script>"
));
}
@Test public void Globals() {
fxt.Init_msg(Xol_msg_itm_.Id_dte_month_name_january, "Jan'uary" ); // add apos to simulate apostrophes in Hebrew months; DATE:2014-07-28
fxt.Mgr().Itm__globals().Enabled_y_();
fxt.Test_write(String_.Concat_lines_nl_skip_last
( ""
, " <link rel=\"stylesheet\" href=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/core.css\" type='text/css'>"
, " <script type='text/javascript'>"
, " var xowa_root_dir = 'file:///mem/xowa/';"
, " var xowa_mode_is_server = false;"
, " var xowa_global_values = {"
, " 'mode_is_gui' : false,"
, " 'mode_is_http' : false,"
, " 'http-port' : 8080,"
, " 'sort-ascending' : 'Sort ascending',"
, " 'sort-descending' : 'Sort descending',"
, " 'wgContentLanguage' : 'en',"
, " 'wgSeparatorTransformTable' : ['.\t.', ',\t,'],"
, " 'wgDigitTransformTable' : ['', ''],"
, " 'wgDefaultDateFormat' : 'dmy',"
, " 'wgMonthNames' : ['', 'Jan\\'uary', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
, " }"
, " </script>"
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/core.js\" type='text/javascript'></script>"
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/exec.js\" type='text/javascript'></script>"
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/DOMContentLoaded.js\" type='text/javascript'></script>"
, " <script type='text/javascript'>"
, " xowa.app.mode = 'cmd';"
, " var x_p = xowa.page;"
, " x_p.wiki = 'en.wikipedia.org';"
, " x_p.ttl = 'Test_page';"
, " </script>"
));
fxt.Init_msg(Xol_msg_itm_.Id_dte_month_name_january, "January" ); // set it back
}
@Test public void Globals_la() { // PURPOSE: la.gfs only specifies "," not "."; make sure both "." and "," show up, or else null ref error during import; DATE:2014-05-13
Xol_lang_itm la_lang = fxt.Wiki().Lang();
gplx.xowa.langs.numbers.Xol_transform_mgr separators_mgr = la_lang.Num_mgr().Separators_mgr();
separators_mgr.Clear();
separators_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__grp, Bry_.new_a7(" "));
fxt.Mgr().Itm__globals().Enabled_y_();
fxt.Test_write(String_.Concat_lines_nl_skip_last
( ""
, " <link rel=\"stylesheet\" href=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/core.css\" type='text/css'>"
, " <script type='text/javascript'>"
, " var xowa_root_dir = 'file:///mem/xowa/';"
, " var xowa_mode_is_server = false;"
, " var xowa_global_values = {"
, " 'mode_is_gui' : false,"
, " 'mode_is_http' : false,"
, " 'http-port' : 8080,"
, " 'sort-ascending' : 'Sort ascending',"
, " 'sort-descending' : 'Sort descending',"
, " 'wgContentLanguage' : 'en',"
, " 'wgSeparatorTransformTable' : ['.\t.', ' \t,']," // note that grp spr (",") is ""
, " 'wgDigitTransformTable' : ['', ''],"
, " 'wgDefaultDateFormat' : 'dmy',"
, " 'wgMonthNames' : ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
, " }"
, " </script>"
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/core.js\" type='text/javascript'></script>"
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/exec.js\" type='text/javascript'></script>"
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/DOMContentLoaded.js\" type='text/javascript'></script>"
, " <script type='text/javascript'>"
, " xowa.app.mode = 'cmd';"
, " var x_p = xowa.page;"
, " x_p.wiki = 'en.wikipedia.org';"
, " x_p.ttl = 'Test_page';"
, " </script>"
));
}
}
class Xoh_head_mgr_fxt {
private final Xop_fxt fxt = new Xop_fxt();
private Xoh_head_mgr mgr;
private Bry_bfr bfr = Bry_bfr_.Reset(255);
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Xoh_head_mgr Mgr() {return mgr;}
public Xol_lang_itm Make_lang(String key) {return wiki.Appe().Lang_mgr().Get_by_or_new(Bry_.new_a7(key));}
public void Clear() {
fxt.Reset();
mgr = fxt.Page().Html_data().Head_mgr();
wiki = fxt.Wiki();
}
public void Init_msg(byte[] key, String val) {
wiki.Msg_mgr().Get_or_make(key).Atrs_set(Bry_.new_a7(val), false, false);
}
public void Init_msg(int id, String val) {
Xol_msg_itm msg_itm = wiki.Lang().Msg_mgr().Itm_by_id_or_null(id);
msg_itm.Atrs_set(Bry_.new_a7(val), false, false);
}
public void Test_write(String expd) {
mgr.Write(bfr, fxt.App(), wiki, fxt.Page());
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,61 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*;
import gplx.xowa.guis.*;
public class Xoh_head_wtr_tst {
@Before public void init() {fxt.Clear();} private Xoh_head_wtr_fxt fxt = new Xoh_head_wtr_fxt();
@Test public void Globals_none() {
Xoh_head_wtr wtr = fxt.Wtr();
wtr.Write_js_head_global_bgn();
wtr.Write_js_head_global_end();
fxt.Test("");
}
@Test public void Globals_some() {
Xoh_head_wtr wtr = fxt.Wtr();
wtr.Write_js_head_global_bgn();
fxt.Exec_Write_js_global_ini_atr_val("key_1", "val_1");
fxt.Exec_Write_js_global_ini_atr_val("key_2", "val_2");
fxt.Exec_Write_js_global_ini_atr_val("key_3", "apos_'_1");
wtr.Write_js_head_global_end();
fxt.Test(String_.Concat_lines_nl_skip_last
( ""
, "var xowa_global_values = {"
, " 'key_1' : 'val_1',"
, " 'key_2' : 'val_2',"
, " 'key_3' : 'apos_\\'_1',"
, "}"
));
}
}
class Xoh_head_wtr_fxt {
private Bry_bfr bfr = Bry_bfr_.Reset(255);
public Xoh_head_wtr Wtr() {return wtr;} private Xoh_head_wtr wtr = new Xoh_head_wtr();
public void Clear() {
wtr.Init(bfr);
}
public void Exec_Write_js_global_ini_atr_val(String key, String val) {wtr.Write_js_global_ini_atr_val(Bry_.new_u8(key), Bry_.new_u8(val));}
public void Test(String expd) {
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
// public void Init_msg(byte[] key, String val) {
// wiki.Msg_mgr().Get_or_make(key).Atrs_set(Bry_.new_a7(val), false, false);
// }
// public void Test_write(String expd) {
// mgr.Write(bfr, fxt.App(), wiki, fxt.Page());
// Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
// }
}

View File

@@ -0,0 +1,55 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*;
public class Xow_fragment_mgr_tst {
Xow_fragment_mgr_fxt fxt = new Xow_fragment_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Html_js_edit_toolbar_fmt() {
fxt.Test_fragment(Xow_fragment_mgr.Invk_html_js_edit_toolbar, String_.Concat_lines_nl
( " var xowa_edit_i18n = {"
, " 'bold_tip' : 'Bold text',"
, " 'bold_sample' : 'Bold text',"
, " 'italic_tip' : 'Italic text',"
, " 'italic_sample' : 'Italic text',"
, " 'link_tip' : 'Internal link',"
, " 'link_sample' : 'Link title',"
, " 'headline_tip' : 'Level 2 headline',"
, " 'headline_sample' : 'Headline text',"
, " 'ulist_tip' : 'Bulleted list',"
, " 'ulist_sample' : 'Bulleted list item',"
, " 'olist_tip' : 'Numbered list',"
, " 'olist_sample' : 'Numbered list item'"
, " };"
));
}
}
class Xow_fragment_mgr_fxt {
public void Clear() {
if (wiki == null) {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
}
} private Xowe_wiki wiki;
public Xol_lang_itm Make_lang(String key) {return wiki.Appe().Lang_mgr().Get_by_or_new(Bry_.new_a7(key));}
public void Test_fragment(String key, String expd) {Test_fragment(wiki.Lang(), key, expd);}
public void Test_fragment(Xol_lang_itm lang, String key, String expd) {
wiki.Fragment_mgr().Evt_lang_changed(lang);
byte[] actl = (byte[])Gfo_invk_.Invk_by_key(wiki.Fragment_mgr(), key);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
}