summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <rsiddharth@ninthfloor.org>2012-11-29 19:56:36 +0530
committerrsiddharth <rsiddharth@ninthfloor.org>2012-11-29 19:56:36 +0530
commit502ca4ede537f3df715f235922fb78d05dcdaa2f (patch)
tree08105035db8e666389feb4fcbaa980fe3d00c395
parent0637e50adf2490a98695bd3b63db12f32f8af631 (diff)
parentbb6f34f8f3b5e77bd00e9439e205bd1b6334fce8 (diff)
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
-rw-r--r--conversion/ConvertFile.java2
-rw-r--r--index/IndexCreator.java2
-rw-r--r--parsers/CloseHtmlTags.java (renamed from parsers/DocumentName.java)35
-rw-r--r--parsers/CodeBlocks.java85
-rw-r--r--parsers/Header.java8
-rw-r--r--parsers/LastUpdate.java51
-rw-r--r--parsers/MetaParser.java60
-rw-r--r--parsers/ParserList.java8
-rw-r--r--parsers/QuoteSpecialText.java4
-rw-r--r--status/PresentFile.java1
-rw-r--r--styling/style.css26
-rw-r--r--todo44
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("!","&#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/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(">","&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
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%;
}
diff --git a/todo b/todo
index a15e999..6c20aab 100644
--- 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.
+
+