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文庫"
{
  "default.enable_half_indent_bracket" => false
}

Instance Method Summary collapse

Instance Method Details

#hook_convert_txt_to_ebook_file(&original_func) ⇒ Object

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



21
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
49
50
51
52
53
54
55
56
57
58
# File 'lib/device/ibunko.rb', line 21

def hook_convert_txt_to_ebook_file(&original_func)
  return false if @options["no-zip"]
  require "zip"
  Zip.unicode_names = true
  # TODO: テキストファイル変換時もsettingを取れるようにする
  setting = {}
  if @novel_data
    setting = NovelSetting.load(@novel_data["id"], @options["ignore-force"], @options["ignore-default"])
  end
  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.exist?(zipfile_path)
  Zip::File.open(zipfile_path, Zip::File::CREATE) do |zip|
    zip.add(File.basename(@converted_txt_path), @converted_txt_path)
    # 挿絵
    if setting["enable_illust"]
      illust_dirpath = File.join(dirpath, Illustration::ILLUST_DIR)
      if File.exist?(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
    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
  if Narou.economy?("cleanup_temp") && @argument_target_type == :novel
    # 作業用ファイルを削除
    FileUtils.rm_f(@converted_txt_path)
  end
  zipfile_path
end

#translate_illust_chuki_to_img_tagObject

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



63
64
65
66
67
# File 'lib/device/ibunko.rb', line 63

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