diff options
author | rsiddharth <rsiddharth@ninthfloor.org> | 2012-10-31 23:32:29 +0530 |
---|---|---|
committer | rsiddharth <rsiddharth@ninthfloor.org> | 2012-10-31 23:32:29 +0530 |
commit | e1804b3d0ef3be3db8be169043c6eae8a98bbc86 (patch) | |
tree | 028ceccfd1f006a051e789c081e539b234eaae61 | |
parent | 1f61844084d9e9383b3be04ff8f60c11eb628075 (diff) |
added:
status/
status/DirectoryInfo.java (record the directory 'level' at which
scruf is parsing with respect to 'root'
directory.)
modified:
Scruf.java (added a line to start the directory level count at zero)
conversion/ConvertDirectory.java (DirectoryInfo.level used to take
count of directory 'leve')
conversion/ConvertFile.java (lines related to 'footer' things were removed)
io/PresentFile.java ( 'footer' & 'backButton' field removed)
parsers/BackButton.java (back button placement happens in the parse
method itself, instead of doing it in Header.java)
(back button is not placed, if the present
directory is root directory)
parsers/Footer.java (footer placement happens in the parse
method itself, instead of doing it in Header.java)
parsers/Header.java (back button placement & footer placement removed.)
-rw-r--r-- | Scruf.java | 2 | ||||
-rw-r--r-- | conversion/ConvertDirectory.java | 13 | ||||
-rw-r--r-- | conversion/ConvertFile.java | 5 | ||||
-rw-r--r-- | io/PresentFile.java | 2 | ||||
-rw-r--r-- | parsers/BackButton.java | 30 | ||||
-rw-r--r-- | parsers/Footer.java | 8 | ||||
-rw-r--r-- | parsers/Header.java | 6 | ||||
-rw-r--r-- | status/DirectoryInfo.java | 10 |
8 files changed, 44 insertions, 32 deletions
@@ -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/conversion/ConvertDirectory.java b/conversion/ConvertDirectory.java index 3dbb8eb..2a0f6a9 100644 --- a/conversion/ConvertDirectory.java +++ b/conversion/ConvertDirectory.java @@ -23,6 +23,7 @@ package scruf.conversion; import java.io.*; import scruf.index.*; +import scruf.status.*; public class ConvertDirectory { private ConvertFile html; @@ -41,22 +42,28 @@ public class ConvertDirectory { // 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); + ++DirectoryInfo.level; + this.convert(file); } } boolean convertIndex = (index.shouldConvert() || canConvert.check(index.indexFile())); - if(convertIndex) + 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 6767717..4f2d7bd 100644 --- a/conversion/ConvertFile.java +++ b/conversion/ConvertFile.java @@ -34,11 +34,6 @@ public class ConvertFile { } 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. */ diff --git a/io/PresentFile.java b/io/PresentFile.java index 14ca7b5..9a3deaa 100644 --- a/io/PresentFile.java +++ b/io/PresentFile.java @@ -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/parsers/BackButton.java b/parsers/BackButton.java index 6dd37d1..0bba9b8 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")) { + fileBuilder.append("../\"> back "); + }else { + fileBuilder.append("./\"> back "); + } + fileBuilder.append("</a>\n"); + fileBuilder.append("</div>\n"); + } + return fileBuilder.toString(); } } diff --git a/parsers/Footer.java b/parsers/Footer.java index 7f079bd..6c1db65 100644 --- a/parsers/Footer.java +++ b/parsers/Footer.java @@ -28,11 +28,11 @@ 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; + return sbuffer.toString(); } } diff --git a/parsers/Header.java b/parsers/Header.java index 5cf2c55..3d9b846 100644 --- a/parsers/Header.java +++ b/parsers/Header.java @@ -46,12 +46,6 @@ 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"); diff --git a/status/DirectoryInfo.java b/status/DirectoryInfo.java new file mode 100644 index 0000000..eb65de8 --- /dev/null +++ b/status/DirectoryInfo.java @@ -0,0 +1,10 @@ +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; +}
\ No newline at end of file |