Sha256: 47b12648b8dffc905bd6ac775f76d58ec41afe98e7b71b0efd55fe9ff3d75759

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

# -*- coding: utf-8 -*-
#
# Copyright 2013 whiteleaf. All rights reserved.
#

module Device::Ibunko
  PHYSICAL_SUPPORT = false
  VOLUME_NAME = nil
  DOCUMENTS_PATH_LIST = nil
  EBOOK_FILE_EXT = ".zip"
  NAME = "iBunko"
  DISPLAY_NAME = "i文庫"

  RELATED_VARIABLES = {
    "force.enable_half_indent_bracket" => false,
    "force.enable_dakuten_font" => false
  }

  #
  # i文庫用にテキストと挿絵ファイルをzipアーカイブ化する
  #
  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.exist?(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.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
      # 表紙画像
      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

  #
  # 挿絵注記をimgタグに変換する
  #
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
narou-1.7.1 lib/device/ibunko.rb