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 ++++++++++++-- index/IndexCreator.java | 13 ++++++++----- io/PresentFile.java | 37 ------------------------------------- parsers/BackButton.java | 2 +- parsers/DocumentName.java | 2 +- parsers/Header.java | 2 +- status/PresentFile.java | 37 +++++++++++++++++++++++++++++++++++++ todo | 14 +++++++++----- 10 files changed, 96 insertions(+), 55 deletions(-) create mode 100644 conversion/CreateHtmlFile.java delete mode 100644 io/PresentFile.java create mode 100644 status/PresentFile.java 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; } } 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/io/PresentFile.java b/io/PresentFile.java deleted file mode 100644 index 9a3deaa..0000000 --- a/io/PresentFile.java +++ /dev/null @@ -1,37 +0,0 @@ -/*+ - * 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.io; - -import java.io.*; - -/** - * Contains information about the present file that - * is being parsed by the parsers. - * - */ -public class PresentFile { - public static String name; - public static File file; -} - - - 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
\n"); 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/status/PresentFile.java b/status/PresentFile.java new file mode 100644 index 0000000..303d4bc --- /dev/null +++ b/status/PresentFile.java @@ -0,0 +1,37 @@ +/*+ + * 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.status; + +import java.io.*; + +/** + * Contains information about the present file that + * is being parsed by the parsers. + * + */ +public class PresentFile { + public static String name; + public static File file; +} + + + 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 -- cgit v1.2.3