scruf

darn simple HTML5 doc generator
git clone git://git.ricketyspace.net/scruf.git
Log | Files | Refs | README

commit 1a886ec82f13a01253e5611aeb18e3c845e2668d
parent 250cf4befea71a2ec6d917d104d20c702e7d4551
Author: rsiddharth <rsiddharth@ninthfloor.org>
Date:   Sun, 24 Jun 2012 21:44:10 +0530

conversion/ConvertDirectory.java: only a small addition -- to print out the file that is under "conversion"

conversion/FileSieve.java: update the regex to ignore hidden files, ".ttf" files.

parsers/Header.java: 

             * Now the blog post goes bettween the <article> & </article> tag, Header class was modified to reflect this 
               change.
             * "Powered by scruf" line must go at the bottom of every html page that is generated by this program, Header
               class was modified to reflect this.
parsers/Images.java: I have modified the "regex" and relevant code to make the "image description" optional. 

Diffstat:
conversion/ConvertDirectory.java | 1+
conversion/FileSieve.java | 2+-
parsers/Header.java | 12++++++++++--
parsers/Images.java | 15++++++++++++---
4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/conversion/ConvertDirectory.java b/conversion/ConvertDirectory.java @@ -24,6 +24,7 @@ public class ConvertDirectory { if(file.isFile()) { can = canConvert.check(file); if(can) { + System.out.println("Converting..."+file.getName()); html.convert(file); index.add(file); } diff --git a/conversion/FileSieve.java b/conversion/FileSieve.java @@ -7,7 +7,7 @@ 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))|(.+?\\~)|(index)|(\\..+)"); + Pattern pattern = Pattern.compile("(.+\\.(html|png|jpg|css|tar|ttf))|(.+?\\~)|(index)|(\\..+)"); Matcher matcher = pattern.matcher(pathname.getName()); boolean bool = matcher.find(); return !bool; diff --git a/parsers/Header.java b/parsers/Header.java @@ -20,15 +20,23 @@ public class Header implements Parser { sbuilder.append("</title>"); sbuilder.append("</head> \n"); sbuilder.append("<body> \n"); + // File Content goes inside <article> tag + sbuilder.append("<article>\n"); // insert File Content. sbuilder.append(fileContent); // insert back button. sbuilder.append(PresentFile.backButton); - // Close body - sbuilder.append("\n</body>\n"); + // add footer if footer is available. if(PresentFile.footer!=null) { sbuilder.append(PresentFile.footer); } + sbuilder.append("</article>\n"); + // add "powered by scruf" at bottom of page. + sbuilder.append("<div class=\"scruf\">\n"); + sbuilder.append("powered by scruf"); + sbuilder.append("</div>"); + // Close body tag + sbuilder.append("\n</body>\n"); sbuilder.append("</html>\n"); return sbuilder.toString(); diff --git a/parsers/Images.java b/parsers/Images.java @@ -4,12 +4,21 @@ import java.util.regex.*; public class Images implements Parser { public String parse(String fileContent) { - Pattern pattern = Pattern.compile("\\{\\{(.+\\.(png|jpg))\\|(.+)\\}\\}"); + Pattern pattern = Pattern.compile("\\{\\{(.+\\.(png|jpg))(\\|(.+))?\\}\\}"); Matcher matcher = pattern.matcher(fileContent); StringBuffer sbuffer = new StringBuffer(); - StringBuilder replacementString = new StringBuilder(); - replacementString.append("<img src=\"$1\" alt=\"$3\" title=\"$3\"/>"); + StringBuilder replacementString =new StringBuilder(); while(matcher.find()) { + // empty the builder. + replacementString.delete(0,replacementString.length()); + // add the _img_ tag + replacementString.append("<img src=\"$1\""); + // if the "title" is given add to the _img_ tag. + if(matcher.group(3)!=null) { + replacementString.append("alt=\"$4\" title=\"$4\""); + } + // close the _img_ tag. + replacementString.append(" />"); matcher.appendReplacement(sbuffer,replacementString.toString()); } matcher.appendTail(sbuffer);