diff options
-rw-r--r-- | conversion/ConvertFile.java | 2 | ||||
-rw-r--r-- | index/IndexCreator.java | 2 | ||||
-rw-r--r-- | parsers/CloseHtmlTags.java (renamed from parsers/DocumentName.java) | 35 | ||||
-rw-r--r-- | parsers/CodeBlocks.java | 85 | ||||
-rw-r--r-- | parsers/Header.java | 8 | ||||
-rw-r--r-- | parsers/LastUpdate.java | 51 | ||||
-rw-r--r-- | parsers/MetaParser.java | 60 | ||||
-rw-r--r-- | parsers/ParserList.java | 8 | ||||
-rw-r--r-- | parsers/QuoteSpecialText.java | 4 | ||||
-rw-r--r-- | status/PresentFile.java | 1 | ||||
-rw-r--r-- | styling/style.css | 26 | ||||
-rw-r--r-- | todo | 44 |
12 files changed, 279 insertions, 47 deletions
diff --git a/conversion/ConvertFile.java b/conversion/ConvertFile.java index 5065ad0..f37d009 100644 --- a/conversion/ConvertFile.java +++ b/conversion/ConvertFile.java @@ -41,6 +41,8 @@ public class ConvertFile { * for use outside this method. */ PresentFile.file = file; + PresentFile.name = null; + PresentFile.author = null; readFile = new ReadFile(file); String fileContent = readFile.getContent(); if(!fileContent.equals("")) { diff --git a/index/IndexCreator.java b/index/IndexCreator.java index e06db24..13b71b0 100644 --- a/index/IndexCreator.java +++ b/index/IndexCreator.java @@ -48,7 +48,7 @@ public class IndexCreator { String fileName = htmlFile.create().getName(); if(shouldAdd(fileName)) { System.out.println("New Entry: "+fileName); - indexContent.append("[[./"); + indexContent.append(" [[./"); indexContent.append(fileName); indexContent.append("|"); indexContent.append(PresentFile.name); diff --git a/parsers/DocumentName.java b/parsers/CloseHtmlTags.java index 032d7c0..ddeaf10 100644 --- a/parsers/DocumentName.java +++ b/parsers/CloseHtmlTags.java @@ -21,19 +21,26 @@ package scruf.parsers; -import java.io.*; -import scruf.status.*; +/** + * this class, inserts the main content of the html into the <article> + * block. + */ -public class DocumentName implements Parser { - public String parse(String fileContent) { - BufferedReader read = - new BufferedReader(new StringReader(fileContent)); - try { - PresentFile.name = read.readLine(); - }catch(IOException e) { - System.err.println("Error reading string "+e); - } - fileContent = new NullIt().nullIt(fileContent,PresentFile.name); - return fileContent; - } +public class CloseHtmlTags implements Parser { + private StringBuilder sbuilder; + /** + * the fileContent has its <head> and <article> fields filled. + */ + public String parse(String fileContent) { + sbuilder = new StringBuilder(); + sbuilder.append(fileContent); + // add "powered by scruf" at bottom of page. + sbuilder.append("\n<div class=\"scruf\">\n"); + sbuilder.append("<a href=\"http://nongnu.org/scruf/\">powered by scruf</a>"); + sbuilder.append("\n</div>\n"); + // Close body tag + sbuilder.append("\n</body>\n"); + sbuilder.append("</html>\n"); + return sbuilder.toString(); + } } diff --git a/parsers/CodeBlocks.java b/parsers/CodeBlocks.java index 64e8841..251c4de 100644 --- a/parsers/CodeBlocks.java +++ b/parsers/CodeBlocks.java @@ -22,10 +22,12 @@ package scruf.parsers; import java.util.regex.*; +import java.util.*; public class CodeBlocks implements Parser { + private SymbolMap symbolMap = new SymbolMap(); public String parse(String fileContent) { - Pattern pattern = Pattern.compile("(\\#\\#\\#)(\\n+)(.+?)(\\n+)(\\1)", + Pattern pattern = Pattern.compile("(\\#\\#\\#)(\\n)(.+?)(\\n)(\\1)", Pattern.DOTALL); Matcher matcher = pattern.matcher(fileContent); LineBreak lbreak = new LineBreak(); @@ -34,7 +36,7 @@ public class CodeBlocks implements Parser { while(matcher.find()) { replacement.delete(0,replacement.length()); replacement.append("<div class=\"code\">"); - replacement.append(lbreak.parse(quote(matcher.group(3)))); + replacement.append(lbreak.parse(quote(matcher.group(3)))); replacement.append("</div>"); matcher.appendReplacement(sbuffer,replacement.toString()); } @@ -42,21 +44,84 @@ public class CodeBlocks implements Parser { return sbuffer.toString(); } /** - * this method quotes special characters -- `\` & - * `$`, in the replacment string as they have - * special meaning. - * + * this method quotes symbols to a HTML number. */ private String quote(String string) { - Pattern pattern = Pattern.compile("\\$|\\\\"); + Pattern pattern = Pattern.compile("(\\&(amp|lt|gt|(\\#35))\\;)|(\\p{Punct})"); Matcher matcher = pattern.matcher(string); StringBuffer sbuffer = new StringBuffer(); - String rep; while(matcher.find()) { - rep = "\\\\\\"+matcher.group(); - matcher.appendReplacement(sbuffer,rep); + if(matcher.group(4)!=null) { + matcher.appendReplacement(sbuffer, + symbolMap.get(matcher.group())); + } } matcher.appendTail(sbuffer); return sbuffer.toString(); } } + +/** + * Map of Symbols & their HTML equivalent numbers. + */ +class SymbolMap extends HashMap<String, String> { + public SymbolMap() { + put("!","!"); + put("\"","""); + put("#","#"); + put("$","$"); + put("%","%"); + put("&","&"); + put("'","'"); + put("(","("); + put(")",")"); + put("*","*"); + put("+","+"); + put(",",","); + put("-","-"); + put(".","."); + put("/","/"); + put(":",":"); + put(";",";"); + put("<","<"); + put("=","="); + put(">",">"); + put("?","?"); + put("@","@"); + put("[","["); + put("\\","\"); + put("]","]"); + put("^","^"); + put("_","_"); + put("`","`"); + put("{","{"); + put("|","|"); + put("}","}"); + put("~","~"); + } +} +/** + +Special Case: + +### + +. +{ +### +oced +### +. +### +code +### +. +### +fizz +### +} +. +### + + +*/
\ No newline at end of file diff --git a/parsers/Header.java b/parsers/Header.java index 50575c1..88316d5 100644 --- a/parsers/Header.java +++ b/parsers/Header.java @@ -37,6 +37,7 @@ public class Header implements Parser { sbuilder.append("<head> \n"); sbuilder.append("<meta charset=\"UTF-8\">\n"); sbuilder.append(" <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" /> \n"); + sbuilder.append("<meta name=\"author\" content=\""+PresentFile.author+"\">\n"); sbuilder.append("<title>"); sbuilder.append(PresentFile.name); sbuilder.append("</title>"); @@ -47,13 +48,6 @@ public class Header implements Parser { // insert File Content. sbuilder.append(fileContent); sbuilder.append("</article>\n"); - // add "powered by scruf" at bottom of page. - sbuilder.append("\n<div class=\"scruf\">\n"); - sbuilder.append("<a href=\"http://nongnu.org/scruf/\">powered by scruf</a>"); - sbuilder.append("\n</div>\n"); - // Close body tag - sbuilder.append("\n</body>\n"); - sbuilder.append("</html>\n"); return sbuilder.toString(); } diff --git a/parsers/LastUpdate.java b/parsers/LastUpdate.java new file mode 100644 index 0000000..4d9f168 --- /dev/null +++ b/parsers/LastUpdate.java @@ -0,0 +1,51 @@ +/*+ + * Copyright 2012 rsiddharth + * Email: <rsiddharth@ninthfloor.org> + * + * This file is part of Scruf. + * + * Scruf is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +package scruf.parsers; + +import java.text.*; +import java.util.*; + +/** + * This class produces a string of the current date. This 'current + * date' string is used append at end of the html page page. + */ + +class LastUpdate implements Parser { + private String startBlock, endBlock; + private DateFormat date; + private StringBuilder sbuilder; + public LastUpdate() { + sbuilder = new StringBuilder(); + startBlock = "\n<div class=\"lastupdate\">\n Last Updated on: "; + date = DateFormat.getDateInstance(DateFormat.LONG); + endBlock = "</div>\n"; + } + public String parse(String fileContent) { + sbuilder.delete(0,sbuilder.length()); + sbuilder.append(fileContent); + sbuilder.append(startBlock); + // date.format() returns the date at this instance in time. + sbuilder.append(date.format(new Date())); + sbuilder.append(endBlock); + return sbuilder.toString(); + } +} diff --git a/parsers/MetaParser.java b/parsers/MetaParser.java new file mode 100644 index 0000000..4ac9394 --- /dev/null +++ b/parsers/MetaParser.java @@ -0,0 +1,60 @@ +/*+ + * Copyright 2012 rsiddharth + * Email: <rsiddharth@ninthfloor.org> + * + * This file is part of Scruf. + * + * Scruf is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +package scruf.parsers; + +import java.util.regex.*; +import scruf.status.*; + +/** + * this class deals with searching the 'scruffy' marked-up document + * for meta-tag related things. + */ + +public class MetaParser implements Parser { + private Pattern pattern; + private Matcher matcher; + private NullIt nullIt; + public MetaParser() { + pattern = Pattern.compile("^meta\\-(.+?)\\:(.+)", + Pattern.MULTILINE); + nullIt = new NullIt(); + + } + public String parse(String fileContent) { + String value; + matcher = pattern.matcher(fileContent); + while(matcher.find()) { + value = matcher.group(2); + if(matcher.group(1).equals("author")) { + PresentFile.author = value; + } + else if(matcher.group(1).equals("title")) { + PresentFile.name = value; + } + // remove the found 'meta' markup to an empty string. + fileContent = nullIt.nullIt(fileContent,matcher.group()); + // reset the matcher with the new file Content. + matcher.reset(fileContent); + } + return fileContent; + } +} diff --git a/parsers/ParserList.java b/parsers/ParserList.java index 999dadc..8691cdd 100644 --- a/parsers/ParserList.java +++ b/parsers/ParserList.java @@ -29,18 +29,20 @@ public class ParserList { parsers = new ArrayList<Parser>(); // add Parsers. NOTE: parser order is significant. parsers.add(new QuoteSpecialText()); - parsers.add(new DocumentName()); + parsers.add(new CodeBlocks()); + parsers.add(new MetaParser()); parsers.add(new DocumentDate()); parsers.add(new WordDecoration()); - parsers.add(new CodeBlocks()); parsers.add(new Headings()); - parsers.add(new Links()); + parsers.add(new Links()); parsers.add(new Images()); parsers.add(new Footer()); parsers.add(new Paragraphs()); parsers.add(new Source()); parsers.add(new BackButton()); parsers.add(new Header()); + parsers.add(new LastUpdate()); + parsers.add(new CloseHtmlTags()); } public List<Parser> list() { return new ArrayList<Parser>(parsers); diff --git a/parsers/QuoteSpecialText.java b/parsers/QuoteSpecialText.java index 165ffa9..76241cc 100644 --- a/parsers/QuoteSpecialText.java +++ b/parsers/QuoteSpecialText.java @@ -33,10 +33,10 @@ public class QuoteSpecialText implements Parser { qmap.put(">",">"); } public String parse(String fileContent) { - Pattern pattern = Pattern.compile("(\\&)|(\\<)|(\\>)"); + Pattern pattern = Pattern.compile("(\\&\\#35\\;)|(\\&)|(\\<)|(\\>)"); Matcher matcher = pattern.matcher(fileContent); StringBuffer sbuffer = new StringBuffer(); - while(matcher.find()) { + while(matcher.find() && matcher.group(1)==null) { matcher.appendReplacement(sbuffer, qmap.get(matcher.group())); } diff --git a/status/PresentFile.java b/status/PresentFile.java index 303d4bc..2e1a690 100644 --- a/status/PresentFile.java +++ b/status/PresentFile.java @@ -30,6 +30,7 @@ import java.io.*; */ public class PresentFile { public static String name; + public static String author; public static File file; } diff --git a/styling/style.css b/styling/style.css index 02e71af..cbcf51f 100644 --- a/styling/style.css +++ b/styling/style.css @@ -71,7 +71,7 @@ div.code { margin-right:auto; border:1px; padding:5px; - width:65%; + width:70%; } div.time { @@ -130,6 +130,30 @@ footer { margin-right:auto; border:1px; padding:5px; + width:45%; +} + +div.lastupdate { + font-size:0.6em; + font-family:"Palatino Linotype","Book Antiqua",Palatino,"URW Palladio L",FreeSerif,serif; + text-align:center; + color:#989898; + margin-left:auto; + margin-right:auto; + border:1px; + padding:5px; + width:40%; +} + +div.source { + font-size:0.4em; + font-family:monospace; + text-align:center; + color:#989898; + margin-left:auto; + margin-right:auto; + border:1px; + padding:5px; width:40%; } @@ -1,17 +1,43 @@ -# 'quote' special symbols inside a code-block. +SCRUF - TODO -*- mode: org; -*- -# introduce 'meta' info in html doc generated -- authorinfo, date of creation, etc. +* features -* introduction to 'scruf' & 'scruffy' mark-up. [working on this one] +** implement lists + introduce mark-up for lists. Weird that I have not implement + yet. -# Test it by generating your _full_ homepage using scruf. -[done] way to ignore directories +** [hp] documentation -[done] move PresentFile.java to status/ + introduction to 'scruf' & 'scruffy' mark-up. [started writing, but + might not get it done anytime in the near future.] + +* testing -[done] extension for scruff marked-up files to make discovery easier. +** build homepage + Test it by generating your _full_ homepage using scruf. -[done] modify conversion/CanConvert.java (bug) +* finished todos + +** [done] ignore directories + way to ignore directories -[done] include a link or something to view the 'source'.
\ No newline at end of file +** [done] move PresentFile.java to status/ + +** [done] extension for scruffy files + extension for scruff marked-up files to make discovery easier. + +** [done] modify conversion/CanConvert.java (bug) + +** [done] link to scruffy source + include a link or something to view the 'source'. + +** [done] 'quote' special symbols inside a code-block. +** [done] 'last update' string + the 'last updated' string must be dangled somewhere in the document + that is licked by scruf. + +** [done] <meta> tags + introduce 'meta' info in html doc generated -- authorinfo. + + |