diff options
author | rsiddharth <rsiddharth@ninthfloor.org> | 2012-12-21 13:25:10 +0530 |
---|---|---|
committer | rsiddharth <rsiddharth@ninthfloor.org> | 2012-12-21 13:25:10 +0530 |
commit | 7f46c19441f6690bde92c1359c535321cb8c3025 (patch) | |
tree | 73ad82bfba3ed35fa9707d73ae7c0dd4c63c6eb6 | |
parent | bed3dc00c9112d70966990ca66ab0a078b5ca0b5 (diff) | |
parent | 03ab823d0318865544c54baaaa0b4ebb63fae4fa (diff) |
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'.
-rw-r--r-- | Run.java (renamed from Scruf.java) | 4 | ||||
-rw-r--r-- | TODO | 74 | ||||
-rw-r--r-- | conversion/ConvertDirectory.java | 29 | ||||
-rw-r--r-- | parsers/BackButton.java | 5 | ||||
-rw-r--r-- | parsers/CodeBlocks.java | 57 | ||||
-rw-r--r-- | parsers/SymbolMap.java | 83 | ||||
-rw-r--r-- | parsers/WordDecoration.java | 30 | ||||
-rw-r--r-- | styling/StyleChecker.java | 16 | ||||
-rw-r--r-- | styling/style.css | 2 | ||||
-rw-r--r-- | todo | 43 |
10 files changed, 222 insertions, 121 deletions
@@ -28,7 +28,7 @@ import scruf.styling.*; import scruf.status.*; import scruf.index.*; -public class Scruf { +public class Run { public static void main(String[] args) { Initialization init = new Initialization(args); File list = init.getListFile(); @@ -36,14 +36,12 @@ public class Scruf { 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); } @@ -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 index a5717bb..87a0145 100644 --- 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 index e504648..38e5a9e 100644 --- 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 index 251c4de..75efa27 100644 --- 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("!","!"); - put("\"","""); - put("#","#"); - put("$","$"); - put("%","%"); - put("&","&"); - put("'","'"); - put("(","("); - put(")",")"); - put("*","*"); - put("+","+"); - put(",",","); - put("-","-"); - put(".","."); - put("/","/"); - put(":",":"); - put(";",";"); - put("<","<"); - put("=","="); - put(">",">"); - put("?","?"); - put("@","@"); - put("[","["); - put("\\","\"); - put("]","]"); - put("^","^"); - put("_","_"); - put("`","`"); - put("{","{"); - put("|","|"); - put("}","}"); - put("~","~"); - } -} -/** Special Case: diff --git a/parsers/SymbolMap.java b/parsers/SymbolMap.java new file mode 100644 index 0000000..752fcf6 --- /dev/null +++ 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("!","!"); + put("\"","""); + put("#","#"); + put("$","$"); + put("%","%"); + put("&","&"); + put("'","'"); + put("(","("); + put(")",")"); + put("*","*"); + put("+","+"); + put(",",","); + put("-","-"); + put(".","."); + put("/","/"); + put(":",":"); + put(";",";"); + put("<","<"); + put("=","="); + put(">",">"); + put("?","?"); + put("@","@"); + put("[","["); + put("\\","\"); + put("]","]"); + put("^","^"); + put("_","_"); + put("`","`"); + put("{","{"); + put("|","|"); + put("}","}"); + put("~","~"); + } + /** + * 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 index 1df8cc6..e7cc0ac 100644 --- 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 index 68d7b46..e70170a 100644 --- 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 index 9166be3..d6a533a 100644 --- 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; @@ -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. - - |