example/Rakefile in madowu-0.0.2 vs example/Rakefile in madowu-0.0.3
- old
+ new
@@ -1,74 +1,109 @@
# coding: utf-8
# Rakefile for Markdown documents.
-#DIRMAP_HTML = '.dirmap.html'
+DIRMAP_MD = '.dirmap.md'
ENCODING = "UTF-8"
HTML2PDF = "wkhtmltopdf"
+TEX2IMAGE = "tex2image"
HTML2PDF_OPTIONS = "-B 1cm -L 1.5cm -R 1.5cm -T 1.5cm -s A4 --encoding #{ENCODING} "
+CONVERT_COMMAND = "convert -alpha deactivate -density 150x150"
require "pp"
require "fileutils"
require "pathname"
-desc "Make .sidebar"
-#dirmaps = []
+## .dirmap.md
+# dirmap コマンドは必ず実行なので task タスク。
+# これを file にすると存在するときに実行されない。
+# 生成物の .dirmap.md から task タスクへの依存を設定すると、
+# .dirmap.md に依存する file タスクに「必ず実行」が伝播して必ず実行になってしまう。
+# DIRMAP_MD というファイルに対する file タスクへの依存として扱うことで、
+# .dirmap.md に依存する file タスクに「必ず実行」が伝播するのを防いでいる。
+desc "update .dirmap.md if directory changed."
+file DIRMAP_MD => :dirmap_command
+task :dirmap_command do
+ sh "dirmap"
+end
-#Dir.glob(['.', "**/*"]).each do |path|
-# next unless FileTest.directory? path
-#
-# dirpath = Pathname.new(path)
-# dirmap = "#{dirpath}/#{DIRMAP_HTML}"
-# dirmap.sub!(/^\.\//, '')
-# dirmaps << dirmap
-# #pp dirmap
-# file dirmap => [dirpath, dirpath.parent] do
-# sh "dirmap #{dirpath} > #{dirpath}/#{DIRMAP_HTML}"
-# end
-#end
-##pp dirmaps
-#task :dirmaps => dirmaps
-
-desc "Make *.html from *.md"
-md_files = FileList["**/*.md"]
+## *.html
+md_files = FileList["*.md"]
html_files = md_files.ext("html")
-task :md2html => FileList[html_files]
+html_tasks = []
html_files.each do |html_file|
md_file = html_file.ext("md")
md_path = Pathname.new( md_file)
dirpath = md_path.dirname
- #dirmap = md_path.dirname + DIRMAP_HTML
- #file html_file => [md_file, dirmap] do
- file html_file => [md_file, dirpath, dirpath.parent] do
- #sh "madowu -o -s #{dirmap} -c madowu.css #{md_file}"
- sh "madowu -o -d -c madowu.css -C UTF-8 #{md_file}"
+ src = FileList[md_file, DIRMAP_MD]
+ file html_file => [DIRMAP_MD, md_file] do
+ sh "madowu -O -s .dirmap.md -c madowu.css -C UTF-8 #{md_file}"
end
+ html_tasks << html_file
end
-desc "Update mtime of all html files"
-task :tree => :md2html do
- html_files.each do |html_file|
- File.utime(Time.now, Time.now, html_file)
- end
-end
+desc "make *.html from *.md"
+task :md2html => [DIRMAP_MD, * html_tasks]
-desc "Make *.pdf from *.html"
+
+desc "make *.pdf from *.html"
pdf_files = html_files.ext("pdf")
task :html2pdf => FileList[pdf_files]
pdf_files.each do |pdf_file|
html_file = pdf_file.ext("html")
file pdf_file => html_file do
sh "#{HTML2PDF} #{HTML2PDF_OPTIONS} #{html_file} #{pdf_file}"
end
end
+desc "make .png from .eps."
+eps_files = FileList["*.eps"]
+png_files = eps_files.ext("png")
+task :eps2png => FileList[png_files]
+png_files.each do |png_file|
+ eps_file = png_file.ext("eps")
+ t = [eps_file]
+ file png_file => t do
+ sh "#{CONVERT_COMMAND} #{eps_file} #{png_file}"
+ end
+end
+
+
+desc "make *.png from *.tex"
+tex_files = FileList["*.tex"]
+png_files = tex_files.ext("png")
+task :tex2png => FileList[png_files]
+png_files.each do |png_file|
+ tex_file = png_file.ext("tex")
+ file png_file => tex_file do
+ #pp png_file, tex_file; exit
+ sh "#{TEX2IMAGE} #{tex_file}"
+ end
+end
+
+
+# recursive だと、サブディレクトリの Rakefile も
+# recursive ターゲットを持っているという前提が必要。
+desc "execute 'rake' in all subdirs with Rakefile"
+rakefiles = FileList["**/Rakefile"]
+dirs = rakefiles.map{|path| Pathname.new(path).dirname.to_s}
+dirs.delete_if {|i| i == '.' }
+dirs.map!{|path| File.absolute_path(path)}
+task :subdir do
+ dirs.each do |dir|
+ Dir.chdir dir
+ system "rake"
+ end
+end
+
+task :all => [:md2html, :subdir]
+
task :pdf => :html2pdf
-task :default => :tree
+#task :default => [:tree, :tex2png, :eps2png]
+task :default => [:md2html, :tex2png, :eps2png]
require "rake/clean"
CLEAN.include( [
html_files,
pdf_files,
- #dirmaps,
])