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 --- conversion/ConvertDirectory.java | 5 +++-- conversion/ConvertFile.java | 44 +++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 23 deletions(-) (limited to 'conversion') diff --git a/conversion/ConvertDirectory.java b/conversion/ConvertDirectory.java index 3cc6a36..3b70a71 100644 --- a/conversion/ConvertDirectory.java +++ b/conversion/ConvertDirectory.java @@ -55,8 +55,9 @@ public class ConvertDirectory { } } - boolean modified = index.write(); - if(modified) + boolean convertIndex = (index.shouldConvert() || + canConvert.check(index.indexFile())); + if(convertIndex) html.convert(index.indexFile()); } } diff --git a/conversion/ConvertFile.java b/conversion/ConvertFile.java index 37da060..6767717 100644 --- a/conversion/ConvertFile.java +++ b/conversion/ConvertFile.java @@ -30,28 +30,30 @@ public class ConvertFile { private List parsers; private ReadFile readFile; public ConvertFile() { - parsers = new ParserList().list(); + parsers = new ParserList().list(); } 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(); + /** + * 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(); + if(!fileContent.equals("")) { + // 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(); } } -- 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) --- conversion/ConvertDirectory.java | 1 - 1 file changed, 1 deletion(-) (limited to 'conversion') diff --git a/conversion/ConvertDirectory.java b/conversion/ConvertDirectory.java index 3b70a71..3dbb8eb 100644 --- a/conversion/ConvertDirectory.java +++ b/conversion/ConvertDirectory.java @@ -54,7 +54,6 @@ public class ConvertDirectory { this.convert(file); } } - boolean convertIndex = (index.shouldConvert() || canConvert.check(index.indexFile())); if(convertIndex) -- cgit v1.2.3 From e1804b3d0ef3be3db8be169043c6eae8a98bbc86 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Wed, 31 Oct 2012 23:32:29 +0530 Subject: 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.) --- conversion/ConvertDirectory.java | 13 ++++++++++--- conversion/ConvertFile.java | 5 ----- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'conversion') 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 @@ -33,11 +33,6 @@ public class ConvertFile { parsers = new ParserList().list(); } 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. -- cgit v1.2.3 From 00a25a7ef03e25864019ef2e4f3fe5813ec292e9 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Fri, 9 Nov 2012 23:49:48 +0530 Subject: added: conversion/ignore/ conversion/ignore/Ignored.java (a class getting info about ignored child-directories, in the present directory) modified: conversion/ConvertDirectory.java (added code to check if the child-directory is in the ignored list) docs/scruf (started sketching out documentation on how to use scruf) styling/style.css todo --- conversion/ConvertDirectory.java | 12 ++++++++++-- conversion/ignore/Ignored.java | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 conversion/ignore/Ignored.java (limited to 'conversion') diff --git a/conversion/ConvertDirectory.java b/conversion/ConvertDirectory.java index 2a0f6a9..a5717bb 100644 --- a/conversion/ConvertDirectory.java +++ b/conversion/ConvertDirectory.java @@ -24,6 +24,7 @@ package scruf.conversion; import java.io.*; import scruf.index.*; import scruf.status.*; +import scruf.conversion.ignore.*; public class ConvertDirectory { private ConvertFile html; @@ -39,6 +40,9 @@ 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. @@ -53,8 +57,12 @@ public class ConvertDirectory { } } else if(file.isDirectory()) { - ++DirectoryInfo.level; - this.convert(file); + // Perform conversion, only if, directory + // is not a ignored directory. + if(!ignored.ignored(file)) { + ++DirectoryInfo.level; + this.convert(file); + } } } boolean convertIndex = (index.shouldConvert() || diff --git a/conversion/ignore/Ignored.java b/conversion/ignore/Ignored.java new file mode 100644 index 0000000..8129f18 --- /dev/null +++ b/conversion/ignore/Ignored.java @@ -0,0 +1,33 @@ +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/ + */ \ No newline at end of file -- 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) --- conversion/ConvertFile.java | 8 +++++--- conversion/CreateHtmlFile.java | 22 ++++++++++++++++++++++ conversion/FileSieve.java | 14 ++++++++++++-- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 conversion/CreateHtmlFile.java (limited to 'conversion') 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 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; } } -- cgit v1.2.3 From 727d6d17305e6dbba4c5231fb40012b5adfaca1b Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 10 Nov 2012 11:38:40 +0530 Subject: baptized the following files with GPL license info: conversion/CreateHtmlFile.java conversion/ignore/Ignored.java --- conversion/CreateHtmlFile.java | 23 ++++++++++++++++++++++- conversion/ignore/Ignored.java | 23 ++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'conversion') diff --git a/conversion/CreateHtmlFile.java b/conversion/CreateHtmlFile.java index ecd86c1..a502f7e 100644 --- a/conversion/CreateHtmlFile.java +++ b/conversion/CreateHtmlFile.java @@ -1,3 +1,24 @@ +/*+ + * Copyright 2012 rsiddharth + * Email: + * + * 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 . + */ + + package scruf.conversion; import java.io.*; @@ -19,4 +40,4 @@ public class CreateHtmlFile { } return htmlFile; } -} \ No newline at end of file +} diff --git a/conversion/ignore/Ignored.java b/conversion/ignore/Ignored.java index 8129f18..a13434e 100644 --- a/conversion/ignore/Ignored.java +++ b/conversion/ignore/Ignored.java @@ -1,3 +1,24 @@ +/*+ + * Copyright 2012 rsiddharth + * Email: + * + * 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 . + */ + + package scruf.conversion.ignore; import java.io.*; @@ -30,4 +51,4 @@ public class Ignored { /** CVS/ /home/rsd/projects/scruf/www/CVS/ - */ \ No newline at end of file + */ -- cgit v1.2.3 From 75114f9ba449a3bafd9d4ddb986e50b772c3a237 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 10 Nov 2012 17:20:42 +0530 Subject: New Parser: Source; Bug-fix for conversion/CanConvert.java & license/Liberate.java. added: parsers/Source.java (New Parser, adds a link to the 'scruffy' source file) modified: conversion/CanConvert.java (bug-fix) conversion/CreateHtmlFile.java (we have two versions of the create() method now) license/Liberate.java (regex fix) parsers/ParserList.java (new parser added, see above) --- conversion/CanConvert.java | 3 ++- conversion/CreateHtmlFile.java | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'conversion') 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/CreateHtmlFile.java b/conversion/CreateHtmlFile.java index a502f7e..729b3cf 100644 --- a/conversion/CreateHtmlFile.java +++ b/conversion/CreateHtmlFile.java @@ -28,11 +28,19 @@ 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() { - File htmlFile=null; - matcher = pattern.matcher(PresentFile.file.getName()); + return create(PresentFile.file); + } + public File create(File file) { + htmlFile=null; + matcher = pattern.matcher(file.getName()); if(matcher.find()) { - htmlFile = new File(PresentFile.file.getParentFile(), + htmlFile = new File(file.getParentFile(), matcher.group(1)+"html"); }else { System.err.println("ERROR: something wrong with scruf: unable to create html file"+ -- cgit v1.2.3