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

Source: Restore broken commit

This commit is contained in:
gnosygnu
2017-02-06 22:14:55 -05:00
parent 938beac9f9
commit 3bfeb94b43
4380 changed files with 328018 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.indicators; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.fmtrs.*;
public class Indicator_html_bldr implements gplx.core.brys.Bfr_arg {
private Indicator_html_bldr_itm bldr_itm = new Indicator_html_bldr_itm();
private Ordered_hash list = Ordered_hash_.New();
public void Enabled_(boolean v) {enabled = v;} private boolean enabled = Bool_.Y;
public void Clear() {
enabled = Bool_.Y;
list.Clear();
}
public int Count() {return list.Count();}
public boolean Has(String key) {return list.Has(key);}
public void Add(Indicator_xnde xnde) {
if (!enabled) return; // do not add if disabled; called from <page>; PAGE:en.s:The_Parochial_System_(Wilberforce,_1838); DATE:2015-04-29
list.Add_if_dupe_use_nth(xnde.Name(), xnde); // Add_if_dupe_use_nth: 2nd indicator overwrites 1st; DATE:2015-04-29
}
public void Bfr_arg__add(Bry_bfr bfr) {
if (list.Count() == 0) return; // do not build html if no items; DATE:2015-04-29
bldr_itm.Init(list);
fmtr_grp.Bld_bfr_many(bfr, bldr_itm);
}
private static final Bry_fmtr
fmtr_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='mw-indicators'>~{itms}"
, " </div>"
), "itms")
;
}
class Indicator_html_bldr_itm implements gplx.core.brys.Bfr_arg {
private Ordered_hash list;
public void Init(Ordered_hash list) {this.list = list;}
public void Bfr_arg__add(Bry_bfr bfr) {
int list_len = list.Count();
for (int i = list_len - 1; i > -1; --i) { // reverse order
Indicator_xnde xnde = (Indicator_xnde)list.Get_at(i);
fmtr_itm.Bld_bfr_many(bfr, xnde.Name(), xnde.Html());
}
}
private static final Bry_fmtr
fmtr_itm = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div id='mw-indicator-~{name}' class='mw-indicator'>~{html}</div>"
), "name", "html")
;
}

View File

@@ -0,0 +1,66 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.indicators; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.xtns.indicators.*;
public class Indicator_html_bldr_tst {
@Before public void init() {fxt.Clear();} private Indicator_html_bldr_fxt fxt = new Indicator_html_bldr_fxt();
@Test public void Basic() {
fxt.Init_indicator("a", "a1");
fxt.Init_indicator("b", "b1");
fxt.Test_bld(String_.Concat_lines_nl_skip_last
( ""
, " <div class='mw-indicators'>"
, " <div id='mw-indicator-b' class='mw-indicator'>b1</div>" // reverse-order
, " <div id='mw-indicator-a' class='mw-indicator'>a1</div>"
, " </div>"
));
}
@Test public void Multiple_ignore() {
fxt.Init_indicator("a", "a1");
fxt.Init_indicator("a", "a2");
fxt.Test_bld(String_.Concat_lines_nl_skip_last
( ""
, " <div class='mw-indicators'>"
, " <div id='mw-indicator-a' class='mw-indicator'>a2</div>" // 2nd overwrites 1st
, " </div>"
));
}
}
class Indicator_html_bldr_fxt {
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page;
private Indicator_xtn_mgr xtn_mgr;
public void Clear() {
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
this.xtn_mgr = wiki.Xtn_mgr().Xtn_indicator();
xtn_mgr.Enabled_y_();
xtn_mgr.Xtn_init_by_wiki(wiki);
this.page = wiki.Parser_mgr().Ctx().Page();
}
public void Init_indicator(String name, String html) {
Indicator_xnde xnde = new Indicator_xnde();
xnde.Init_for_test(name, Bry_.new_u8(html));
Indicator_html_bldr indicators = page.Html_data().Indicators();
indicators.Add(xnde);
}
public void Test_bld(String expd) {
Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
page.Html_data().Indicators().Bfr_arg__add(tmp_bfr);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.indicators; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.wikis.pages.skins.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
public class Indicator_xnde implements Xox_xnde, Mwh_atr_itm_owner1 {
public String Name() {return name;} private String name;
public byte[] Html() {return html;} private byte[] html;
public void Init_for_test(String name, byte[] html) {this.name = name; this.html = html;} // TEST
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {
if (xatr_id_obj == null) return;
Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj;
switch (xatr_id.Val()) {
case Xatr_name: this.name = xatr.Val_as_str(); break;
}
}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
this.html = Xop_parser_.Parse_text_to_html(wiki, ctx, ctx.Page(), ctx.Page().Ttl(), Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()), false);
Indicator_html_bldr html_bldr = ctx.Page().Html_data().Indicators();
if (this.name != null) html_bldr.Add(this); // NOTE: must do null-check b/c Add will use Name as key for hashtable
}
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
if (this.name == null) bfr.Add_str_a7("Error: Page status indicators' name attribute must not be empty.");
}
private static final byte Xatr_name = 0;
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7()
.Add_str_obj("name", Byte_obj_val.new_(Xatr_name));
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.indicators; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Indicator_xnde_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_parse_page_all_str("<indicator name='a'>test</indicator>", "");
}
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.indicators; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.htmls.*; import gplx.xowa.wikis.*;
public class Indicator_xtn_mgr extends Xox_mgr_base {
public Indicator_xtn_mgr() {
}
@Override public boolean Enabled_default() {return false;}
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("Indicator");
@Override public Xox_mgr Xtn_clone_new() {return new Indicator_xtn_mgr();}
}