madowu 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/example/Rakefile CHANGED
@@ -1,57 +1,50 @@
1
1
  # coding: utf-8
2
2
  # Rakefile for Markdown documents.
3
3
 
4
- #DIRMAP_HTML = '.dirmap.html'
4
+ DIRMAP_MD = '.dirmap.md'
5
5
  ENCODING = "UTF-8"
6
6
  HTML2PDF = "wkhtmltopdf"
7
+ TEX2IMAGE = "tex2image"
7
8
  HTML2PDF_OPTIONS = "-B 1cm -L 1.5cm -R 1.5cm -T 1.5cm -s A4 --encoding #{ENCODING} "
9
+ CONVERT_COMMAND = "convert -alpha deactivate -density 150x150"
8
10
 
9
11
  require "pp"
10
12
  require "fileutils"
11
13
  require "pathname"
12
14
 
13
- desc "Make .sidebar"
14
- #dirmaps = []
15
-
16
- #Dir.glob(['.', "**/*"]).each do |path|
17
- # next unless FileTest.directory? path
18
- #
19
- # dirpath = Pathname.new(path)
20
- # dirmap = "#{dirpath}/#{DIRMAP_HTML}"
21
- # dirmap.sub!(/^\.\//, '')
22
- # dirmaps << dirmap
23
- # #pp dirmap
24
- # file dirmap => [dirpath, dirpath.parent] do
25
- # sh "dirmap #{dirpath} > #{dirpath}/#{DIRMAP_HTML}"
26
- # end
27
- #end
28
- ##pp dirmaps
29
- #task :dirmaps => dirmaps
30
-
31
- desc "Make *.html from *.md"
32
- md_files = FileList["**/*.md"]
15
+ ## .dirmap.md
16
+ # dirmap コマンドは必ず実行なので task タスク。
17
+ # これを file にすると存在するときに実行されない。
18
+ # 生成物の .dirmap.md から task タスクへの依存を設定すると、
19
+ # .dirmap.md に依存する file タスクに「必ず実行」が伝播して必ず実行になってしまう。
20
+ # DIRMAP_MD というファイルに対する file タスクへの依存として扱うことで、
21
+ # .dirmap.md に依存する file タスクに「必ず実行」が伝播するのを防いでいる。
22
+ desc "update .dirmap.md if directory changed."
23
+ file DIRMAP_MD => :dirmap_command
24
+ task :dirmap_command do
25
+ sh "dirmap"
26
+ end
27
+
28
+ ## *.html
29
+ md_files = FileList["*.md"]
33
30
  html_files = md_files.ext("html")
34
- task :md2html => FileList[html_files]
31
+ html_tasks = []
35
32
  html_files.each do |html_file|
36
33
  md_file = html_file.ext("md")
37
34
  md_path = Pathname.new( md_file)
38
35
  dirpath = md_path.dirname
39
- #dirmap = md_path.dirname + DIRMAP_HTML
40
- #file html_file => [md_file, dirmap] do
41
- file html_file => [md_file, dirpath, dirpath.parent] do
42
- #sh "madowu -o -s #{dirmap} -c madowu.css #{md_file}"
43
- sh "madowu -o -d -c madowu.css -C UTF-8 #{md_file}"
36
+ src = FileList[md_file, DIRMAP_MD]
37
+ file html_file => [DIRMAP_MD, md_file] do
38
+ sh "madowu -O -s .dirmap.md -c madowu.css -C UTF-8 #{md_file}"
44
39
  end
40
+ html_tasks << html_file
45
41
  end
46
42
 
47
- desc "Update mtime of all html files"
48
- task :tree => :md2html do
49
- html_files.each do |html_file|
50
- File.utime(Time.now, Time.now, html_file)
51
- end
52
- end
43
+ desc "make *.html from *.md"
44
+ task :md2html => [DIRMAP_MD, * html_tasks]
53
45
 
54
- desc "Make *.pdf from *.html"
46
+
47
+ desc "make *.pdf from *.html"
55
48
  pdf_files = html_files.ext("pdf")
56
49
  task :html2pdf => FileList[pdf_files]
57
50
  pdf_files.each do |pdf_file|
@@ -62,13 +55,55 @@ pdf_files.each do |pdf_file|
62
55
  end
63
56
 
64
57
 
58
+ desc "make .png from .eps."
59
+ eps_files = FileList["*.eps"]
60
+ png_files = eps_files.ext("png")
61
+ task :eps2png => FileList[png_files]
62
+ png_files.each do |png_file|
63
+ eps_file = png_file.ext("eps")
64
+ t = [eps_file]
65
+ file png_file => t do
66
+ sh "#{CONVERT_COMMAND} #{eps_file} #{png_file}"
67
+ end
68
+ end
69
+
70
+
71
+ desc "make *.png from *.tex"
72
+ tex_files = FileList["*.tex"]
73
+ png_files = tex_files.ext("png")
74
+ task :tex2png => FileList[png_files]
75
+ png_files.each do |png_file|
76
+ tex_file = png_file.ext("tex")
77
+ file png_file => tex_file do
78
+ #pp png_file, tex_file; exit
79
+ sh "#{TEX2IMAGE} #{tex_file}"
80
+ end
81
+ end
82
+
83
+
84
+ # recursive だと、サブディレクトリの Rakefile も
85
+ # recursive ターゲットを持っているという前提が必要。
86
+ desc "execute 'rake' in all subdirs with Rakefile"
87
+ rakefiles = FileList["**/Rakefile"]
88
+ dirs = rakefiles.map{|path| Pathname.new(path).dirname.to_s}
89
+ dirs.delete_if {|i| i == '.' }
90
+ dirs.map!{|path| File.absolute_path(path)}
91
+ task :subdir do
92
+ dirs.each do |dir|
93
+ Dir.chdir dir
94
+ system "rake"
95
+ end
96
+ end
97
+
98
+ task :all => [:md2html, :subdir]
99
+
65
100
  task :pdf => :html2pdf
66
- task :default => :tree
101
+ #task :default => [:tree, :tex2png, :eps2png]
102
+ task :default => [:md2html, :tex2png, :eps2png]
67
103
 
68
104
  require "rake/clean"
69
105
  CLEAN.include( [
70
106
  html_files,
71
107
  pdf_files,
72
- #dirmaps,
73
108
  ])
74
109
 
data/example/eq.tex ADDED
@@ -0,0 +1,9 @@
1
+ \documentclass[a4paper,11pt]{article}
2
+ \pagestyle{empty}
3
+ \begin{document} %----------------------------------------------------
4
+
5
+ \begin{eqnarray*}
6
+ e^{i\theta} &=& \cos \theta + i \sin \theta
7
+ \end{eqnarray*}
8
+
9
+ \end{document}
data/example/index.md CHANGED
@@ -3,3 +3,6 @@
3
3
  * [enum.html](enum.html)
4
4
  * [heading.html](heading.html)
5
5
  * [list.html](list.html)
6
+
7
+ ![equation](eq.png)
8
+
data/example/madowu.css CHANGED
@@ -56,6 +56,7 @@ span.adminmenu {
56
56
  white-space: nowrap;
57
57
  }
58
58
 
59
+ /*
59
60
  h1 {
60
61
  height: 64px;
61
62
  line-height: 64px;
@@ -67,13 +68,20 @@ h1 {
67
68
  h2 {
68
69
  font-size: 160%;
69
70
  }
71
+ */
70
72
 
71
73
  div.body {
72
74
  margin-left: 1.8em;
73
75
  line-height: 120%;
76
+ font-size: 100%;
77
+ }
78
+
79
+ div.body h1 {
80
+ font-size: 160%;
74
81
  }
75
82
 
76
83
  div.body h2 {
84
+ font-size: 150%;
77
85
  margin-top: 1.5em;
78
86
  margin-bottom: 0.5em;
79
87
  padding: 0.4em 0.4em 0.4em 0.4em;
@@ -83,6 +91,7 @@ div.body h2 {
83
91
  }
84
92
 
85
93
  div.body h3 {
94
+ font-size: 140%;
86
95
  margin-top: 1.5em;
87
96
  margin-bottom: 0.5em;
88
97
  padding: 0.4em 0.4em 0.4em 0.4em;
@@ -92,14 +101,14 @@ div.body h3 {
92
101
  }
93
102
 
94
103
  div.body h4 {
95
- font-size: 140%;
104
+ font-size: 130%;
96
105
  padding: 0.4em 0.4em 0.4em 0.4em;
97
106
  border-top: solid 2px #48c;
98
107
  border-left: solid 2px #48c;
99
108
  border-right: solid 2px #48c;
100
109
  }
101
110
  div.body h5 {
102
- font-size: 140%;
111
+ font-size: 120%;
103
112
  padding: 0.4em 0.4em 0.4em 0.4em;
104
113
  border-top: solid 1px #48c;
105
114
  border-left: solid 1px #48c;
@@ -0,0 +1,109 @@
1
+ # coding: utf-8
2
+ # Rakefile for Markdown documents.
3
+
4
+ DIRMAP_MD = '.dirmap.md'
5
+ ENCODING = "UTF-8"
6
+ HTML2PDF = "wkhtmltopdf"
7
+ TEX2IMAGE = "tex2image"
8
+ HTML2PDF_OPTIONS = "-B 1cm -L 1.5cm -R 1.5cm -T 1.5cm -s A4 --encoding #{ENCODING} "
9
+ CONVERT_COMMAND = "convert -alpha deactivate -density 150x150"
10
+
11
+ require "pp"
12
+ require "fileutils"
13
+ require "pathname"
14
+
15
+ ## .dirmap.md
16
+ # dirmap コマンドは必ず実行なので task タスク。
17
+ # これを file にすると存在するときに実行されない。
18
+ # 生成物の .dirmap.md から task タスクへの依存を設定すると、
19
+ # .dirmap.md に依存する file タスクに「必ず実行」が伝播して必ず実行になってしまう。
20
+ # DIRMAP_MD というファイルに対する file タスクへの依存として扱うことで、
21
+ # .dirmap.md に依存する file タスクに「必ず実行」が伝播するのを防いでいる。
22
+ desc "update .dirmap.md if directory changed."
23
+ file DIRMAP_MD => :dirmap_command
24
+ task :dirmap_command do
25
+ sh "dirmap"
26
+ end
27
+
28
+ ## *.html
29
+ md_files = FileList["*.md"]
30
+ html_files = md_files.ext("html")
31
+ html_tasks = []
32
+ html_files.each do |html_file|
33
+ md_file = html_file.ext("md")
34
+ md_path = Pathname.new( md_file)
35
+ dirpath = md_path.dirname
36
+ src = FileList[md_file, DIRMAP_MD]
37
+ file html_file => [DIRMAP_MD, md_file] do
38
+ sh "madowu -O -s .dirmap.md -c madowu.css -C UTF-8 #{md_file}"
39
+ end
40
+ html_tasks << html_file
41
+ end
42
+
43
+ desc "make *.html from *.md"
44
+ task :md2html => [DIRMAP_MD, * html_tasks]
45
+
46
+
47
+ desc "make *.pdf from *.html"
48
+ pdf_files = html_files.ext("pdf")
49
+ task :html2pdf => FileList[pdf_files]
50
+ pdf_files.each do |pdf_file|
51
+ html_file = pdf_file.ext("html")
52
+ file pdf_file => html_file do
53
+ sh "#{HTML2PDF} #{HTML2PDF_OPTIONS} #{html_file} #{pdf_file}"
54
+ end
55
+ end
56
+
57
+
58
+ desc "make .png from .eps."
59
+ eps_files = FileList["*.eps"]
60
+ png_files = eps_files.ext("png")
61
+ task :eps2png => FileList[png_files]
62
+ png_files.each do |png_file|
63
+ eps_file = png_file.ext("eps")
64
+ t = [eps_file]
65
+ file png_file => t do
66
+ sh "#{CONVERT_COMMAND} #{eps_file} #{png_file}"
67
+ end
68
+ end
69
+
70
+
71
+ desc "make *.png from *.tex"
72
+ tex_files = FileList["*.tex"]
73
+ png_files = tex_files.ext("png")
74
+ task :tex2png => FileList[png_files]
75
+ png_files.each do |png_file|
76
+ tex_file = png_file.ext("tex")
77
+ file png_file => tex_file do
78
+ #pp png_file, tex_file; exit
79
+ sh "#{TEX2IMAGE} #{tex_file}"
80
+ end
81
+ end
82
+
83
+
84
+ # recursive だと、サブディレクトリの Rakefile も
85
+ # recursive ターゲットを持っているという前提が必要。
86
+ desc "execute 'rake' in all subdirs with Rakefile"
87
+ rakefiles = FileList["**/Rakefile"]
88
+ dirs = rakefiles.map{|path| Pathname.new(path).dirname.to_s}
89
+ dirs.delete_if {|i| i == '.' }
90
+ dirs.map!{|path| File.absolute_path(path)}
91
+ task :subdir do
92
+ dirs.each do |dir|
93
+ Dir.chdir dir
94
+ system "rake"
95
+ end
96
+ end
97
+
98
+ task :all => [:md2html, :subdir]
99
+
100
+ task :pdf => :html2pdf
101
+ #task :default => [:tree, :tex2png, :eps2png]
102
+ task :default => [:md2html, :tex2png, :eps2png]
103
+
104
+ require "rake/clean"
105
+ CLEAN.include( [
106
+ html_files,
107
+ pdf_files,
108
+ ])
109
+