scruf

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

commit 7f46c19441f6690bde92c1359c535321cb8c3025
parent bed3dc00c9112d70966990ca66ab0a078b5ca0b5
Author: rsiddharth <rsiddharth@ninthfloor.org>
Date:   Fri, 21 Dec 2012 13:25:10 +0530

merged from devel branch.
removed:
  Scruf.java
  todo
added:
  Run.java
  TODO
  parsers/SymbolMap.java
modified:
  conversion/ConvertDirectory.java
  parsers/BackButton.java
  parsers/CodeBlocks.java
  parsers/WordDecoration.java
  styling/StyleChecker.java
  styling/style.css
pending merges:
  rsiddharth 2012-12-21 [bug-fix]: when the default style sheet is newer than the style sheet
    rsiddharth 2012-12-21 Scruf.java has been renamed to Run.java
    rsiddharth 2012-12-21 [method named changed]: The method named 'resolve()' in styling/StyleChecker.java is changed ...
    rsiddharth 2012-12-21 [bug-fix]: Each directory is checked if it contains the style.css, if
    rsiddharth 2012-12-21 added license text to parsers/SymbolMap.java.
    rsiddharth 2012-12-21 updated TODO
    rsiddharth 2012-12-20 [bug-fix]: From now on, all the special characters in the string
    rsiddharth 2012-12-20 SymbolMap class which was in CodeBlock.java is shifted to a dedicated
    rsiddharth 2012-12-20 [bug-fix]: Back Buttons were not put in webpages that were present in
    rsiddharth 2012-12-15 bunch of new todos; 'todo' renamed to 'TODO'.

Diffstat:
Run.java | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Scruf.java | 51---------------------------------------------------
TODO | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
conversion/ConvertDirectory.java | 29+++++++++++++++++++++--------
parsers/BackButton.java | 5+++--
parsers/CodeBlocks.java | 57+--------------------------------------------------------
parsers/SymbolMap.java | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
parsers/WordDecoration.java | 30++++++++++++++++++++++++++++--
styling/StyleChecker.java | 16++++++++++------
styling/style.css | 2+-
todo | 43-------------------------------------------
11 files changed, 270 insertions(+), 169 deletions(-)

diff --git a/Run.java b/Run.java @@ -0,0 +1,49 @@ +/*+ + * Copyright 2012 rsiddharth + * Email: <rsiddharth@ninthfloor.org> + * + * 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 <http://www.gnu.org/licenses/>. + */ + + +package scruf; + +import java.io.*; +import scruf.io.*; +import scruf.conversion.*; +import scruf.styling.*; +import scruf.status.*; +import scruf.index.*; + +public class Run { + public static void main(String[] args) { + Initialization init = new Initialization(args); + File list = init.getListFile(); + ReadFile readList = new ReadFile(list); + String dirs[] = readList.split("\n"); + File directory; + ConvertDirectory html = new ConvertDirectory(); + for(String dir:dirs) { + // if empty string, do nothing. + if(dir.length()==0) { + continue; + } + directory = new File(dir).getAbsoluteFile(); + DirectoryInfo.level=0; + html.convert(directory); + } + } +} diff --git a/Scruf.java b/Scruf.java @@ -1,51 +0,0 @@ -/*+ - * Copyright 2012 rsiddharth - * Email: <rsiddharth@ninthfloor.org> - * - * 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 <http://www.gnu.org/licenses/>. - */ - - -package scruf; - -import java.io.*; -import scruf.io.*; -import scruf.conversion.*; -import scruf.styling.*; -import scruf.status.*; -import scruf.index.*; - -public class Scruf { - public static void main(String[] args) { - Initialization init = new Initialization(args); - File list = init.getListFile(); - ReadFile readList = new ReadFile(list); - String dirs[] = readList.split("\n"); - File directory; - ConvertDirectory html = new ConvertDirectory(); - StyleChecker styleSheet = new StyleChecker(); - for(String dir:dirs) { - // if empty string, do nothing. - if(dir.length()==0) { - continue; - } - directory = new File(dir).getAbsoluteFile(); - styleSheet.resolve(directory); - DirectoryInfo.level=0; - html.convert(directory); - } - } -} diff --git a/TODO b/TODO @@ -0,0 +1,74 @@ +SCRUF - TODO -*- mode: org; -*- + +* features + +** build system (GNU auto tools) + +** test suite + +** implement lists + introduce mark-up for lists. Weird that I have not implement + yet. + +** [hp] documentation + + introduction to 'scruf' & 'scruffy' mark-up. finished the initial + draft. It need to be edited and fine tuned. + +** mark-up to center align text + +* distribution related + +** README file + a brief description of the project; pointer to website; notes on + the platform; a roadmap to important files; pointer to INSTALL + file; pointer to AUTHORS file; project NEWS. +** INSTALL file + point to the manual where installation instruction can be found. +** AUTHORS file +** NEWS file + should contain information about new releases and features(if + needed). +** HISTORY file + not required for 0.1.0 release. +** FAQ file + not required for 0.1.0 release. +** checksum + md5sum. +** manual + the manual file should also be part of the source distribution. + +** package & upload it in savannah + +* website + +** create a documentation section in the homepage. + +** create a mailing list section in the homepage + +* finished todos + +** [done] ignore directories + way to ignore directories + +** [done] move PresentFile.java to status/ + +** [done] extension for scruffy files + extension for scruff marked-up files to make discovery easier. + +** [done] modify conversion/CanConvert.java (bug) + +** [done] link to scruffy source + include a link or something to view the 'source'. + +** [done] 'quote' special symbols inside a code-block. +** [done] 'last update' string + the 'last updated' string must be dangled somewhere in the document + that is licked by scruf. + +** [done] <meta> tags + introduce 'meta' info in html doc generated -- authorinfo. + +** [done] mailing list +** [done] build rsiddharth's weblog + Test it by generating rsiddharth's weblog using scruf. diff --git a/conversion/ConvertDirectory.java b/conversion/ConvertDirectory.java @@ -25,14 +25,18 @@ import java.io.*; import scruf.index.*; import scruf.status.*; import scruf.conversion.ignore.*; +import scruf.styling.*; public class ConvertDirectory { private ConvertFile html; private CanConvert canConvert; private boolean can; + private StyleChecker styleSheet; + private boolean styleFlag; public ConvertDirectory() { - html = new ConvertFile(); - canConvert = new CanConvert(); + html = new ConvertFile(); + canConvert = new CanConvert(); + styleSheet = new StyleChecker(); } public void convert(File directory) { if(!directory.isDirectory()) { @@ -47,14 +51,18 @@ public class ConvertDirectory { IndexCreator index = new IndexCreator(directory); // iterate through the directory. System.out.println("Current Directory: "+directory.getAbsolutePath()); + // reset styleFlag. + styleFlag = false; for(File file:directory.listFiles(new FileSieve())) { if(file.isFile()) { - can = canConvert.check(file); - if(can) { - System.out.println("Converting..."+file.getAbsolutePath()); - html.convert(file); - index.add(file); - } + can = canConvert.check(file); + if(can) { + System.out.println("Converting..."+file.getAbsolutePath()); + html.convert(file); + index.add(file); + // set styleFlag. + styleFlag = true; + } } else if(file.isDirectory()) { // Perform conversion, only if, directory @@ -65,6 +73,11 @@ public class ConvertDirectory { } } } + // if styleFlag is set, check for style sheet in + // in the directory. + if(styleFlag) { + styleSheet.check(directory); + } boolean convertIndex = (index.shouldConvert() || canConvert.check(index.indexFile())); if(convertIndex) { diff --git a/parsers/BackButton.java b/parsers/BackButton.java @@ -29,14 +29,15 @@ public class BackButton implements Parser { // this method doesn't modify the filContent. public String parse(String fileContent) { StringBuilder fileBuilder = new StringBuilder(fileContent); + String fileName = PresentFile.file.getName(); /** * Back button is added only if the present directory being * parsed is not 'root'. */ - if(DirectoryInfo.level!=0) { + if(DirectoryInfo.level!=0 || !(fileName.equals("index.scruffy"))) { fileBuilder.append("\n<div class=\"back\">\n"); fileBuilder.append("<a href=\""); - if(PresentFile.file.getName().equals("index.scruffy")) { + if(fileName.equals("index.scruffy")) { fileBuilder.append("../\"> back "); }else { fileBuilder.append("./\"> back "); diff --git a/parsers/CodeBlocks.java b/parsers/CodeBlocks.java @@ -36,71 +36,16 @@ public class CodeBlocks implements Parser { while(matcher.find()) { replacement.delete(0,replacement.length()); replacement.append("<div class=\"code\">"); - replacement.append(lbreak.parse(quote(matcher.group(3)))); + replacement.append(lbreak.parse(symbolMap.quote(matcher.group(3)))); replacement.append("</div>"); matcher.appendReplacement(sbuffer,replacement.toString()); } matcher.appendTail(sbuffer); return sbuffer.toString(); } - /** - * this method quotes symbols to a HTML number. - */ - private String quote(String string) { - Pattern pattern = Pattern.compile("(\\&(amp|lt|gt|(\\#35))\\;)|(\\p{Punct})"); - Matcher matcher = pattern.matcher(string); - StringBuffer sbuffer = new StringBuffer(); - while(matcher.find()) { - if(matcher.group(4)!=null) { - matcher.appendReplacement(sbuffer, - symbolMap.get(matcher.group())); - } - } - matcher.appendTail(sbuffer); - return sbuffer.toString(); - } } /** - * Map of Symbols & their HTML equivalent numbers. - */ -class SymbolMap extends HashMap<String, String> { - public SymbolMap() { - put("!","&#33;"); - put("\"","&#34;"); - put("#","&#35;"); - put("$","&#36;"); - put("%","&#37;"); - put("&","&#38;"); - put("'","&#39;"); - put("(","&#40;"); - put(")","&#41;"); - put("*","&#42;"); - put("+","&#43;"); - put(",","&#44;"); - put("-","&#45;"); - put(".","&#46;"); - put("/","&#47;"); - put(":","&#58;"); - put(";","&#59;"); - put("<","&#60;"); - put("=","&#61;"); - put(">","&#62;"); - put("?","&#63;"); - put("@","&#64;"); - put("[","&#91;"); - put("\\","&#92;"); - put("]","&#93;"); - put("^","&#94;"); - put("_","&#95;"); - put("`","&#96;"); - put("{","&#123;"); - put("|","&#124;"); - put("}","&#125;"); - put("~","&#126;"); - } -} -/** Special Case: diff --git a/parsers/SymbolMap.java b/parsers/SymbolMap.java @@ -0,0 +1,83 @@ +/*+ + * Copyright 2012 rsiddharth + * Email: <rsiddharth@ninthfloor.org> + * + * 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 <http://www.gnu.org/licenses/>. + */ + + + +package scruf.parsers; + +import java.util.regex.*; +import java.util.*; + +/** + * Map of Symbols & their HTML equivalent numbers. + */ +public class SymbolMap extends HashMap<String, String> { + public SymbolMap() { + put("!","&#33;"); + put("\"","&#34;"); + put("#","&#35;"); + put("$","&#36;"); + put("%","&#37;"); + put("&","&#38;"); + put("'","&#39;"); + put("(","&#40;"); + put(")","&#41;"); + put("*","&#42;"); + put("+","&#43;"); + put(",","&#44;"); + put("-","&#45;"); + put(".","&#46;"); + put("/","&#47;"); + put(":","&#58;"); + put(";","&#59;"); + put("<","&#60;"); + put("=","&#61;"); + put(">","&#62;"); + put("?","&#63;"); + put("@","&#64;"); + put("[","&#91;"); + put("\\","&#92;"); + put("]","&#93;"); + put("^","&#94;"); + put("_","&#95;"); + put("`","&#96;"); + put("{","&#123;"); + put("|","&#124;"); + put("}","&#125;"); + put("~","&#126;"); + } + /** + * this method quotes symbols to a HTML number. + */ + public String quote(String string) { + Pattern pattern = Pattern.compile("(\\&(amp|lt|gt|(\\#35))\\;)|(\\p{Punct})"); + Matcher matcher = pattern.matcher(string); + StringBuffer sbuffer = new StringBuffer(); + while(matcher.find()) { + if(matcher.group(4)!=null) { + matcher.appendReplacement(sbuffer, + this.get(matcher.group())); + } + } + matcher.appendTail(sbuffer); + return sbuffer.toString(); + } +} + diff --git a/parsers/WordDecoration.java b/parsers/WordDecoration.java @@ -28,13 +28,14 @@ import scruf.io.*; public class WordDecoration implements Parser { private HashMap<String, String> tagMap; + private SymbolMap symbolMap; public WordDecoration() { tagMap = new HashMap<String, String>(); tagMap.put("''","<i>$7</i>"); tagMap.put("__","<u>$7</u>"); tagMap.put("'''","<b>$7</b>"); tagMap.put("%%%","<blockquote>$7</blockquote>"); - tagMap.put("`","<span class=\"monospace\">$7</span>"); + symbolMap = new SymbolMap(); } public String parse(String fileContent) { Pattern pattern = @@ -44,10 +45,35 @@ public class WordDecoration implements Parser { StringBuffer sbuffer = new StringBuffer(); String replacement; while(matcher.find()) { - replacement = tagMap.get(matcher.group(1)); + // if the block found is a monospace block, + // get the replacement from 'monospaceBlock' + // method, else get it from the 'tagMap': + if(matcher.group(6)!=null) { + // group 7 is the string inside the word decorated + // mark up. (see the pattern above) + replacement = monospaceBlock(matcher.group(7)); + }else { + replacement = tagMap.get(matcher.group(1)); + } matcher.appendReplacement(sbuffer,replacement); } matcher.appendTail(sbuffer); return sbuffer.toString(); } + + // monopace blocks need special treatment, therefore, + // this method for its construction: + private String monospaceBlock(String content) { + // quote all special characters in the monospace + // block: + String quotedContent= symbolMap.quote(content); + + // build monospace HTML block: + StringBuilder sb = new StringBuilder(); + sb.append("<span class=\"monospace\">"); + sb.append(quotedContent); + sb.append("</span>"); + + return sb.toString(); + } } diff --git a/styling/StyleChecker.java b/styling/StyleChecker.java @@ -23,18 +23,22 @@ package scruf.styling; import scruf.io.*; import java.io.*; + public class StyleChecker { private File styleSheet; private File curDir; private String styleContent; - - public void resolve(File curDir) { + // the default style sheet in scruf package. + private File scrufStyleSheet = new File("scruf/styling/style.css"); + public void check(File curDir) { this.curDir = curDir.getAbsoluteFile(); styleSheet = new File(curDir,"style.css"); - // if style shee doesn't exists, copy default sheet - // to the directory. - if(!styleSheet.exists()) { - styleContent = new ReadFile(new File("scruf/styling/style.css")).getContent(); + // if style sheet doesn't exists or if the default style is newer + // than style sheet in the directory, copy default sheet to the + // directory. + if((!styleSheet.exists()) || + scrufStyleSheet.lastModified() > styleSheet.lastModified()) { + styleContent = new ReadFile(scrufStyleSheet).getContent(); new WriteFile(styleSheet,styleContent).write(); } } diff --git a/styling/style.css b/styling/style.css @@ -6,7 +6,7 @@ */ article { - font-size:1.50em; /* 1.88 */ + font-size:1.50em; font-family:"Palatino Linotype","Book Antiqua",Palatino,"URW Palladio L",FreeSerif,serif; color:#787878; margin-left:auto; diff --git a/todo b/todo @@ -1,43 +0,0 @@ -SCRUF - TODO -*- mode: org; -*- - -* features - -** implement lists - introduce mark-up for lists. Weird that I have not implement - yet. - - -** [hp] documentation - - introduction to 'scruf' & 'scruffy' mark-up. [started writing, but - might not get it done anytime in the near future.] - -* testing - -** build homepage - Test it by generating your _full_ homepage using scruf. - -* finished todos - -** [done] ignore directories - way to ignore directories - -** [done] move PresentFile.java to status/ - -** [done] extension for scruffy files - extension for scruff marked-up files to make discovery easier. - -** [done] modify conversion/CanConvert.java (bug) - -** [done] link to scruffy source - include a link or something to view the 'source'. - -** [done] 'quote' special symbols inside a code-block. -** [done] 'last update' string - the 'last updated' string must be dangled somewhere in the document - that is licked by scruf. - -** [done] <meta> tags - introduce 'meta' info in html doc generated -- authorinfo. - -