aozora2html 0.3.0 → 0.4.0

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: c728a5e7de9b498b6ffb3a3d14e93618d0d5a1c3
4
- data.tar.gz: bb7c9aba17c5e9104b33b95e903bac5ab583314b
3
+ metadata.gz: 2d5866db44c93055109ebd1523d14adbc54430b4
4
+ data.tar.gz: 024cf855007a18c9b4592fa1576cc50394b52f3b
5
5
  SHA512:
6
- metadata.gz: 00407b60c3bf56507c99996e7412983db7e048312df52a500f18bf625abeac3eb2ff74a280552520186282efd9e719ac09ce1a5523d9b8bd5853a13824244bc7
7
- data.tar.gz: 7269f8c1a43bfcfbd6be044f33836aaa2cda31dfad98e5b74623df3273195174275edc5c3314a5390bc0d7afc6ca397724f2af93013b84a3e43c47f8bce5dcea
6
+ metadata.gz: d022e52edd4ad4d8d329e6b9aa3421505e60942bdc80b558bf2691a1e871b7053b10fae60b1b6493d5d6670ff4554822f2996056e86de695e4cb0430a01b4d60
7
+ data.tar.gz: 67f47a64d1df309ffcef401e9faef8b466a56fbb00a26d8b17afcac0bdc78d95264167af01b6d249f58f3661279262fe3ab849bc4b8e47c88277d29762c8204e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ <a name="0.4.0"></a>
2
+ ## 0.4.0
3
+
4
+ ### Features
5
+
6
+ * 第1引数にファイル名ではなく`http://...`といったURLを与えた場合、そのURLのファイルをダウンロードしHTMLに変換するようにした
7
+ * 第1引数が省略された場合、結果をファイルではなく標準出力に出力するようにした
8
+
1
9
  <a name="0.3.0"></a>
2
10
  ## 0.3.0
3
11
 
data/README.md CHANGED
@@ -39,6 +39,18 @@ $ aozora2html foo.txt foo.html
39
39
  $ aozora2html foo.zip foo.html
40
40
  ```
41
41
 
42
+ 第1引数にURLを指定すると、そのURLのファイルをダウンロードして変換します。
43
+
44
+ ```
45
+ $ aozora2html http://example.jp/foo/bar.zip foo.html
46
+ ```
47
+
48
+ 第2引数を省略すると、ファイルではなく標準出力に変換結果を出力します。
49
+
50
+ ```
51
+ $ aozora2html foo.txt
52
+ ```
53
+
42
54
  コマンドラインオプションとして`--gaiji-dir`と`--use-jisx0213`があります。
43
55
  `--gaiji-dir`は外字画像のパスを指定します。
44
56
  `--use-jisx0213`はJIS X 0213の外字画像を使わず、数値実体参照として表示します。
data/bin/aozora2html CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'aozora2html'
4
4
  require 'optparse'
5
+ require "tempfile"
5
6
 
6
7
  # override Aozora2Html#push_chars
7
8
  #
@@ -27,7 +28,7 @@ class Aozora2Html
27
28
  end
28
29
  end
29
30
 
30
- opt = OptionParser.new("Usage: aozora2html [options] <text file> <html file>\n")
31
+ opt = OptionParser.new("Usage: aozora2html [options] <text file> [<html file>]\n")
31
32
  opt.on('--gaiji-dir DIR', 'setting gaiji directory')
32
33
  opt.on('--use-jisx0213', 'setting gaiji directory')
33
34
  opt.version = Aozora2Html::VERSION
@@ -41,24 +42,47 @@ if options["use-jisx0213"]
41
42
  Embed_Gaiji_tag.use_jisx0213 = true
42
43
  end
43
44
 
44
- if ARGV.size != 2
45
+ if ARGV.size < 1 || ARGV.size > 2
45
46
  $stderr.print opt.banner
46
47
  exit 1
47
48
  end
48
49
 
49
- if !File.exists?(ARGV[0])
50
- $stderr.print "file not found: #{ARGV[0]}\n"
51
- exit 1
52
- end
50
+ src_file, dest_file = ARGV[0], ARGV[1]
53
51
 
54
- if File.extname(ARGV[0]) == ".zip"
55
- require "tempfile"
56
- Dir.mktmpdir do |dir|
52
+ Dir.mktmpdir do |dir|
53
+ if dest_file.nil?
54
+ dest_file = File.join(dir, "output.html")
55
+ end
56
+ if src_file =~ /\Ahttps?:/
57
+ require 'open-uri'
58
+ down_file = File.join(dir, File.basename(src_file))
59
+ begin
60
+ open(down_file, "wb") do |f0|
61
+ open(src_file){|f1| f0.write(f1.read)}
62
+ end
63
+ src_file = down_file
64
+ rescue
65
+ $stderr.print "file not found: #{src_file}\n"
66
+ $stderr.print "Download Error: #{$!}\n"
67
+ exit 1
68
+ end
69
+ else
70
+ if !File.exists?(src_file)
71
+ $stderr.print "file not found: #{src_file}\n"
72
+ exit 1
73
+ end
74
+ end
75
+
76
+ if File.extname(src_file) == ".zip"
57
77
  tmpfile = File.join(dir, "aozora.txt")
58
- Aozora2Html::Zip.unzip(ARGV[0], tmpfile)
59
- Aozora2Html.new(tmpfile, ARGV[1]).process
78
+ Aozora2Html::Zip.unzip(src_file, tmpfile)
79
+ Aozora2Html.new(tmpfile, dest_file).process
80
+ else
81
+ Aozora2Html.new(src_file, dest_file).process
82
+ end
83
+ if !ARGV[1]
84
+ output = File.read(dest_file)
85
+ print output
60
86
  end
61
- else
62
- Aozora2Html.new(ARGV[0], ARGV[1]).process
63
87
  end
64
88
 
@@ -1,3 +1,3 @@
1
1
  class Aozora2Html
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aozora2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aozorahack team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-31 00:00:00.000000000 Z
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip