From f6f99c41dbd86f85ce816ea8d388e44e04aed6cc Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 27 Oct 2012 16:34:13 +0530 Subject: modified: .bzrignore conversion/ConvertDirectory.java (bug-fix) It is checked whether file "index" is modified since the last conversion. This check was not performed before. conversion/ConvertFile.java Some optimization there. Now we check if the file content is "empty" before we delve into conversion. index/IndexCreator.java # "index" file is created in the directory, if it is not created. # write() renamed to shouldConvert(). The method now returns true when a link is added to 'index' or when the index.html file does not exists. io/ReadFile.java # Exception message for made verbose. todo --- index/IndexCreator.java | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'index') diff --git a/index/IndexCreator.java b/index/IndexCreator.java index fc469ce..f86f03a 100644 --- a/index/IndexCreator.java +++ b/index/IndexCreator.java @@ -33,13 +33,20 @@ public class IndexCreator { // 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"); + indexContent = new StringBuilder(); + if(index.exists()) { + indexContent.append(new ReadFile(index). + getContent()); + }else { + try { + index.createNewFile(); + }catch(IOException e) { + throw new RuntimeException("Unable to create file: "+ + index.getAbsolutePath(),e); + } + } } public void add(File file) { String fileName = file.getName(); @@ -53,10 +60,20 @@ public class IndexCreator { modified=true; } } - public boolean write() { + public boolean shouldConvert() { + // we assume that index.html exists. + boolean indexHTMLExists=true; if(modified) new WriteFile(index,indexContent.toString()).write(); - return modified; + // Check for this existence of index.html. + if(!(new File(directory,"index.html").exists())) { + indexHTMLExists=false; + } + /** + * returns true either when 'index' is modified or + * when index.html does not exists. + */ + return (modified || !indexHTMLExists); } public File indexFile() { return index; -- cgit v1.2.3 From 1f61844084d9e9383b3be04ff8f60c11eb628075 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Wed, 31 Oct 2012 22:00:35 +0530 Subject: modified: conversion/ConvertDirectory.java (minor edit) index/IndexCreator.java (removed code which (1) creates a index file, if it is not present (2) checks for the existence of index.html) io/WriteFile.java (made the stdout message more verbose) parsers/Header.java ('scruf' footer links to scruf's project page) todo (1 task completed) --- index/IndexCreator.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'index') diff --git a/index/IndexCreator.java b/index/IndexCreator.java index f86f03a..ef683f7 100644 --- a/index/IndexCreator.java +++ b/index/IndexCreator.java @@ -39,13 +39,6 @@ public class IndexCreator { if(index.exists()) { indexContent.append(new ReadFile(index). getContent()); - }else { - try { - index.createNewFile(); - }catch(IOException e) { - throw new RuntimeException("Unable to create file: "+ - index.getAbsolutePath(),e); - } } } public void add(File file) { @@ -61,19 +54,9 @@ public class IndexCreator { } } public boolean shouldConvert() { - // we assume that index.html exists. - boolean indexHTMLExists=true; if(modified) new WriteFile(index,indexContent.toString()).write(); - // Check for this existence of index.html. - if(!(new File(directory,"index.html").exists())) { - indexHTMLExists=false; - } - /** - * returns true either when 'index' is modified or - * when index.html does not exists. - */ - return (modified || !indexHTMLExists); + return (modified); } public File indexFile() { return index; -- cgit v1.2.3 From ceed73fa063ffb3b72d21c8a8800122c115acc58 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 10 Nov 2012 11:29:31 +0530 Subject: 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) --- index/IndexCreator.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'index') 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; } -- cgit v1.2.3