madowu 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44189e5d16442234da611b91060a05d1bc3cd732
4
- data.tar.gz: 093a5bbf14f4baa1cae59749cfdcb28b3748d8b3
3
+ metadata.gz: decfbfaf61dffe9a4ba5fee8ada06b22f80c5dd1
4
+ data.tar.gz: c4d98b1223c6bc20c5fa9fda7dffff29e5c6713b
5
5
  SHA512:
6
- metadata.gz: f8d0a69c5ab29f7bace895e8aa75b99f106b87b0a55b7edde46b75a113b7016687b3a7e56aa05685cc5d0b47dff75a656a501287389023d5765c704accc726cf
7
- data.tar.gz: 3429b1f6be911870920be080cbc64cd7e79e0078c723d39fdb7ddee885533cc597920015b2ab07eaf2970caa3d5eac1b26b6b98d448082d7cc3d2b6ea5f1a5c2
6
+ metadata.gz: 560b45d6783bb1cc40099412fe804c06837ffdab0f8468597556cb5d4f1fe25bc77516285e840c455693d1eaf3da9e539990e89bd7362a9311edaf06506758d1
7
+ data.tar.gz: ba320592204afc4e654be3e312d2cc51a449cb63e173904dab919eca046f961219e532c2ae0ac456e61c23e0eddc1c385c69ce21c6e03288e7943eb99aff960d
data/CHANGES CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  <!-- Master -->
4
4
 
5
+ == Version 0.0.8 [2017-04-11]
6
+
7
+ * Apply escape_zsh to string for kakasi command
8
+ * Add example/doc
9
+ * Add bin/figchange
10
+ * add bin/tex2image --background white
11
+ * Add bin/dirmap --index-link
12
+ * Rename Madowu::Isbn to Madowu::BookInfo
13
+ * Bugfix of bin/isbninfo
14
+
5
15
  == Version 0.0.7 [2016-07-14]
6
16
 
7
17
  * /bin/madowu is abolished
data/Gemfile CHANGED
@@ -13,4 +13,5 @@ group :development do
13
13
  gem "simplecov", "~> 0.11"
14
14
  gem 'amazon-ecs', "~> 2.4"
15
15
  gem 'tefil', "~> 0.1"
16
+ gem 'builtinextension', "~> 0.1"
16
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/bin/dirmap CHANGED
@@ -19,6 +19,7 @@ op.banner = [
19
19
  op.on("-v" , "--verbose" , "Output to stdout too"){ options[:verbose] = true}
20
20
  op.on("-f" , "--force" , "Force output"){ options[:force] = true}
21
21
  op.on("-k" , "--kakasi" , "Sort by Japanese yomi"){ options[:kakasi] = true}
22
+ op.on("-i" , "--index-link" , "Link to index.html even when not exist"){ options[:index] = true}
22
23
  op.parse!(ARGV)
23
24
 
24
25
  if ARGV.size > 1
@@ -42,7 +43,10 @@ def should_update?(options, outfile, new_contents)
42
43
  end
43
44
 
44
45
  outfile = DEFAULT_OUTFILE
45
- contents = Madowu::DirectoryMapper.dirmap(dir, options[:kakasi])
46
+ contents = Madowu::DirectoryMapper.dirmap(path: dir,
47
+ kakasi: options[:kakasi],
48
+ index: options[:index],
49
+ )
46
50
 
47
51
  if should_update?(options, outfile, contents)
48
52
  io = File.open(outfile, 'w')
@@ -0,0 +1,56 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "optparse"
5
+ require "pp"
6
+ require "string/escapezsh"
7
+
8
+ USAGE = <<HERE
9
+ Usage: #{File.basename("#{__FILE__}")} [options] old_name new_name
10
+ HERE
11
+
12
+ ## option analysis
13
+ options = {}
14
+ op = OptionParser.new
15
+ op.banner = USAGE
16
+ op.on("-g" , "--git" , "git mv"){options[:git] = true}
17
+ op.parse!(ARGV)
18
+
19
+ old_name = ARGV.shift
20
+ new_name = ARGV.shift
21
+
22
+ def execute(command)
23
+ puts command
24
+ system command
25
+ end
26
+
27
+ if Dir.glob("#{new_name}*").empty?
28
+ option = ''
29
+ option += " --git " if options[:git]
30
+ command = "rensub --global #{option} -y #{old_name} #{new_name}"
31
+ execute(command)
32
+ else
33
+ puts "already exist: #{ Dir.glob("#{new_name}*").join(' ')}"
34
+ exit
35
+ end
36
+
37
+ targets = ARGV
38
+ if targets.empty?
39
+ targets += Dir.glob("*.md")
40
+ targets += Dir.glob("*.tex")
41
+ targets += Dir.glob("Rakefile")
42
+ targets.flatten
43
+ end
44
+
45
+ targets.each do |file|
46
+ execute("linesub --global --overwrite #{old_name} #{new_name} #{file}")
47
+
48
+ old_label = "#fig:#{old_name}".escape_zsh
49
+ new_label = "#fig:#{new_name}".escape_zsh
50
+ execute("linesub --global --overwrite #{old_label} #{new_label} #{file}")
51
+
52
+ old_label = "#fig:#{old_name.sub(/^fig/, '')}".escape_zsh
53
+ new_label = "#fig:#{new_name.sub(/^fig/, '')}".escape_zsh
54
+ execute("linesub --global --overwrite #{old_label} #{new_label} #{file}")
55
+ end
56
+
@@ -6,17 +6,31 @@ require 'nokogiri'
6
6
  require "madowu"
7
7
 
8
8
  ARGF.each do |isbn|
9
- book = Madowu::Isbn.new(isbn)
9
+ begin
10
+ #book = Madowu::Isbn.new(isbn, true)
11
+ book = Madowu::BookInfo.load_isbn(isbn)
12
+ end
10
13
 
11
- puts <<HERE
12
- [ ![#{book.title}](#{book.img_url})
13
- #{book.title},
14
- #{book.author},
15
- ISBN:#{book.isbn},
16
- #{book.publisher},
17
- #{book.publication_date}
18
- ](#{book.url})
19
- HERE
14
+ printf("[ ![%s](%s)\n%s,\n%s,\nISBN:\n%s,%s,\n%s\n](%s)\n",
15
+ book.title,
16
+ book.img_url,
17
+ book.title,
18
+ book.author,
19
+ book.isbn,
20
+ book.publisher,
21
+ book.publication_date,
22
+ book.url
23
+ )
24
+
25
+ # puts <<HERE
26
+ #[ ![#{book.title}](#{book.img_url})
27
+ # #{book.title},
28
+ # #{book.author},
29
+ # ISBN:#{book.isbn},
30
+ # #{book.publisher},
31
+ # #{book.publication_date}
32
+ #](#{book.url})
33
+ #HERE
20
34
 
21
35
 
22
36
 
@@ -60,7 +60,7 @@ img_file = Pathname(tex_file).sub_ext(".#{img_ext}").to_s
60
60
 
61
61
  commands = []
62
62
  commands << "#{LATEX} #{tex_file} > /dev/null"
63
- commands << "#{CONVERT} -trim -density #{density}x#{density} #{dvi_file} #{img_file}"
63
+ commands << "#{CONVERT} -background white -alpha deactivate -trim -density #{density}x#{density} #{dvi_file} #{img_file}"
64
64
  execute(commands)
65
65
  commands = []
66
66
 
@@ -1,16 +1,17 @@
1
1
  # coding: utf-8
2
2
  # Rakefile for Markdown documents.
3
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"
4
+ DIRMAP_MD = '.dirmap.md'
5
+ HTML2PDF = "wkhtmltopdf -B 1cm -L 1.5cm -R 1.5cm -T 1.5cm -s A4 --encoding UTF-8 "
6
+ TEX2IMAGE = "tex2image"
7
+ IMAGEMAGICK = "convert -alpha deactivate -density 144x144"
8
+ INKSCAPE = "inkscape"
10
9
 
11
10
  require "pp"
12
11
  require "fileutils"
13
12
  require "pathname"
13
+ require "tempfile"
14
+ require "rake/clean"
14
15
 
15
16
  ## .dirmap.md
16
17
  # dirmap コマンドは必ず実行なので task タスク。
@@ -22,7 +23,7 @@ require "pathname"
22
23
  desc "update .dirmap.md if directory changed."
23
24
  file DIRMAP_MD => :dirmap_command
24
25
  task :dirmap_command do
25
- sh "dirmap" # You can use --kakasi option if the command installed
26
+ sh "dirmap --kakasi"
26
27
  end
27
28
 
28
29
  ## *.html
@@ -35,75 +36,86 @@ html_files.each do |html_file|
35
36
  dirpath = md_path.dirname
36
37
  src = FileList[md_file, DIRMAP_MD]
37
38
  file html_file => [DIRMAP_MD, md_file] do
38
- sh "madowu -O -s .dirmap.md -c madowu.css -C UTF-8 #{md_file}"
39
+ puts "Update: #{md_file} -> #{html_file}"
40
+
41
+ side_lines = `pandoc #{DIRMAP_MD}`.split("\n")
42
+ side_lines.unshift "<div class='sidebar'>"
43
+ side_lines.push "</div>"
44
+
45
+ line = `pandoc -s -N --toc -c madowu.css --mathjax --filter pandoc-crossref #{md_file}`
46
+ lines = line.split("\n")
47
+ end_body = lines.index('</body>')
48
+ lines.insert(end_body, side_lines)
49
+ lines.flatten
50
+ # -N = --number-sections
51
+ # -s = --standalone
52
+ File.open(html_file, "w") {|io| io.puts lines}
39
53
  end
40
54
  html_tasks << html_file
41
55
  end
42
-
56
+ CLEAN.include(html_files)
43
57
  desc "make *.html from *.md"
44
58
  task :md2html => [DIRMAP_MD, * html_tasks]
45
59
 
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
60
  # recursive だと、サブディレクトリの Rakefile も
85
61
  # recursive ターゲットを持っているという前提が必要。
86
62
  desc "execute 'rake' in all subdirs with Rakefile"
87
63
  rakefiles = FileList["**/Rakefile"]
88
64
  dirs = rakefiles.map{|path| Pathname.new(path).dirname.to_s}
89
- dirs.delete_if {|i| i == '.' }
65
+ #dirs.delete_if {|i| i == '.' }
90
66
  dirs.map!{|path| File.absolute_path(path)}
67
+ #pp dirs; exit
91
68
  task :subdir do
92
69
  dirs.each do |dir|
70
+ puts "■" + dir
93
71
  Dir.chdir dir
94
72
  system "rake"
95
73
  end
96
74
  end
97
75
 
98
- task :all => [:md2html, :subdir]
99
-
100
- task :pdf => :html2pdf
101
- #task :default => [:tree, :tex2png, :eps2png]
102
- task :default => [:md2html, :tex2png, :eps2png]
76
+ ############################################################
77
+ ## extension rules
78
+ ## src_exts: array of the extentions that the destination file depends on.
79
+ ## src_exts[0] is used as a 'src' of rake target.
80
+ def rule_src2dst(src_exts, dst_ext)
81
+ desc "convert from .#{src_exts[0]} to #{dst_ext}."
82
+ dst_files = []
83
+ FileList["*.#{src_exts[0]}"].each do |src_file|
84
+ dst_file = src_file.ext(dst_ext)
85
+ basename = File.basename(src_file, ".#{src_exts[0]}")
86
+ src_files = src_exts.map {|ext| FileList["#{basename}.#{ext}"]}.flatten
87
+ src_files.select!{|path| FileTest.exist? path }
88
+ file dst_file => src_files do
89
+ yield(src_files, dst_file)
90
+ end
91
+ dst_files << dst_file
92
+ end
93
+ task "#{src_exts[0]}2#{dst_ext}".to_sym => dst_files
94
+ CLEAN.include(dst_files)
95
+ end
103
96
 
104
- require "rake/clean"
105
- CLEAN.include( [
106
- html_files,
107
- pdf_files,
108
- ])
97
+ rule_src2dst(['pov'], 'png') { |srcs, dst| sh "povray -D #{srcs[0]}"}
98
+ rule_src2dst(['eps'], 'png') { |srcs, dst| sh "#{IMAGEMAGICK} #{srcs[0]} #{dst}"}
99
+ rule_src2dst(['dot'], 'png') { |srcs, dst| sh "dot -Tpng #{srcs[0]} -o #{dst}"}
100
+ rule_src2dst(['tex'], 'png') { |srcs, dst| sh "#{TEX2IMAGE} #{srcs[0]}" }
101
+ rule_src2dst(['svg'], 'eps') { |srcs, dst| sh "#{INKSCAPE} -T -z -E #{dst} #{srcs[0]}" }
102
+ rule_src2dst(['svg'], 'png') { |srcs, dst|
103
+ #直接 png にすると、透明背景で余白ありになる。
104
+ eps_file = Tempfile.new.path
105
+ sh "#{INKSCAPE} -T -z -E #{eps_file} #{srcs[0]}"
106
+ sh "#{IMAGEMAGICK} #{srcs[0]} #{dst}"
107
+ FileUtils.rm eps_file
108
+ }
109
+ rule_src2dst(['rb', 'dat'] , 'png') { |srcs, dst| sh "ruby #{srcs[0]}" }
110
+ rule_src2dst(['rb', 'dat'] , 'eps') { |srcs, dst| sh "ruby #{srcs[0]} --eps"}
111
+ rule_src2dst(['plt', 'dat'] , 'eps') { |srcs, dst| sh "gnuplot ./#{srcs[0]}"}
112
+ rule_src2dst(['html'], 'pdf') { |srcs, dst| sh "#{HTML2PDF} #{srcs[0]} #{dst}"}
113
+
114
+ ############################################################
115
+
116
+ #task :all => [:md2html, :subdir]
117
+ task :default => [:md2html, :tex2png, :svg2png, :rb2png, :pov2png, :dot2png]
118
+ # 基本方針として、html を生成するのをデフォルトとする。
119
+ # :eps2png は、rb2eps と rb2png の関係に干渉する
120
+ # :plt2eps
109
121
 
@@ -0,0 +1,2 @@
1
+ *.png
2
+ *.eps
@@ -0,0 +1,121 @@
1
+ # coding: utf-8
2
+ # Rakefile for Markdown documents.
3
+
4
+ DIRMAP_MD = '.dirmap.md'
5
+ HTML2PDF = "wkhtmltopdf -B 1cm -L 1.5cm -R 1.5cm -T 1.5cm -s A4 --encoding UTF-8 "
6
+ TEX2IMAGE = "tex2image"
7
+ IMAGEMAGICK = "convert -alpha deactivate -density 144x144"
8
+ INKSCAPE = "inkscape"
9
+
10
+ require "pp"
11
+ require "fileutils"
12
+ require "pathname"
13
+ require "tempfile"
14
+ require "rake/clean"
15
+
16
+ ## .dirmap.md
17
+ # dirmap コマンドは必ず実行なので task タスク。
18
+ # これを file にすると存在するときに実行されない。
19
+ # 生成物の .dirmap.md から task タスクへの依存を設定すると、
20
+ # .dirmap.md に依存する file タスクに「必ず実行」が伝播して必ず実行になってしまう。
21
+ # DIRMAP_MD というファイルに対する file タスクへの依存として扱うことで、
22
+ # .dirmap.md に依存する file タスクに「必ず実行」が伝播するのを防いでいる。
23
+ desc "update .dirmap.md if directory changed."
24
+ file DIRMAP_MD => :dirmap_command
25
+ task :dirmap_command do
26
+ sh "dirmap --kakasi"
27
+ end
28
+
29
+ ## *.html
30
+ md_files = FileList["*.md"]
31
+ html_files = md_files.ext("html")
32
+ html_tasks = []
33
+ html_files.each do |html_file|
34
+ md_file = html_file.ext("md")
35
+ md_path = Pathname.new( md_file)
36
+ dirpath = md_path.dirname
37
+ src = FileList[md_file, DIRMAP_MD]
38
+ file html_file => [DIRMAP_MD, md_file] do
39
+ puts "Update: #{md_file} -> #{html_file}"
40
+
41
+ side_lines = `pandoc #{DIRMAP_MD}`.split("\n")
42
+ side_lines.unshift "<div class='sidebar'>"
43
+ side_lines.push "</div>"
44
+
45
+ line = `pandoc -s -N --toc -c madowu.css --mathjax --filter pandoc-crossref #{md_file}`
46
+ lines = line.split("\n")
47
+ end_body = lines.index('</body>')
48
+ lines.insert(end_body, side_lines)
49
+ lines.flatten
50
+ # -N = --number-sections
51
+ # -s = --standalone
52
+ File.open(html_file, "w") {|io| io.puts lines}
53
+ end
54
+ html_tasks << html_file
55
+ end
56
+ CLEAN.include(html_files)
57
+ desc "make *.html from *.md"
58
+ task :md2html => [DIRMAP_MD, * html_tasks]
59
+
60
+ # recursive だと、サブディレクトリの Rakefile も
61
+ # recursive ターゲットを持っているという前提が必要。
62
+ desc "execute 'rake' in all subdirs with Rakefile"
63
+ rakefiles = FileList["**/Rakefile"]
64
+ dirs = rakefiles.map{|path| Pathname.new(path).dirname.to_s}
65
+ #dirs.delete_if {|i| i == '.' }
66
+ dirs.map!{|path| File.absolute_path(path)}
67
+ #pp dirs; exit
68
+ task :subdir do
69
+ dirs.each do |dir|
70
+ puts "■" + dir
71
+ Dir.chdir dir
72
+ system "rake"
73
+ end
74
+ end
75
+
76
+ ############################################################
77
+ ## extension rules
78
+ ## src_exts: array of the extentions that the destination file depends on.
79
+ ## src_exts[0] is used as a 'src' of rake target.
80
+ def rule_src2dst(src_exts, dst_ext)
81
+ desc "convert from .#{src_exts[0]} to #{dst_ext}."
82
+ dst_files = []
83
+ FileList["*.#{src_exts[0]}"].each do |src_file|
84
+ dst_file = src_file.ext(dst_ext)
85
+ basename = File.basename(src_file, ".#{src_exts[0]}")
86
+ src_files = src_exts.map {|ext| FileList["#{basename}.#{ext}"]}.flatten
87
+ src_files.select!{|path| FileTest.exist? path }
88
+ file dst_file => src_files do
89
+ yield(src_files, dst_file)
90
+ end
91
+ dst_files << dst_file
92
+ end
93
+ task "#{src_exts[0]}2#{dst_ext}".to_sym => dst_files
94
+ CLEAN.include(dst_files)
95
+ end
96
+
97
+ rule_src2dst(['pov'], 'png') { |srcs, dst| sh "povray -D #{srcs[0]}"}
98
+ rule_src2dst(['eps'], 'png') { |srcs, dst| sh "#{IMAGEMAGICK} #{srcs[0]} #{dst}"}
99
+ rule_src2dst(['dot'], 'png') { |srcs, dst| sh "dot -Tpng #{srcs[0]} -o #{dst}"}
100
+ rule_src2dst(['tex'], 'png') { |srcs, dst| sh "#{TEX2IMAGE} #{srcs[0]}" }
101
+ rule_src2dst(['svg'], 'eps') { |srcs, dst| sh "#{INKSCAPE} -T -z -E #{dst} #{srcs[0]}" }
102
+ rule_src2dst(['svg'], 'png') { |srcs, dst|
103
+ #直接 png にすると、透明背景で余白ありになるので eps を経由する
104
+ eps_file = Tempfile.new.path
105
+ sh "#{INKSCAPE} -T -z -E #{eps_file} #{srcs[0]}"
106
+ sh "#{IMAGEMAGICK} #{srcs[0]} #{dst}"
107
+ FileUtils.rm eps_file
108
+ }
109
+ rule_src2dst(['rb' , 'dat'], 'png') { |srcs, dst| sh "ruby #{srcs[0]}" }
110
+ rule_src2dst(['rb' , 'dat'], 'eps') { |srcs, dst| sh "ruby #{srcs[0]} --eps"}
111
+ rule_src2dst(['plt', 'dat'], 'eps') { |srcs, dst| sh "gnuplot ./#{srcs[0]}"}
112
+ rule_src2dst(['html' ], 'pdf') { |srcs, dst| sh "#{HTML2PDF} #{srcs[0]} #{dst}"}
113
+
114
+ ############################################################
115
+
116
+ #task :all => [:md2html, :subdir]
117
+ task :default => [:md2html, :tex2png, :svg2png, :rb2png, :pov2png, :dot2png]
118
+ # 基本方針として、html を生成するのをデフォルトとする。
119
+ # :eps2png は、rb2eps と rb2png の関係に干渉する
120
+ # :plt2eps
121
+