Permalink
Browse files

Added ProGit.css for better list layout and better code formatting, m…

…ake_epub.sh cleaned up
  • Loading branch information...
1 parent 22e0cc1 commit e13f242ac3a3f789d59e6a61d10d4ee842e4e8d8 @ingorichter ingorichter committed May 1, 2010
Showing with 73 additions and 79 deletions.
  1. +28 −0 epub/ProGit.css
  2. +45 −79 epub/make_epub.sh
View
@@ -0,0 +1,28 @@
+ul {
+ margin: 20px;
+}
+
+ol {
+ margin: 20px;
+}
+
+body pre {
+ margin: 10px;
+ font-weight: bold;
+}
+
+body pre2 {
+ background-color: silver;
+ padding: 10px;
+ border-top-style: solid;
+ border-left-style: solid;
+ border-left-width: 1px;
+ border-top-width: 1px;
+ overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
+ white-space: pre-wrap; /* css-3 */
+ white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
+ white-space: -pre-wrap; /* Opera 4-6 */
+ white-space: -o-pre-wrap; /* Opera 7 */
+ /* width: 99%; */
+ word-wrap: break-word; /* Internet Explorer 5.5+ */
+ }
View
@@ -2,107 +2,73 @@
//script requires Groovy, Markdown and Calibre. On Ubuntu call "sudo apt-get install groovy markdown calibre"
-/*Class TextDumper is required for Groovy < 1.7*/
-class TextDumper implements Runnable {
- InputStream input;
- StringBuffer sb;
-
- TextDumper(input, sb) {
- this.input = input;
- this.sb = sb;
- }
-
- void run() {
- def isr = new InputStreamReader(input);
- def br = new BufferedReader(isr);
- String next;
- try {
- while ((next = br.readLine()) != null) {
- sb.append(next);
- sb.append("\n");
- }
- } catch (IOException e) {
- throw new GroovyRuntimeException("exception while reading process stream", e);
- }
- }
-}
-println "This script requires Groovy, Markdown and Calibre. On Ubuntu call 'sudo apt-get install groovy markdown calibre'"
+@GrabResolver(name='scala-tools', root='http://scala-tools.org/repo-releases')
+@Grab(group='org.markdownj', module='markdownj', version='0.3.0-1.0.2b4')
+
+import com.petebevin.markdown.MarkdownProcessor
+
+println "This script requires Groovy, Markdown and Calibre. On Ubuntu call 'sudo apt-get install groovy calibre'"
if (args.size() == 0) {
println "First parameter must be name of language(=directory). For example: 'en'"
return
}
+
def lang = args[0]
def langDir = new File("..", lang)
-def figures = new File("../figures")
def dest = new File("target")
+
dest.deleteDir()
dest.mkdirs()
+
def markdownFile = ~/.*\.markdown/
def filesForIndex = []
+def mp = new MarkdownProcessor()
+
langDir.eachDir { dir ->
- dir.eachFileMatch(markdownFile) { file ->
- def preparedFile = new File(dest, file.getName())
- println "Processing ${file}"
- preparedFile.withWriter { writer ->
- file.withReader { reader ->
- String line = null
- while ( (line = reader.readLine()) != null) {
- def matches = line =~ /^\s*Insert\s(.*)/
- if (matches.size() != 0) {
- def imageFile = matches[0][1].trim().replaceAll(/(.*)(\.png)/, '$1-tn$2')
- //println "file:" + imageFile
- def nextLine = reader.readLine()
- line = """![${nextLine}](../../figures/${imageFile} "${nextLine}")"""
- //println "Line: " + line
- }
- writer.print(line)
- writer.print("\n")
- } //while
- } // reader
- } //writer
- def htmlFile = new File(dest, file.getName() + ".html")
- filesForIndex += htmlFile;
- def cmd = ["""markdown""", """${preparedFile}"""]
- println "Executing ${cmd}"
- def proc = cmd.execute();
- def sout = new StringBuffer()
- def serr = new StringBuffer()
- def groovyLessThan165 = {
- Thread thread = new Thread(new TextDumper(proc.getInputStream(), sout));
- thread.start();
- try { thread.join(); } catch (InterruptedException ignore) {}
- try { proc.waitFor(); } catch (InterruptedException ignore) {}
- }
- groovyLessThan165()
- //Groovy >= 1.6.5: proc.waitForProcessOutput(sour, serr)
- htmlFile.withWriter {
- it << sout.toString()
- }
+ dir.eachFileMatch(markdownFile) { file ->
+ println "Processing ${file}"
+
+ def fileContent = file.getText('UTF-8')
+
+ def content = fileContent.replaceAll(/(?m)^Insert\s+(.*)(\.png)\s+(Figure\s+.*)/, '[$3](../../figures/$1-tn$2 "$3")')
+
+ def htmlFile = new File(dest, file.name + ".html")
+ filesForIndex += htmlFile;
+
+ def result = mp.markdown(content)
+
+ htmlFile.withWriter('UTF-8') {
+ it << result
+ }
} //file
} //dir
+
+
+// concat all files into one single html file
def indexFile = new File(dest, "progit.html")
-indexFile.withWriter { writer ->
- writer << """<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Pro Git - professional version control</title></head><body>"""
- filesForIndex.sort().each { file ->
- def fileName = file.getName()
- file.eachLine {
- writer << it
- writer << '\n'
- }
- }
- writer << """</body></html>"""
+indexFile.withWriter('UTF-8') { writer ->
+ writer << """<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Pro Git - professional version control</title></head><body>"""
+
+ filesForIndex.sort().each { file ->
+ writer << file.getText('UTF-8')
+ }
+
+ writer << """</body></html>"""
}
-def epubFile = new File(dest, "progit_${args[0]}.epub")
+
+def epubFile = new File(dest, "progit_${lang}.epub")
println "EpubFile" + epubFile
-def cmd = ["""ebook-convert""", indexFile.getPath(), epubFile.getPath(),
+
+def cmd = ["""/Applications/calibre.app/Contents/MacOS/ebook-convert""", indexFile.getPath(), epubFile.getPath(),
"""--cover""", """title.png""",
"""--authors""", "Scott Chacon",
"--comments", "licensed under the Creative Commons Attribution-Non Commercial-Share Alike 3.0 license",
"--level1-toc", "//h:h1",
"--level2-toc", "//h:h2",
- "--level3-toc", "//h:h3"
+ "--level3-toc", "//h:h3",
+ "--extra-css", "ProGit.css",
+ "--language", lang
]
+
def proc = cmd.execute();
proc.waitFor();
-
-

5 comments on commit e13f242

Contributor

mikegr replied Jun 1, 2010

This only works with Mac OS X -> "/Applications/calibre.app/Contents/MacOS/ebook-convert"" - Major problem
Furthermore it requires Groovy 1.7 which is not packaged with latest Ubuntu version (lucid). - Minor problem

Contributor

ingorichter replied Jun 2, 2010

Agree, to find the correct ebook-convert (depending on the platform) there is another solution required. Which groovy version comes with the latest Ubuntu? I thought they update the groovy version on regulary basis.

Contributor

gioele replied Jun 2, 2010

In may epub branch you'll find a Rakefile that removes the need of Groovy. I also sent a pull request for it.

http://github.com/gioele/progit/tree/epub

Hope this helps.

Contributor

gioele replied Jun 2, 2010

I added to my epub branch (in commit gioele/progit@d01bf6c) a little auto-detection mechanism for Mac OS X.

Contributor

ingorichter replied Jun 3, 2010

That looks quite good. Good work!
What about adding support for Windows (to make the list of popular OS'es complete)?

Please sign in to comment.