Permalink
Browse files

initial the new book from sdcamp

  • Loading branch information...
1 parent 56e7d96 commit 4c4b5a046841475800f548e5ceba7ddbc331ef99 @larrycai committed Jan 19, 2012
View
@@ -1,12 +1,12 @@
-target/
-velocity.log
-cobertura.ser
-.project
-.classpath
-.settings/
-*~
-pom.xml~
-.svn/*
-release.properties
-*.releaseBackup
-~*
+kuaiyuanbook.*
+*.pdf
+*.swp
+latex/*
+!latex/makepdf
+!latex/README
+!latex/template.tex
+!latex/config.yml
+epub/temp
+*~
+.#*
+*.epub
View
@@ -0,0 +1,99 @@
+# Introduction #
+
+As open source books, ebooks and pdf format should be created on fly, the following sections describe those solution in detail.
+
+The solution below is based on [Pro Git][progit]; while it is little updated on format inside.
+
+# Making Pdf books #
+PDF format is used to read/print in nice way like real book, [pandoc][pandoc] good at this and it is used instead to generate latex from markdown, and latex tool `xelatex` (is part of [TexLive][texlive] now) is used to convert pdf from latex.
+
+Please check [ctax](http://www.ctan.org/) and [TexLive][texlive] for more background for latex, which is quite complicated and elegant if you have never touched before.
+
+## Ubuntu Platform ##
+
+Ubuntu Platform Oneiric (11.10) is used mainly due to pandoc.
+
+[pandoc][pandoc] can be installed directly from source, which version is 1.8.x. If you use Ubuntu 11.04, then it is just 1.5.x.
+
+Though texlive 2011 can be installed separately, the default one texlive 2009 from Ubuntu repository is good enough so far.
+
+ $ sudo apt-get install pandoc
+ $ sudo apt-get texlive-xelatex
+ $ sudo apt-get texlive-latex-recommended # main packages
+ $ sudo apt-get texlive-latex-extra # package titlesec
+
+You need to install related fonts for Chinese, fortunately they exist in ubuntu source also.
+
+ $ sudo apt-get install ttf-arphic-gbsn00lp ttf-arphic-ukai # from arphic
+ $ sudo apt-get install ttf-wqy-microhei ttf-wqy-zenhei # from WenQuanYi
+
+Then it should work perfectly
+
+ $ ./makepdfs zh
+
+Just remind you, some [extra pandoc markdown format](http://johnmacfarlane.net/pandoc/README.html) is used inside this book:
+
+ * code syntax highlight (doesn't work in pdf, while it should work in html/epub which needed later)
+ * footnote
+
+# Making Ebooks #
+
+**In long term** I will use pandoc instead of solution below since from 1.8.x, pandoc supports for epub as well.
+
+[ruby rdiscount](https://github.com/rtomayko/rdiscount) is used to convert all the markdown files to html format.
+
+[Calibre][calibre]'s command `ebook-convert` is used to convert html files into ebooks like `.mobi` (Kindle) and `.epub` (for iPad), it exists in several platforms (Windows, OS X, Linux).
+
+[Calibre][calibre] needs X-Windows for some reason, If X-Windows is not used like server only, then [xvfb](http://en.wikipedia.org/wiki/Xvfb) (Virtual Framebuffer 'fake' X server) package should be installed to support headless X-Windows. Simple X-Windows server like XMing doesn't support X-Input.
+
+After preparing the environment, you can simple run the command below to generate related ebooks
+
+ $ ./makeebooks zh # default for .mobi
+ $ export FORMAT=epub ;
+ $ ./makeebooks zh # for epub
+
+## Ubuntu ##
+Ubuntu 11.04 (Natty) is verified, it should work in other version as well with slight changes.
+
+ $ sudo apt-get install ruby calibre rubygems # ruby 1.8.7 is used
+ $ sudo apt-get install calibre # calibre 0.7.44 for ubuntu 11.04
+ $ gem install rdiscount ruby-debug
+
+## Windows (not fixed) ##
+
+[RubyInstaller & DevKit](http://rubyinstaller.org/downloads/) is needed for ruby environment on windows, ruby 1.9 is verified, and "Git for windows" is used to provide unix environment.
+
+ $ gem install rdiscount
+ $ gem install ruby-debug19 # have problem
+
+ Building native extensions. This could take a while...
+ ERROR: Error installing ruby-debug19:
+ ERROR: Failed to build gem native extension.
+
+ c:/Ruby193/bin/ruby.exe extconf.rb
+ checking for vm_core.h... no
+ c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/ruby_core_source.rb:39: Use RbConfig instead of obsolet
+ and deprecated Config.
+ checking for vm_core.h... no
+ *** extconf.rb failed ***
+ ...
+
+[Calibre][calibre]'s command `ebook-convert` is under `calibre` directory, it should be added into your path, then the related ebook can be created.
+
+Then you should be able to generate pdf
+
+ $ xvfb-run ./makeebooks zh # if no X-Windows
+
+## Fedora platform ##
+This is copied from [Pro Git][progit], not verified yet
+
+On Fedora you can run something like this::
+
+ $ yum install ruby calibre rubygems ruby-devel rubygem-ruby-debug
+ $ gem install rdiscount
+ $ makeebooks en # will produce a mobi
+
+[pandoc]: http://johnmacfarlane.net/pandoc/
+[calibre]: http://calibre-ebook.com/
+[progit]: http://github.com/progit/progit
+[texlive]: http://www.tug.org/texlive/
View
@@ -0,0 +1,18 @@
+# Software Development Book Contents#
+
+This is the book for how to write opensource books, it covers markdown,pandoc,latex
+
+Hope you enjoy it, I hope it helps you learn better software development.
+
+Please check BUILD.md for how to making ebooks by yourself,
+
+Original contribution is to [Pro Git](http://github.com/progit/progit)
+
+#Errata#
+
+If you see anything that is technically wrong or otherwise in need of
+correction, please email me at larry dot caiyu at gmail dot com to inform me.
+
+### License
+ The license is under ![](http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png), see [CC BY NC ND 3.0](http://creativecommons.org/licenses/by-nc-nd/3.0/) for more
+
View
@@ -1,18 +0,0 @@
-# Introduction
-
-this is just a template and guideline on how to write manual in markdown format.
-
-
-### Chapters
-It is plan to cover
-
-* Chapter 1: Introduction, What is markdown, what is included in this manual
-
-### License
- The license is under ![](http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png), see [CC BY NC ND 3.0](http://creativecommons.org/licenses/by-nc-nd/3.0/) for more
-
-### Way of working
-
-If you are interesting, contact me larry.caiyu@gmail.com
-
-
View
160 Rakefile
@@ -0,0 +1,160 @@
+# encoding: UTF-8
+
+require 'rake/clean'
+
+
+$lang = ENV['language']
+$lang ||= 'en'
+
+namespace :epub do
+ TMP_DIR = File.join('epub', 'temp', $lang)
+ INDEX_FILEPATH = File.join(TMP_DIR, 'sdcamp.html')
+ TARGET_FILEPATH = "sdcamp-#{$lang}.epub"
+
+ SOURCE_FILES = FileList.new(File.join($lang, '**', '*.markdown')).sort
+ CONVERTED_MK_FILES = SOURCE_FILES.pathmap(File.join(TMP_DIR, '%f'))
+ HTML_FILES = CONVERTED_MK_FILES.ext('html')
+
+ desc "generate EPUB ebook (add language=xx to build lang xx)"
+ task :generate => :check
+ task :generate => TARGET_FILEPATH
+
+ desc "check whether all the required tools are installed"
+ task :check do
+ begin
+ require 'maruku'
+ found_maruku = true
+ rescue LoadError
+ found_maruku = false
+ end
+
+ $ebook_convert_cmd = ENV['ebook_convert_path'].to_s
+ if $ebook_convert_cmd.empty?
+ $ebook_convert_cmd = `which ebook-convert`.chomp
+ end
+ if $ebook_convert_cmd.empty?
+ mac_osx_path = '/Applications/calibre.app/Contents/MacOS/ebook-convert'
+ $ebook_convert_cmd = mac_osx_path
+ end
+ found_calibre = File.executable?($ebook_convert_cmd)
+
+ if !found_maruku
+ puts 'EPUB generation requires the Maruku gem.'
+ puts ' On Ubuntu call "sudo apt-get install libmaruku-ruby".'
+ end
+ if !found_calibre
+ puts 'EPUB generation requires Calibre.'
+ puts ' On Ubuntu call "sudo apt-get install calibre".'
+ end
+
+ if !found_calibre || !found_maruku then exit 1 end
+ end
+
+ directory TMP_DIR
+
+ rule '.html' => '.mk' do |t|
+ require 'maruku'
+
+ mk_filename = t.source
+ html_filename = t.name
+ puts "Converting #{mk_filename} -> #{html_filename}"
+
+ mk_file = File.open(mk_filename, 'r') do |mk|
+ html_file = File.open(html_filename, 'w') do |html|
+ code = Maruku.new(mk.read.encode("UTF-8")).to_html
+ code.gsub!(/^(<h.) (id='[^']+?')/, '\1')
+ html << code
+ html << "\n"
+ end
+ end
+ end
+
+ src_for_converted = proc do |dst|
+ base_name = dst.pathmap('%n')
+ SOURCE_FILES.find { |s| s.pathmap('%n') == base_name }
+ end
+
+ rule '.mk' => src_for_converted do |t|
+ src_filename = t.source
+ dest_filename = t.name
+ puts "Processing #{src_filename} -> #{dest_filename}"
+
+ figures_dir = "../../../figures"
+
+ dest_file = File.open(dest_filename, 'w')
+ src_file = File.open(src_filename, 'r')
+ until src_file.eof?
+ line = src_file.readline
+
+ matches = line.match /^\s*Insert\s(.*)/
+ if matches
+ image_path = matches[1]
+ real_image_path = image_path.pathmap("#{figures_dir}/%X-tn%x")
+
+ next_line = src_file.readline.chomp
+
+ line = "![#{next_line}](#{real_image_path} \"#{next_line}\")\n"
+ end
+
+ dest_file << line
+ end
+ src_file.close
+ dest_file.close
+ end
+
+ file INDEX_FILEPATH => TMP_DIR
+ file INDEX_FILEPATH => HTML_FILES do
+ index_file = File.open(INDEX_FILEPATH, 'w') do |file|
+ file << '<?xml version="1.0" encoding="UTF-8"?>'
+ file << "\n"
+ file << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
+ file << '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
+ file << "\n"
+ file << "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='#{$lang}'>"
+ file << '<head>'
+ file << '<title>Pro Git - professional version control</title>'
+ file << '</head>'
+ file << '<body>'
+ file << "\n"
+
+ HTML_FILES.each do |chapter_file|
+ file << File.open(chapter_file).read
+ file << "\n"
+ end
+
+ file << '</body></html>'
+ file << "\n"
+ end
+ end
+
+ file TARGET_FILEPATH => INDEX_FILEPATH do
+ opts = [
+ '--language', $lang,
+ '--authors', 'Scott Chacon',
+ '--comments', 'Licensed under the Creative Commons Attribution-Non Commercial-Share Alike 3.0 license',
+
+ '--cover', 'epub/title.png',
+ '--extra-css', 'epub/ProGit.css',
+
+ '--chapter', '//h:h1',
+ '--level1-toc', '//h:h1',
+ '--level2-toc', '//h:h2',
+ '--level3-toc', '//h:h3',
+ ]
+
+ sh $ebook_convert_cmd, INDEX_FILEPATH, TARGET_FILEPATH, *opts
+ end
+
+ CLEAN.push(*CONVERTED_MK_FILES)
+ CLEAN.push(*HTML_FILES)
+ CLEAN << INDEX_FILEPATH
+ CLEAN << TMP_DIR
+ CLOBBER << TARGET_FILEPATH
+end
+
+namespace :pdf do
+ desc "generate a pdf"
+ task :generate do
+ system("ruby makepdfs")
+ end
+end
View
@@ -1,22 +0,0 @@
-/* -----------------------------------------------------------------------
-
- Blueprint CSS Framework 0.7.1
- http://blueprintcss.googlecode.com
-
- * Copyright (c) 2007-2008. See LICENSE for more info.
- * See README for instructions on how to use Blueprint.
- * For credits and origins, see AUTHORS.
- * This is a compressed file. See the sources in the 'src' directory.
-
------------------------------------------------------------------------ */
-
-/* ie.css */
-body {text-align:center;}
-.container {text-align:left;}
-* html .column {overflow-x:hidden;}
-* html legend {margin:-18px -8px 16px 0;padding:0;}
-ol {margin-left:2em;}
-sup {vertical-align:text-top;}
-sub {vertical-align:text-bottom;}
-html>body p code {*white-space:normal;}
-hr {margin:-8px auto 11px;}
@@ -1,14 +0,0 @@
-Fancy Type
-
-* Gives you classes to use if you'd like some
- extra fancy typography.
-
-Credits and instructions are specified above each class
-in the fancy-type.css file in this directory.
-
-
-Usage
-----------------------------------------------------------------
-
-1) Add this plugin to lib/settings.yml.
- See compress.rb for instructions.
Oops, something went wrong.

0 comments on commit 4c4b5a0

Please sign in to comment.