scruf

darn simple HTML5 doc generator
git clone git://git.ricketyspace.net/scruf.git
Log | Files | Refs | README

commit 502ca4ede537f3df715f235922fb78d05dcdaa2f
parent 0637e50adf2490a98695bd3b63db12f32f8af631
Author: rsiddharth <rsiddharth@ninthfloor.org>
Date:   Thu, 29 Nov 2012 19:56:36 +0530

removed:
  parsers/DocumentName.java
added:
  parsers/CloseHtmlTags.java
  parsers/LastUpdate.java
  parsers/MetaParser.java
modified:
  conversion/ConvertFile.java
  index/IndexCreator.java
  parsers/CodeBlocks.java
  parsers/Header.java
  parsers/ParserList.java
  parsers/QuoteSpecialText.java
  status/PresentFile.java
  styling/style.css
  todo

Diffstat:
conversion/ConvertFile.java | 2++
index/IndexCreator.java | 2+-
parsers/CloseHtmlTags.java | 46++++++++++++++++++++++++++++++++++++++++++++++
parsers/CodeBlocks.java | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
parsers/DocumentName.java | 39---------------------------------------
parsers/Header.java | 8+-------
parsers/LastUpdate.java | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
parsers/MetaParser.java | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
parsers/ParserList.java | 8+++++---
parsers/QuoteSpecialText.java | 4++--
status/PresentFile.java | 1+
styling/style.css | 26+++++++++++++++++++++++++-
todo | 45+++++++++++++++++++++++++++++++++++----------
13 files changed, 305 insertions(+), 73 deletions(-)

diff --git 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 @@ -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/CloseHtmlTags.java b/parsers/CloseHtmlTags.java @@ -0,0 +1,46 @@ +/*+ + * 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; + +/** + * this class, inserts the main content of the html into the <article> + * block. + */ + +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 @@ -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("!","&#33;"); + put("\"","&#34;"); + put("#","&#35;"); + put("$","&#36;"); + put("%","&#37;"); + put("&","&#38;"); + put("'","&#39;"); + put("(","&#40;"); + put(")","&#41;"); + put("*","&#42;"); + put("+","&#43;"); + put(",","&#44;"); + put("-","&#45;"); + put(".","&#46;"); + put("/","&#47;"); + put(":","&#58;"); + put(";","&#59;"); + put("<","&#60;"); + put("=","&#61;"); + put(">","&#62;"); + put("?","&#63;"); + put("@","&#64;"); + put("[","&#91;"); + put("\\","&#92;"); + put("]","&#93;"); + put("^","&#94;"); + put("_","&#95;"); + put("`","&#96;"); + put("{","&#123;"); + put("|","&#124;"); + put("}","&#125;"); + put("~","&#126;"); + } +} +/** + +Special Case: + +### + +. +{ +### +oced +### +. +### +code +### +. +### +fizz +### +} +. +### + + +*/+ \ No newline at end of file diff --git a/parsers/DocumentName.java b/parsers/DocumentName.java @@ -1,39 +0,0 @@ -/*+ - * 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.io.*; -import scruf.status.*; - -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; - } -} diff --git 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 @@ -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 @@ -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 @@ -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 @@ -33,10 +33,10 @@ public class QuoteSpecialText implements Parser { qmap.put(">","&gt;"); } 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 @@ -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 @@ -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%; } diff --git a/todo b/todo @@ -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. + +