summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <rsiddharth@ninthfloor.org>2012-11-10 17:31:36 +0530
committerrsiddharth <rsiddharth@ninthfloor.org>2012-11-10 17:31:36 +0530
commit0637e50adf2490a98695bd3b63db12f32f8af631 (patch)
tree18446a430ad8c17833bb23a4e95383d8c9e2ca0d
parentd2f10460050965fa11e046bd6967b08a0e5e49b7 (diff)
parentab443161eaa4cb631423884972108785ce764269 (diff)
merged from devel branch
-rw-r--r--.bzrignore1
-rw-r--r--Scruf.java2
-rw-r--r--abstract120
-rw-r--r--conversion/CanConvert.java3
-rw-r--r--conversion/ConvertDirectory.java25
-rw-r--r--conversion/ConvertFile.java41
-rw-r--r--conversion/CreateHtmlFile.java51
-rw-r--r--conversion/FileSieve.java14
-rw-r--r--conversion/ignore/Ignored.java54
-rw-r--r--docs/scruf88
-rw-r--r--index/IndexCreator.java25
-rw-r--r--io/ReadFile.java2
-rw-r--r--io/WriteFile.java2
-rw-r--r--license/Liberate.java2
-rw-r--r--parsers/BackButton.java30
-rw-r--r--parsers/CodeBlocks.java7
-rw-r--r--parsers/DocumentDate.java23
-rw-r--r--parsers/DocumentName.java2
-rw-r--r--parsers/Footer.java9
-rw-r--r--parsers/Header.java11
-rw-r--r--parsers/ParserList.java4
-rw-r--r--parsers/QuoteSpecialText.java46
-rw-r--r--parsers/Source.java36
-rw-r--r--status/DirectoryInfo.java31
-rw-r--r--status/PresentFile.java (renamed from io/PresentFile.java)4
-rw-r--r--styling/style.css45
-rw-r--r--todo19
27 files changed, 486 insertions, 211 deletions
diff --git a/.bzrignore b/.bzrignore
index e19e389..499a518 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -1,2 +1,3 @@
scribble
*.class
+test
diff --git a/Scruf.java b/Scruf.java
index d632faf..fc8b310 100644
--- a/Scruf.java
+++ b/Scruf.java
@@ -25,6 +25,7 @@ import java.io.*;
import scruf.io.*;
import scruf.conversion.*;
import scruf.styling.*;
+import scruf.status.*;
import scruf.index.*;
public class Scruf {
@@ -43,6 +44,7 @@ public class Scruf {
}
directory = new File(dir).getAbsoluteFile();
styleSheet.resolve(directory);
+ DirectoryInfo.level=0;
html.convert(directory);
}
}
diff --git a/abstract b/abstract
deleted file mode 100644
index c85d7ae..0000000
--- a/abstract
+++ /dev/null
@@ -1,120 +0,0 @@
- Project Scruf.
-
- What.
-
-This is a "just for fun" project aiming at converting plain text
-documents to html web pages. We are are focusing on producing
-fundamental and simple web-pages which are clean, yet simple, we will
-be using CSS to ease down on the design and the format of the web-pages
-that are produced by the program.
-
-The plain text document will contain mark-ups that are to frilled by
-the user for the program to identify different elements of the
-document. For instance, a <h2> heading should be surrounded by the
-'==', as it is evident, the number of equals sign (=) is equal to the
-heading number, a <h4> heading should be surrounded '===='.
-
-
- An illustration.
-
- a marked-up plain text document.
-
-
-== heading two ==
-
-this is paragraph *one*.
-
-this is paragraph _three_.
-
-Do you know how to /count/ ?.
-
- the html-converted plain text document.
-
-<html>
-<body>
- <p>this is paragraph <b>one</b>. </p>
-
- <p>this is paragraph <u>three</u> </p>
-
- <p>Do you know how to <i>count</i>
-
-</body>
-</html>
-
-
-<!-- As it is evident from the above html snippet that the paragraphs
-are surrounded by the <p> tag, words surrounded by a '*' is made bold,
-words surrounded by the '_' is underlined, words surrounded by '/' is
-italized. The role of our conversion program will be to identify these
-mark-ups ind the plain text document and according produce to needed
-html tag for that mark up. -->
-
- Why.
-
-So why should we write a html conversion program from the scratch when
-we have awesome suites like WordPress and the like. Why re-invent the
-wheel ?.
-
-Here are few reasons by we desire to write from scratch :
-
- * If we have to adapt or modify an already existing converter, we
- need to bunch of source files before we can even start thinking
- about how to adapt it. It takes a lot of time to adapt
- specifically to our needs.
-
- * This project aims to project a very very simple, clean and
- small blogging program which can cater to the user without
- the need MySQL, PHP or other complex programs.
-
- * We didn't start this project without a purpose, siddharth
- wishes to exploit the html converter to host his verbal rambles
- on his web site.
-
- How.
-
-How are we going to crunch this project ?. What follows gives some
-details about the project.
-
- Platform
-
-The program will be compatible on GNU/Linux machines. We don't have
-plans to have support for Windows/ Mac OSX machines.
-
- Programming Language.
-
-The suite will be written in the (filthy) Java programming
-language. OpenJDK 6.0 will be used for compiling the programs.
-
- Cascading Style Sheets.
-
-The project will also write simple and clean stylesheets for properly
-formatting and frilling the html documents that are produced by the
-programs.
- Documentation.
-
-A minimalistic documentation to learn the mark-ups will be made
-available for the user to start writing marked-up plain text documents
-ready for html conversion.
-
- Who
-
- Who is behind this project anyway ?.
-
-
- * Sury Narayanan : He will responsible for writing
- stylesheet to decorate the html docs.
-
- * Saravana Bharathy : He will writing the documentation for
- the mark-ups for the plain text document.
-
- * Siddharth : He will be writing code for the project and he
- will be the first user of the html converter.
-
-
- Licensing.
-
-All programs written under the project scruf will be licensed under
-the GNU General Public License v3 or later.
-
-
- \ No newline at end of file
diff --git a/conversion/CanConvert.java b/conversion/CanConvert.java
index baf62c5..8f704e7 100644
--- a/conversion/CanConvert.java
+++ b/conversion/CanConvert.java
@@ -25,9 +25,10 @@ import java.io.*;
public class CanConvert {
private File htmlFile;
+ private CreateHtmlFile createHtml = new CreateHtmlFile();
private long modified1, modified2;
public boolean check(File file) {
- htmlFile = new File(file.getAbsolutePath()+".html");
+ htmlFile = createHtml.create(file);
modified1 = file.lastModified();
modified2 = htmlFile.lastModified();
if(modified1 > modified2) {
diff --git a/conversion/ConvertDirectory.java b/conversion/ConvertDirectory.java
index 3cc6a36..a5717bb 100644
--- a/conversion/ConvertDirectory.java
+++ b/conversion/ConvertDirectory.java
@@ -23,6 +23,8 @@ package scruf.conversion;
import java.io.*;
import scruf.index.*;
+import scruf.status.*;
+import scruf.conversion.ignore.*;
public class ConvertDirectory {
private ConvertFile html;
@@ -38,25 +40,38 @@ public class ConvertDirectory {
" No conversion done on.");
return;
}
+ // Ignored object maintains a list of 'ignored' sub-directories
+ // in this directory.
+ Ignored ignored = new Ignored(directory);
// index creator for the present directory.
IndexCreator index = new IndexCreator(directory);
// iterate through the directory.
+ System.out.println("Current Directory: "+directory.getAbsolutePath());
for(File file:directory.listFiles(new FileSieve())) {
if(file.isFile()) {
can = canConvert.check(file);
if(can) {
- System.out.println("Converting..."+file.getName());
+ System.out.println("Converting..."+file.getAbsolutePath());
html.convert(file);
index.add(file);
}
}
else if(file.isDirectory()) {
- this.convert(file);
+ // Perform conversion, only if, directory
+ // is not a ignored directory.
+ if(!ignored.ignored(file)) {
+ ++DirectoryInfo.level;
+ this.convert(file);
+ }
}
}
-
- boolean modified = index.write();
- if(modified)
+ boolean convertIndex = (index.shouldConvert() ||
+ canConvert.check(index.indexFile()));
+ if(convertIndex) {
+ System.out.println("Converting..."+index.indexFile().getAbsolutePath());
html.convert(index.indexFile());
+ }
+ --DirectoryInfo.level;
}
+
}
diff --git a/conversion/ConvertFile.java b/conversion/ConvertFile.java
index 37da060..5065ad0 100644
--- a/conversion/ConvertFile.java
+++ b/conversion/ConvertFile.java
@@ -25,33 +25,32 @@ import scruf.io.*;
import scruf.parsers.*;
import java.util.*;
import java.io.*;
+import scruf.status.*;
public class ConvertFile {
private List<Parser> parsers;
private ReadFile readFile;
+ private CreateHtmlFile htmlFile;
public ConvertFile() {
- parsers = new ParserList().list();
+ parsers = new ParserList().list();
+ htmlFile = new CreateHtmlFile();
}
public void convert(File file) {
- /**
- * footer is optional, so it is null
- * by default.
- */
- PresentFile.footer = null;
- /**
- * takes the present file reference
- * for use outside this method.
- */
- PresentFile.file = file;
- readFile = new ReadFile(file);
- String fileContent = readFile.getContent();
- // start conversion.
- for(Parser p:parsers) {
- fileContent = p.parse(fileContent);
- }
-
- // Write converted file to respective html file.
- File outputFile = new File(file.getAbsolutePath()+".html");
- new WriteFile(outputFile,fileContent).write();
+ /**
+ * takes the present file reference
+ * for use outside this method.
+ */
+ PresentFile.file = file;
+ readFile = new ReadFile(file);
+ String fileContent = readFile.getContent();
+ if(!fileContent.equals("")) {
+ // start conversion.
+ for(Parser p:parsers) {
+ fileContent = p.parse(fileContent);
+
+ }
+ }
+ // Write to corresponding html file.
+ new WriteFile(htmlFile.create(),fileContent).write();
}
}
diff --git a/conversion/CreateHtmlFile.java b/conversion/CreateHtmlFile.java
new file mode 100644
index 0000000..729b3cf
--- /dev/null
+++ b/conversion/CreateHtmlFile.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.conversion;
+
+import java.io.*;
+import java.util.regex.*;
+import scruf.status.*;
+
+public class CreateHtmlFile {
+ private Pattern pattern = Pattern.compile("(.+?\\.)scruffy");
+ private Matcher matcher;
+ private File htmlFile=null;
+ /**
+ * This method uses PresentFile.file as the 'file' for
+ * which a corresponding 'htmlFile' has to be created.
+ */
+ public File create() {
+ return create(PresentFile.file);
+ }
+ public File create(File file) {
+ htmlFile=null;
+ matcher = pattern.matcher(file.getName());
+ if(matcher.find()) {
+ htmlFile = new File(file.getParentFile(),
+ matcher.group(1)+"html");
+ }else {
+ System.err.println("ERROR: something wrong with scruf: unable to create html file"+
+ " for "+PresentFile.file.getName());
+ }
+ return htmlFile;
+ }
+}
diff --git a/conversion/FileSieve.java b/conversion/FileSieve.java
index 8d53648..3571433 100644
--- a/conversion/FileSieve.java
+++ b/conversion/FileSieve.java
@@ -28,9 +28,19 @@ public class FileSieve implements FileFilter {
// this method return true, if this file doesn't represent
// a html file.
public boolean accept(File pathname) {
- Pattern pattern = Pattern.compile("(.+\\.(html|png|jpg|css|tar|ttf))|(.+?\\~)|(index)|(\\..+)|(\\#.+?\\#)");
+ // check if this is a directory, if yes, accept immediately.
+ if(pathname.isDirectory() && (!pathname.isHidden())) {
+ return true;
+ }
+ Pattern pattern = Pattern.compile(".+?\\.scruffy$");
+ Pattern indexPattern = Pattern.compile("^index\\.scruffy$");
Matcher matcher = pattern.matcher(pathname.getName());
+ Matcher indexMatcher = indexPattern.matcher(pathname.getName());
boolean bool = matcher.find();
- return !bool;
+ if(bool) {
+ // don't 'accept' if the file is 'index.scruffy'.
+ bool = !(indexMatcher.find());
+ }
+ return bool;
}
}
diff --git a/conversion/ignore/Ignored.java b/conversion/ignore/Ignored.java
new file mode 100644
index 0000000..a13434e
--- /dev/null
+++ b/conversion/ignore/Ignored.java
@@ -0,0 +1,54 @@
+/*+
+ * 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.conversion.ignore;
+
+import java.io.*;
+import scruf.io.*;
+
+public class Ignored {
+ private String ignoredList[];
+ public Ignored(File directory) {
+ File ignoredFile = new File(directory,".ignored");
+ if(ignoredFile.exists()) {
+ ignoredList = new ReadFile(ignoredFile).split("\n");
+ }
+ }
+ public boolean ignored(File subdirectory) {
+ boolean ignored = false;
+ if(ignoredList!=null) {
+ for(String dir:ignoredList) {
+ if(subdirectory.getName().matches(dir)) {
+ System.out.println("Ignoring Directory: "+
+ subdirectory.getAbsolutePath());
+ ignored = true;
+ break;
+ }
+ }
+ }
+ return ignored;
+ }
+}
+
+/**
+ CVS/
+ /home/rsd/projects/scruf/www/CVS/
+ */
diff --git a/docs/scruf b/docs/scruf
new file mode 100644
index 0000000..63f0b3e
--- /dev/null
+++ b/docs/scruf
@@ -0,0 +1,88 @@
+scruf - documentation
+
+==========
+scruf - documentation
+==========
+
+ ''scruf'' is a simple program that converts text marked-up in
+''scruffy'' mark-up to HTML5 files. It was written specifically for
+generating blog posts. The way ''scruf'' works is straight forward --
+it takes in directory and converts all the ''scruffy'' marked-up
+plain-text files into corresponding HTML5 files. After the conversion,
+''scruf'' puts links to the generated HTML5 files in the `index.html`
+file of that directory. So, that's how ''scruf'' works.
+
+====================
+using scruf
+====================
+
+Before you plunge into learning about scruf and eventually using
+it. Let me run you through the pre-requisites.
+
+ '''Paraphernalia''': ''scruf'' is written in Java, therefore, you'll
+ need the `openjdk` package, inorder to be able to compile and run
+ scruf. Go ahead and install `openjdk` before proceeding
+ forward. Number two, ''scruf'' was written on a GNU/Linux machine,
+ so, it should work well on all Unix-based operating systems.
+
+Once, you have a copy of `openjdk` installed on your machine, you're
+all set to start licking ''scruf''. Here we go.
+
+==============================
+scruffy mark-up
+==============================
+
+Inorder to convert plain-text files into HTML5 using ''scruf'', you
+got to mark it up with the ''scruff'' mark-up, so that ''scruf''
+understands the elements of the plain-text document and duly converts
+them into HTML5. As the name suggests ''scruffy'' mark is pretty
+shabby when compared to cleaner mark-ups like
+[[http://daringfireball.net/projects/markdown/|Markdown]]. ''scruffy''
+is inspired, to an extent, from [[http://moinmo.in/|MoinMoin]] &
+[[http://www.mediawiki.org/wiki/MediaWiki|MediaWiki]] syntax.
+
+
+========================================
+basic structure
+========================================
+
+The ''scruffy'' plain-text document that is going to be converted by
+''scruf'', follows a format and here it is:
+
+###
+
+title
+
+==========
+foo heading
+==========
+
+$$$ 1 January 1970 $$$
+
+The bar blog post goes like this...
+...
+...
+the bar blog post ends
+
+----------------------------------------------------------------------
+author's signature
+----------------------------------------------------------------------
+
+###
+
+The first line in the ''scruffy'' document __must__ always begin with
+the text of the title of the document. The ''title'' is the string
+that is going to be displayed on the browser tabs and for compliance
+sake, it is recommended that it be same as the ''heading'' of the
+''scruffy'' document. Followed by the ''title'' is the heading, then
+the body of the post/essay/whatever and finally the author's
+signature. This is the basic structure of a ''scruffy'' document.
+
+
+========================================
+syntax
+========================================
+
+==============================
+running scruf
+==============================
diff --git a/index/IndexCreator.java b/index/IndexCreator.java
index fc469ce..e06db24 100644
--- a/index/IndexCreator.java
+++ b/index/IndexCreator.java
@@ -25,35 +25,38 @@ import java.io.*;
import java.util.regex.*;
import scruf.io.*;
import scruf.conversion.*;
+import scruf.status.*;
public class IndexCreator {
private File directory;
private File index;
+ private CreateHtmlFile htmlFile;
private StringBuilder indexContent;
// set to true, if index file is modified.
boolean modified = false;
public IndexCreator(File directory) {
- this.directory = directory;
- index = new File(directory,"index");
- indexContent = new StringBuilder();
- if(index.exists()) {
- indexContent.append(new ReadFile(index).
- getContent());
- }
+ this.directory = directory;
+ index = new File(directory,"index.scruffy");
+ indexContent = new StringBuilder();
+ if(index.exists()) {
+ indexContent.append(new ReadFile(index).
+ getContent());
+ }
+ htmlFile = new CreateHtmlFile();
}
public void add(File file) {
- String fileName = file.getName();
+ String fileName = htmlFile.create().getName();
if(shouldAdd(fileName)) {
System.out.println("New Entry: "+fileName);
indexContent.append("[[./");
- indexContent.append(fileName+".html");
+ indexContent.append(fileName);
indexContent.append("|");
indexContent.append(PresentFile.name);
indexContent.append("]]\n");
modified=true;
}
}
- public boolean write() {
+ public boolean shouldConvert() {
if(modified)
new WriteFile(index,indexContent.toString()).write();
return modified;
@@ -67,7 +70,7 @@ public class IndexCreator {
boolean check1 = !(Pattern.compile(regex).
matcher(indexContent.toString()).find());
// checks if fileName is index itself.
- boolean check2 = !(Pattern.matches(fileName,"index"));
+ boolean check2 = !(Pattern.matches(fileName,"index.scruffy"));
boolean add = (check1 && check2);
return add;
}
diff --git a/io/ReadFile.java b/io/ReadFile.java
index beccdc3..2607b16 100644
--- a/io/ReadFile.java
+++ b/io/ReadFile.java
@@ -44,7 +44,7 @@ public class ReadFile {
new FileReader(file));
}catch(FileNotFoundException e) {
throw new RuntimeException("Unable to open file :"
- +file.getName());
+ +file.getAbsolutePath());
}
String line;
StringBuilder sbuilder = new StringBuilder();
diff --git a/io/WriteFile.java b/io/WriteFile.java
index d19bb72..0a2a1e7 100644
--- a/io/WriteFile.java
+++ b/io/WriteFile.java
@@ -32,7 +32,7 @@ public class WriteFile {
}
public void write() {
try {
- System.out.println("Writing..."+outputFile.getName());
+ System.out.println("Writing..."+outputFile.getAbsolutePath());
BufferedWriter bwriter = new BufferedWriter
(new FileWriter(outputFile));
// write content to file.
diff --git a/license/Liberate.java b/license/Liberate.java
index c7d1222..22ab291 100644
--- a/license/Liberate.java
+++ b/license/Liberate.java
@@ -67,7 +67,7 @@ public class Liberate {
public static void main(String[] args) {
Liberate libre = new Liberate();
- libre.baptize("./scruf/",".+\\.java");
+ libre.baptize("./scruf/",".+\\.java$");
}
} \ No newline at end of file
diff --git a/parsers/BackButton.java b/parsers/BackButton.java
index 6dd37d1..e504648 100644
--- a/parsers/BackButton.java
+++ b/parsers/BackButton.java
@@ -23,21 +23,27 @@ package scruf.parsers;
import java.io.*;
import scruf.io.*;
+import scruf.status.*;
public class BackButton implements Parser {
// this method doesn't modify the filContent.
public String parse(String fileContent) {
- StringBuilder button = new StringBuilder();
- button.append("\n<div class=\"back\">\n");
- button.append("<a href=\"");
- if(PresentFile.file.getName().equals("index")) {
- button.append("../\"> home ");
- }else {
- button.append("./\"> back ");
- }
- button.append("</a>\n");
- button.append("</div>\n");
- PresentFile.backButton = button.toString();
- return fileContent;
+ StringBuilder fileBuilder = new StringBuilder(fileContent);
+ /**
+ * Back button is added only if the present directory being
+ * parsed is not 'root'.
+ */
+ if(DirectoryInfo.level!=0) {
+ fileBuilder.append("\n<div class=\"back\">\n");
+ fileBuilder.append("<a href=\"");
+ if(PresentFile.file.getName().equals("index.scruffy")) {
+ fileBuilder.append("../\"> back ");
+ }else {
+ fileBuilder.append("./\"> back ");
+ }
+ fileBuilder.append("</a>\n");
+ fileBuilder.append("</div>\n");
+ }
+ return fileBuilder.toString();
}
}
diff --git a/parsers/CodeBlocks.java b/parsers/CodeBlocks.java
index 2c47099..64e8841 100644
--- a/parsers/CodeBlocks.java
+++ b/parsers/CodeBlocks.java
@@ -25,7 +25,7 @@ import java.util.regex.*;
public class CodeBlocks implements Parser {
public String parse(String fileContent) {
- Pattern pattern = Pattern.compile("(\\#\\#\\#)(.+?)(\\1)",
+ Pattern pattern = Pattern.compile("(\\#\\#\\#)(\\n+)(.+?)(\\n+)(\\1)",
Pattern.DOTALL);
Matcher matcher = pattern.matcher(fileContent);
LineBreak lbreak = new LineBreak();
@@ -34,7 +34,7 @@ public class CodeBlocks implements Parser {
while(matcher.find()) {
replacement.delete(0,replacement.length());
replacement.append("<div class=\"code\">");
- replacement.append(quote(lbreak.parse(matcher.group(2))));
+ replacement.append(lbreak.parse(quote(matcher.group(3))));
replacement.append("</div>");
matcher.appendReplacement(sbuffer,replacement.toString());
}
@@ -53,9 +53,8 @@ public class CodeBlocks implements Parser {
StringBuffer sbuffer = new StringBuffer();
String rep;
while(matcher.find()) {
- rep = "\\\\\\"+matcher.group();
+ rep = "\\\\\\"+matcher.group();
matcher.appendReplacement(sbuffer,rep);
-
}
matcher.appendTail(sbuffer);
return sbuffer.toString();
diff --git a/parsers/DocumentDate.java b/parsers/DocumentDate.java
index 717fe25..7b66caa 100644
--- a/parsers/DocumentDate.java
+++ b/parsers/DocumentDate.java
@@ -1,3 +1,24 @@
+/*+
+ * 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.*;
@@ -14,4 +35,4 @@ public class DocumentDate implements Parser {
matcher.appendTail(sbuffer);
return sbuffer.toString();
}
-} \ No newline at end of file
+}
diff --git a/parsers/DocumentName.java b/parsers/DocumentName.java
index 09eaf22..032d7c0 100644
--- a/parsers/DocumentName.java
+++ b/parsers/DocumentName.java
@@ -22,7 +22,7 @@
package scruf.parsers;
import java.io.*;
-import scruf.io.*;
+import scruf.status.*;
public class DocumentName implements Parser {
public String parse(String fileContent) {
diff --git a/parsers/Footer.java b/parsers/Footer.java
index 7f079bd..f8d85ae 100644
--- a/parsers/Footer.java
+++ b/parsers/Footer.java
@@ -28,11 +28,12 @@ public class Footer implements Parser {
Pattern pattern = Pattern.compile("\\-{70}\\n(.+)\\n\\-{70}");
Matcher matcher = pattern.matcher(fileContent);
StringBuffer sbuffer = new StringBuffer();
+ String footer=null;
while(matcher.find()) {
- PresentFile.footer = "\n<footer>"+matcher.group(1)+"</footer>\n";
- fileContent = new NullIt().nullIt(fileContent,matcher.group());
+ footer = "\n<footer>"+matcher.group(1)+"</footer>\n";
+ matcher.appendReplacement(sbuffer,footer);
}
-
- return fileContent;
+ matcher.appendTail(sbuffer);
+ return sbuffer.toString();
}
}
diff --git a/parsers/Header.java b/parsers/Header.java
index eebec5d..50575c1 100644
--- a/parsers/Header.java
+++ b/parsers/Header.java
@@ -21,7 +21,7 @@
package scruf.parsers;
-import scruf.io.*;
+import scruf.status.*;
public class Header implements Parser {
@@ -46,21 +46,14 @@ public class Header implements Parser {
sbuilder.append("<article>\n");
// insert File Content.
sbuilder.append(fileContent);
- // add footer if footer is available.
- if(PresentFile.footer!=null) {
- sbuilder.append(PresentFile.footer);
- }
- // insert back button.
- sbuilder.append(PresentFile.backButton);
sbuilder.append("</article>\n");
// add "powered by scruf" at bottom of page.
sbuilder.append("\n<div class=\"scruf\">\n");
- sbuilder.append("<a href=\"/scruf/\">powered by scruf</a>");
+ 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/ParserList.java b/parsers/ParserList.java
index f57a6b8..999dadc 100644
--- a/parsers/ParserList.java
+++ b/parsers/ParserList.java
@@ -28,15 +28,17 @@ public class ParserList {
public ParserList() {
parsers = new ArrayList<Parser>();
// add Parsers. NOTE: parser order is significant.
+ parsers.add(new QuoteSpecialText());
parsers.add(new DocumentName());
parsers.add(new DocumentDate());
parsers.add(new WordDecoration());
parsers.add(new CodeBlocks());
parsers.add(new Headings());
- parsers.add(new Paragraphs());
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());
}
diff --git a/parsers/QuoteSpecialText.java b/parsers/QuoteSpecialText.java
new file mode 100644
index 0000000..165ffa9
--- /dev/null
+++ b/parsers/QuoteSpecialText.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;
+
+import java.util.*;
+import java.util.regex.*;
+
+public class QuoteSpecialText implements Parser {
+ Map<String,String> qmap;
+ public QuoteSpecialText() {
+ qmap = new HashMap<String,String>();
+ qmap.put("&","&amp;");
+ qmap.put("<","&lt;");
+ qmap.put(">","&gt;");
+ }
+ public String parse(String fileContent) {
+ Pattern pattern = Pattern.compile("(\\&)|(\\<)|(\\>)");
+ Matcher matcher = pattern.matcher(fileContent);
+ StringBuffer sbuffer = new StringBuffer();
+ while(matcher.find()) {
+ matcher.appendReplacement(sbuffer,
+ qmap.get(matcher.group()));
+ }
+ matcher.appendTail(sbuffer);
+ return sbuffer.toString();
+ }
+}
diff --git a/parsers/Source.java b/parsers/Source.java
new file mode 100644
index 0000000..4dbe303
--- /dev/null
+++ b/parsers/Source.java
@@ -0,0 +1,36 @@
+/*+
+ * 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 scruf.status.*;
+
+public class Source implements Parser {
+ private StringBuilder sbuilder;
+ public String parse(String fileContent) {
+ sbuilder = new StringBuilder(fileContent);
+ // append a link to the source.
+ sbuilder.append("\n <div class=\"source\"> \n");
+ sbuilder.append("\n <a href=\"./"+PresentFile.file.getName()+
+ "\">source</a> \n </div>");
+ return sbuilder.toString();
+ }
+}
diff --git a/status/DirectoryInfo.java b/status/DirectoryInfo.java
new file mode 100644
index 0000000..d2cd191
--- /dev/null
+++ b/status/DirectoryInfo.java
@@ -0,0 +1,31 @@
+/*+
+ * 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.status;
+
+public class DirectoryInfo {
+ /**
+ * This variable stores the 'level' at which
+ * scruf is parsing the files with respect to
+ * root.
+ */
+ public static int level;
+}
diff --git a/io/PresentFile.java b/status/PresentFile.java
index 14ca7b5..303d4bc 100644
--- a/io/PresentFile.java
+++ b/status/PresentFile.java
@@ -19,7 +19,7 @@
*/
-package scruf.io;
+package scruf.status;
import java.io.*;
@@ -30,8 +30,6 @@ import java.io.*;
*/
public class PresentFile {
public static String name;
- public static String footer;
- public static String backButton;
public static File file;
}
diff --git a/styling/style.css b/styling/style.css
index 17e41a4..02e71af 100644
--- a/styling/style.css
+++ b/styling/style.css
@@ -1,8 +1,14 @@
+/*
+ Author: rsiddharth
+ Contact: <rsiddharth@ninthfloor.org>
+ License: Public Domain <http://creativecommons.org/publicdomain/zero/1.0/>
+
+*/
+
article {
- font-size:1.50em; /* 1.88 */
- font-style:normal;
+ font-size:1.50em; /* 1.88 */
font-family:"Palatino Linotype","Book Antiqua",Palatino,"URW Palladio L",FreeSerif,serif;
- color:#686868;
+ color:#787878;
margin-left:auto;
margin-right:auto;
border:1px;
@@ -11,14 +17,18 @@ article {
box-shadow: 1px 1.5px 3px 0.5px #bababa;
}
-h1, h2, h3, h4 {
+h1, h2, h3, h4, h5 {
margin-left:auto;
- margin-right:auto;
- border:1px;
+ margin-right:auto;
+ border:1px;
padding:5px;
width:75%;
text-align:center;
}
+h1 {
+ font-size:1.80em;
+}
+
p, i, b{
margin-left:auto;
margin-right:auto;
@@ -27,7 +37,7 @@ p, i, b{
width:70%;
text-align:justify;
line-height:170%;
- /*-moz-word-wrap:break-word;*/
+ -moz-word-wrap:break-word;
}
.center {
text-align:center;
@@ -36,7 +46,7 @@ p, i, b{
blockquote {
font-size:0.77em;
font-style:oblique;
- color:#787878;
+ color:#888888;
text-align:justify;
background-color:#fcfcfc;
margin-left:auto;
@@ -64,6 +74,18 @@ div.code {
width:65%;
}
+div.time {
+ font-size:0.50em;
+ font-family:"Palatino Linotype","Book Antiqua",Palatino,"URW Palladio L",FreeSerif,serif;
+ color:#aaaaaa;
+ margin-left:auto;
+ margin-right:auto;
+ border:1px;
+ padding:5px;
+ width:20%;
+ text-align:center;
+}
+
img {
margin-left:auto;
margin-right:auto;
@@ -71,6 +93,7 @@ img {
border: 1px;
padding: 10px;
}
+
a:link,a:visited {
transition:border-bottom 0.3s, color 0.3s;
-moz-transition:border-bottom 0.3s, color 0.3s;
@@ -87,10 +110,10 @@ a:hover,a:active {
}
div.back {
- font-size:0.9em;
+ font-size:0.7em;
font-family:junicode,"Palatino Linotype","Book Antiqua",Palatino,"URW Palladio L",FreeSerif,serif;
text-align:center;
- color:#686868;
+ color:#989898;
margin-left:auto;
margin-right:auto;
border:1px;
@@ -102,7 +125,7 @@ footer {
font-size:0.8em;
font-family:"Palatino Linotype","Book Antiqua",Palatino,"URW Palladio L",FreeSerif,serif;
text-align:center;
- color:#686868;
+ color:#989898;
margin-left:auto;
margin-right:auto;
border:1px;
diff --git a/todo b/todo
index f900683..a15e999 100644
--- a/todo
+++ b/todo
@@ -1,2 +1,17 @@
-IndexGenerator thingy has to be re-written. (why ? I seem to have
-forgotten, need to invistigate).
+# 'quote' special symbols inside a code-block.
+
+# introduce 'meta' info in html doc generated -- authorinfo, date of creation, etc.
+
+* introduction to 'scruf' & 'scruffy' mark-up. [working on this one]
+
+# Test it by generating your _full_ homepage using scruf.
+
+[done] way to ignore directories
+
+[done] move PresentFile.java to status/
+
+[done] extension for scruff marked-up files to make discovery easier.
+
+[done] modify conversion/CanConvert.java (bug)
+
+[done] include a link or something to view the 'source'. \ No newline at end of file