Module: Device::Ibunko

Defined in:
lib/device/ibunko.rb

Overview

Copyright 2013 whiteleaf. All rights reserved.

Constant Summary collapse

PHYSICAL_SUPPORT =
false
VOLUME_NAME =
nil
DOCUMENTS_PATH_LIST =
nil
EBOOK_FILE_EXT =
".zip"
NAME =
"iBunko"
DISPLAY_NAME =
"i文庫"
{
  "force.enable_half_indent_bracket" => false,
  "force.enable_dakuten_font" => false
}

Instance Method Summary collapse

Instance Method Details

#hook_convert_txt_to_ebook_file(&original_func) ⇒ Object

i文庫用にテキストと挿絵ファイルをzipアーカイブ化する



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/device/ibunko.rb', line 22

def hook_convert_txt_to_ebook_file(&original_func)
  return false if @options["no-zip"]
  require "zip"
  Zip.unicode_names = true
  dirpath = File.dirname(@converted_txt_path)
  translate_illust_chuki_to_img_tag
  zipfile_path = @converted_txt_path.sub(/.txt$/, @device.ebook_file_ext)
  File.delete(zipfile_path) if File.exists?(zipfile_path)
  Zip::File.open(zipfile_path, Zip::File::CREATE) do |zip|
    zip.add(File.basename(@converted_txt_path), @converted_txt_path)
    illust_dirpath = File.join(dirpath, Illustration::ILLUST_DIR)
    # 挿絵
    if File.exists?(illust_dirpath)
      Dir.glob(File.join(illust_dirpath, "*")) do |img_path|
        zip.add(File.join(Illustration::ILLUST_DIR, File.basename(img_path)), img_path)
      end
    end
    # 表紙画像
    cover_name = NovelConverter.get_cover_filename(dirpath)
    if cover_name
      zip.add(cover_name, File.join(dirpath, cover_name))
    end
  end
  puts File.basename(zipfile_path) + " を出力しました"
  puts "<bold><green>#{@device.display_name}用ファイルを出力しました</green></bold>".termcolor
  zipfile_path
end

#translate_illust_chuki_to_img_tagObject

挿絵注記をimgタグに変換する



53
54
55
56
57
# File 'lib/device/ibunko.rb', line 53

def translate_illust_chuki_to_img_tag
  data = File.read(@converted_txt_path, encoding: Encoding::UTF_8)
  data.gsub!(/[#挿絵((.+?))入る]/, "<img src=\"\\1\">")
  File.write(@converted_txt_path, data)
end