Skip to content

Commit

Permalink
Add css support to our dictionary!
Browse files Browse the repository at this point in the history
  • Loading branch information
darkgeek committed Sep 16, 2015
1 parent c0e2a64 commit 4f09897
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/main/java/im/darkgeek/dicts/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public int process(Element element) {
return 1;
}
};
Callback changeToH1 = new Callback() {
public int process(Element element) {
element.setName("h2");
return 1;
}
};

System.setProperty("entityExpansionLimit", "640000");
System.out.println(System.getProperty("user.dir"));
Expand All @@ -121,6 +127,7 @@ public int process(Element element) {
.addQuirk("er", changeToHypeLink)
.addQuirk("qau", enhanceQAUblock)
.addQuirk("au", enhanceQAUblock)
.addQuirk("ent", changeToH1)
.generate();
System.out.println("Size: " + list.size());
DictGenerator.createGeneratorScript(list);
Expand Down
75 changes: 73 additions & 2 deletions src/main/java/im/darkgeek/dicts/DictGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,68 @@ public class DictGenerator {
"with slob.create('gcide.slob') as w:\n";
private static String GENERATOR_TEMPLATE =
" w.add(\"\"\"#DEFINATION#\"\"\".encode('utf-8'), \"\"\"#WORD#\"\"\", content_type='text/html; charset=utf-8')";
private static final String SCRIPT_NAME = "dict_creator.py";
private static String nightModeCss = "body {\n" +
" background-color: black;\n" +
" color: gray;\n" +
"}\n" +
"\n" +
"h1, h2, h3, h4, h5, h6 {\n" +
" color: gray !important;\n" +
"}\n" +
"\n" +
"img {\n" +
" background-color: lightgray;\n" +
"}\n" +
"\n" +
"table {\n" +
" background-color: black !important;\n" +
" color: gray !important;\n" +
"}\n" +
"\n" +
"div.thumbinner {\n" +
" background-color: #191919 !important;\n" +
"}\n" +
"\n" +
"div.thumb {\n" +
" border-color: black !important;\n" +
"}\n" +
"\n" +
"a {\n" +
" color: green;\n" +
"}\n" +
"\n" +
"a:visited {\n" +
" color: darkgreen;\n" +
"}\n";
private static String nightModeCssLink = "<link rel=\"alternate stylesheet\" href=\"~/css/night.css\"" +
" type=\"text/css\" title=\"Night\">";
private static String defaultCss = "pos {\n" +
"\tcolor: darkgreen;\n" +
"\tfont-weight: bold;\n" +
"}\n" +
"\n" +
"hw,sn {\n" +
"\tfont-weight: bold;\n" +
"}\n" +
"\n" +
"q,it,ant,asp,booki,causedby,cnvto,compof,\n" +
"contr,cref,film,fld,itran,itrans,abbr,altname,altnpluf,\n" +
"ets,etsep,ex,mark,qex,sd,ship,source,pluf,uex,isa,mathex,\n" +
"ratio,singf,xlati,tran,tr,iref,figref,ptcl,title,stype,\n" +
"part,parts,membof,member,members,corr,qperson,prod,prodmac,\n" +
"stage,inv,methodfor,examp,unit,uses,usedby,perf,recipr,sig,wns,\n" +
"w16ns,spn,kingdom,phylum,subphylum,class,subclass,ord,subord,\n" +
"suborder,fam,subfam,gen,var,varn\n" +
"{\n" +
"\tfont-style: italic;\n" +
"}\n" +
"\n" +
"qau,au {\n" +
"\tfont-style: italic;\n" +
" font-weight: bold;\n" +
"}";
private static String defaultCssLink = "<link rel=\"stylesheet\" href=\"~/css/default.css\" type=\"text/css\">";
private static String SCRIPT_NAME = "dict_creator.py";

public static void createGeneratorScript(List<DictItem> items) {
if (items == null)
Expand All @@ -25,11 +86,21 @@ public static void createGeneratorScript(List<DictItem> items) {
printWriter = new PrintWriter(SCRIPT_NAME, "UTF-8");

printWriter.print(GENERATOR_SCRIPT_HEADER);
printWriter.println(
GENERATOR_TEMPLATE
.replace("#DEFINATION#", nightModeCss)
.replace("#WORD#", "~/css/night.css")
);
printWriter.println(
GENERATOR_TEMPLATE
.replace("#DEFINATION#", defaultCss)
.replace("#WORD#", "~/css/default.css")
);

for (DictItem item : items) {
printWriter.println(
GENERATOR_TEMPLATE
.replace("#DEFINATION#", item.getExplanation())
.replace("#DEFINATION#", nightModeCssLink + defaultCssLink + item.getExplanation())
.replace("#WORD#", item.getWord())
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/im/darkgeek/dicts/DictProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ private boolean isMarkwordOfUnList(String entValue) {

private void processLonglistUnPrefixedWords(Element pElement, List<DictItem> itemList, CompoundDictItem unCDictItem) {
CompoundDictItem compoundDictItem = new CompoundDictItem();
String unDefTemplate = "<p><ent>#WORD#</ent><br/><hw>#WORD#</hw><br/>" +
"<def>#DEFINITION#</def></p>";
String unDefTemplate = "<p><h1>#WORD#</h1><br/><hw>#WORD#</hw>" +
"<def>&nbsp;&nbsp;-&nbsp;&nbsp;#DEFINITION#</def></p>";

for (Iterator i = pElement.elementIterator(); i.hasNext(); ) {
Element currElement = (Element) i.next();
Expand Down

0 comments on commit 4f09897

Please sign in to comment.