summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <rsiddharth@ninthfloor.org>2012-11-10 11:29:31 +0530
committerrsiddharth <rsiddharth@ninthfloor.org>2012-11-10 11:29:31 +0530
commitceed73fa063ffb3b72d21c8a8800122c115acc58 (patch)
treee6519430ea904e1e7842b17e1ad177a17ef5bfb4
parent00a25a7ef03e25864019ef2e4f3fe5813ec292e9 (diff)
marked-up files should have a '.scruffy' extension from now on. This
commit is an un-stable commit. It has bugs. removed: io/PresentFile.java (moved to status/PresentFile.java) added: conversion/CreateHtmlFile.java (creates a corresponding '.html' file for a given '.scruffy' marked-up file) (needs some fine-tuning) status/PresentFile.java (see above) modified: conversion/ConvertFile.java (CreatHtmlFile object takes care of producing a corresponding html 'File') conversion/FileSieve.java (regex modified to reflect the '.scruffy' extension) index/IndexCreator.java (edits to reflect the '.scruffy' extension) parsers/BackButton.java (edit to reflect the '.scruffy' extension) parsers/DocumentName.java (edit to reflect the package change for PresentFile class) parsers/Header.java (edit to reflect the package change for PresentFile class) todo (updated todo)
-rw-r--r--conversion/ConvertFile.java8
-rw-r--r--conversion/CreateHtmlFile.java22
-rw-r--r--conversion/FileSieve.java14
-rw-r--r--index/IndexCreator.java13
-rw-r--r--parsers/BackButton.java2
-rw-r--r--parsers/DocumentName.java2
-rw-r--r--parsers/Header.java2
-rw-r--r--status/PresentFile.java (renamed from io/PresentFile.java)2
-rw-r--r--todo14
9 files changed, 60 insertions, 19 deletions
diff --git a/conversion/ConvertFile.java b/conversion/ConvertFile.java
index 4f2d7bd..5065ad0 100644
--- a/conversion/ConvertFile.java
+++ b/conversion/ConvertFile.java
@@ -25,12 +25,15 @@ 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();
+ htmlFile = new CreateHtmlFile();
}
public void convert(File file) {
/**
@@ -47,8 +50,7 @@ public class ConvertFile {
}
}
- // Write converted file to respective html file.
- File outputFile = new File(file.getAbsolutePath()+".html");
- new WriteFile(outputFile,fileContent).write();
+ // 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..ecd86c1
--- /dev/null
+++ b/conversion/CreateHtmlFile.java
@@ -0,0 +1,22 @@
+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;
+ public File create() {
+ File htmlFile=null;
+ matcher = pattern.matcher(PresentFile.file.getName());
+ if(matcher.find()) {
+ htmlFile = new File(PresentFile.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;
+ }
+} \ No newline at end of file
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/index/IndexCreator.java b/index/IndexCreator.java
index ef683f7..e06db24 100644
--- a/index/IndexCreator.java
+++ b/index/IndexCreator.java
@@ -25,28 +25,31 @@ 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");
+ 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");
@@ -56,7 +59,7 @@ public class IndexCreator {
public boolean shouldConvert() {
if(modified)
new WriteFile(index,indexContent.toString()).write();
- return (modified);
+ return modified;
}
public File indexFile() {
return index;
@@ -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/parsers/BackButton.java b/parsers/BackButton.java
index 0bba9b8..e504648 100644
--- a/parsers/BackButton.java
+++ b/parsers/BackButton.java
@@ -36,7 +36,7 @@ public class BackButton implements Parser {
if(DirectoryInfo.level!=0) {
fileBuilder.append("\n<div class=\"back\">\n");
fileBuilder.append("<a href=\"");
- if(PresentFile.file.getName().equals("index")) {
+ if(PresentFile.file.getName().equals("index.scruffy")) {
fileBuilder.append("../\"> back ");
}else {
fileBuilder.append("./\"> back ");
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/Header.java b/parsers/Header.java
index 902d0c6..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 {
diff --git a/io/PresentFile.java b/status/PresentFile.java
index 9a3deaa..303d4bc 100644
--- a/io/PresentFile.java
+++ b/status/PresentFile.java
@@ -19,7 +19,7 @@
*/
-package scruf.io;
+package scruf.status;
import java.io.*;
diff --git a/todo b/todo
index 07afedf..d925074 100644
--- a/todo
+++ b/todo
@@ -1,13 +1,17 @@
-# 'quote' special symbols inside a code-block.
+# modify conversion/CanConvert.java (bug)
# include a link or something to view the 'source'. [working on this one]
-# introduce 'meta' info in html doc generated -- authorinfo, date of creation, etc.
-
--- way to ignore directories -- [done]
+# 'quote' special symbols inside a code-block.
-# extension for scruff marked-up files to make discovery easier.
+# 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. \ No newline at end of file