class Object

Constants

PREDEF_FILE
REVIEW_EPUBMAKER
REVIEW_PDFMAKER

Public Instance Methods

_main() click to toggle source
# File ../../../../../bin/review-compile, line 36
def _main
  mode = :files
  basedir = nil
  if /\Areview2/ =~ File.basename($0)
    target = File.basename($0, '.rb').sub(/review2/, '')
  else
    target = nil
  end
  check_only = false
  output_filename = nil

  config = ReVIEW::Configure.values
  config.merge!({
    "secnolevel" => 2, # for IDGXML and HTML
    "tableopt" => nil, # for IDGXML
    "nolf" => nil, # for IDGXML
    "chapref" => nil, # for IDGXML
    "structuredxml" => nil, # for IDGXML
    "stylesheet" => [], # for HTML
    "mathml" => nil, # for HTML
    "language" => "ja", # for HTML
    "deprecated-blocklines" => nil,
    "footnotetext" => false,
    "htmlext" => "html",
    "htmlversion" => 4,
  })

  opts = OptionParser.new
  opts.version = ReVIEW::VERSION
  opts.banner = "Usage: #{File.basename($0)} [--target=FMT]"
  opts.on('--yaml=YAML', 'Read configurations from YAML file.') do |yaml|
    require 'yaml'
    config = config.merge(YAML.load_file(yaml))
  end
  opts.on('-c', '--check', 'Check manuscript') { check_only = true }
  opts.on('--level=LVL', 'Section level to append number.') {|lvl| config["secnolevel"] = lvl.to_i }
  opts.on('--toclevel=LVL', 'Section level to append number.') {|lvl| config["toclevel"] = lvl.to_i }
  opts.on('--nolfinxml', 'Do not insert LF in XML. (idgxml)') { config["nolf"] = true }
  opts.on('--structuredxml', 'Produce XML with structured sections. (idgxml)') { config["structuredxml"] = true }
  opts.on('--table=WIDTH', 'Default table width. (idgxml)') {|tbl| config["tableopt"] = tbl }
  opts.on('--listinfo', 'Append listinfo tag to lists to indicate begin/end. (idgxml)') { config["listinfo"] = true }
  opts.on('--chapref="before,middle,after"', 'Chapref decoration.') {|cdec| config["chapref"] = cdec }
  opts.on('--subdirmode', 'Use chapter/id.ext path style to find images. (deprecated)') do
    STDERR.puts "Warning: --subdirmode is deprecated. Images are automatically detected."
  end
  opts.on('--singledirmode', 'Use id.ext path style to find images. (deprecated)') do
    STDERR.puts "Warning: --singledirmode is deprecated. Images are automatically detected."
  end
  opts.on('--chapterlink', 'make chapref hyperlink') { config["chapterlink"] = true }
  opts.on('--stylesheet=file', 'Stylesheet file for HTML (comma separated)') {|files| config["stylesheet"] = files.split(/\s*,\s*/) }
  opts.on('--mathml', 'Use MathML for TeX equation in HTML') do
    config["mathml"] = true
  end
  opts.on('--htmlversion=VERSION', 'HTML version.') do |v|
    v = v.to_i
    config["htmlversion"] = v if v == 4 || v == 5
  end
  opts.on('--epubversion=VERSION', 'EPUB version.') do |v|
    v = v.to_i
    config["epubversion"] = v if v == 2 || v == 3
  end
  opts.on('--hdnumberingmode', 'Output numbering headlines. (deprecated)') { config["hdnumberingmode"] = true }
  opts.on('--deprecated-blocklines', 'Disable paragrahs in block tags. Treat physical line as a paragraph. (deprecated)') { config["deprecated-blocklines"] = true }
  opts.on('--target=FMT', 'Target format.') {|fmt| target = fmt } unless target
  opts.on('--footnotetext',
            'Use footnotetext and footnotemark instead of footnote (latex)') {
    config["footnotetext"] = true
  }
  opts.on('--draft', 'use draft mode(inline comment)') { config["draft"] = true }
  opts.on('-a', '--all', 'Compile all chapters.') do
    mode = :dir
    basedir = nil
  end
  opts.on('--directory=DIR', 'Compile all chapters in DIR.') do |path|
    mode = :dir
    basedir = path
  end
  opts.on('--output-file=FILENAME', 'Write all results into file instead of stdout.') do |filename|
    output_filename = filename
  end
  opts.on('--tabwidth=WIDTH', 'tab width') {|width| config["tabwidth"] = width.to_i }
  opts.on('--catalogfile=FILENAME', 'Set catalog file') do |catalogfile|
    config["catalogfile"] = catalogfile
  end
  opts.on('--help', 'Prints this message and quit.') do
    puts opts.help
    exit 0
  end
  begin
    opts.parse!
    unless target
      if check_only
        target = 'html'
      else
        raise OptionParser::ParseError, "no target given"
      end
    end
  rescue OptionParser::ParseError => err
    error err.message
    $stderr.puts opts.help
    exit 1
  end

  begin
    config["builder"] = target
    ReVIEW::I18n.setup(config["language"])

    case mode
    when :files
      if ARGV.empty?
        error 'no input'
        exit 1
      end

      basedir = File.dirname(ARGV[0])
      book = ReVIEW::Book::Base.load(basedir)
      book.config = config # needs only at the first time
      ARGV.each do |item|
        chap_name = File.basename(item, '.*')
        chap = book.chapter(chap_name)
        compiler = ReVIEW::Compiler.new(load_strategy_class(target, check_only))
        result = compiler.compile(chap)
        if output_filename
          write output_filename, result
        else
          puts result unless check_only
        end
      end
    when :dir
      book = basedir ? ReVIEW::Book.load(basedir) : ReVIEW::Book::Base.load
      book.config = config
      compiler = ReVIEW::Compiler.new(load_strategy_class(target, check_only))
      book.chapters.each do |chap|
        str = compiler.compile(chap)
        write "#{chap.name}#{compiler.strategy.extname}", str unless check_only
      end
      # PART
      book.parts_in_file.each do |part|
        str = compiler.compile(part)
        write "#{part.name}#{compiler.strategy.extname}", str unless check_only
      end
    else
      raise "must not happen: #{mode}"
    end
  rescue ReVIEW::ApplicationError => err
    raise if $DEBUG
    error err.message
    exit 1
  end
end
_parse(str, header) click to toggle source
# File ../../../../../bin/review-catalog-converter, line 87
def _parse(str, header)
  if str.present?
    header + str.split("\n").map{|i| "  - #{i}\n" }.join
  else
    header
  end
end
assets_dir() click to toggle source
# File ../../../../../test/test_helper.rb, line 9
def assets_dir
  File.join(File.dirname(__FILE__), "assets")
end
blank?() click to toggle source
# File ../../../../../lib/review/extentions/object.rb, line 2
def blank?
  respond_to?(:empty?) ? empty? : !self
end
chapnumstr(n) click to toggle source
# File ../../../../../bin/review-vol, line 96
def chapnumstr(n)
  n ? sprintf('%2d.', n) : '   '
end
check_text(files) click to toggle source
# File ../../../../../bin/review-check, line 80
def check_text(files)
  re, neg = words_re("#{@book.basedir}/#{@book.reject_file}")
  files.each do |path|
    File.open(path) {|f|
      each_paragraph(f) do |para, lineno|
        s = para.join('')
        if m = re.match(s)
          next if m[0] == @review_utils_word_ok
          next if neg and neg =~ s
          str, offset = find_line(para, re)
          out = sprintf("%s:%d: %s\n", path, lineno + offset, str)
          print out
        end
      end
    }
  end
end
compile_block(text) click to toggle source
# File ../../../../../test/test_helper.rb, line 23
def compile_block(text)
  method_name = "compile_block_#{@builder.target_name}"
  if !self.respond_to?(method_name, true)
    method_name = "compile_block_default"
  end
  self.__send__(method_name, text)
end
compile_block_default(text) click to toggle source
# File ../../../../../test/test_helper.rb, line 31
def compile_block_default(text)
  @chapter.content = text
  @compiler.compile(@chapter)
end
compile_block_html(text) click to toggle source
# File ../../../../../test/test_helper.rb, line 36
def compile_block_html(text)
  @chapter.content = text
  matched = @compiler.compile(@chapter).match(/<body>\n(.+)<\/body>/)
  if matched && matched.size > 1
    matched[1]
  else
    ""
  end
end
compile_block_idgxml(text) click to toggle source
# File ../../../../../test/test_helper.rb, line 46
def compile_block_idgxml(text)
  @chapter.content = text
  @compiler.compile(@chapter).gsub(/.*<doc xmlns:aid="http:\/\/ns.adobe.com\/AdobeInDesign\/4.0\/">/,"").gsub(/<\/doc>\n/, "")
end
compile_inline(text) click to toggle source
# File ../../../../../test/test_helper.rb, line 19
def compile_inline(text)
  @builder.compile_inline(text)
end
each_paragraph(f) { |[$1], filename, lineno| ... } click to toggle source
# File ../../../../../bin/review-check, line 130
def each_paragraph(f)
  @review_utils_word_ok = nil
  while line = f.gets
    case line
    when /\A\#@ok\((.*)\)/
      @review_utils_word_ok = $1
    when /\A\#@/
      ;
    when %r[\A//caption\{(.*?)//\}]
      yield [$1], f.filename, f.lineno
    when %r<\A//\w.*\{\s*\z>
      while line = f.gets
        break if %r<//\}> === line
      end
    when /\A=/
      yield [line.slice(/\A=+(?:\[.*?\])?\s+(.*)/, 1).strip], f.lineno
    when /\A\s*\z/
      # skip
    else
      buf = [line.strip]
      lineno = f.lineno
      while line = f.gets
        break if line.strip.empty?
        break if %r<\A(?:=|//[\w\}])> =~ line
        next if %r<\A\#@> =~ line
        buf.push line.strip
      end
      yield buf, lineno
      @review_utils_word_ok = nil
    end
  end
end
each_paragraph_line(f, &block) click to toggle source
# File ../../../../../bin/review-check, line 163
def each_paragraph_line(f, &block)
  each_paragraph(f) do |para, *|
    para.each(&block)
  end
end
error(msg) click to toggle source
# File ../../../../../bin/review-compile, line 187
def error(msg)
  $stderr.puts "#{File.basename($0, '.*')}: error: #{msg}"
end
error_exit(msg) click to toggle source
# File ../../../../../bin/review-index, line 105
def error_exit(msg)
  $stderr.puts "#{File.basename($0)}: #{msg}"
  exit 1
end
find_line(lines, re) click to toggle source
# File ../../../../../bin/review-check, line 98
def find_line(lines, re)
  # single line?
  lines.each_with_index do |line, idx|
    return line.gsub(re, '<<<\&>>>'), idx if re =~ line
  end

  # multiple lines?
  i = 0
  while i < lines.size - 1
    str = lines[i] + lines[i+1]
    return str.gsub(re, '<<<\&>>>'), i if re =~ str
    i += 1
  end

  raise 'must not happen'
end
generate_catalog_file(dir) click to toggle source
# File ../../../../../bin/review-init, line 93
def generate_catalog_file(dir)
  File.open(dir + "/catalog.yml", "w") do |file|
    file.write <<-EOS
PREDEF:

CHAPS:
  - #{File.basename(dir)}.re

APPENDIX:

POSTDEF:

EOS
  end
end
generate_config(dir) click to toggle source
# File ../../../../../bin/review-init, line 117
def generate_config(dir)
  if @epub_version.to_i == 2
    FileUtils.cp @review_dir + "/test/sample-book/src/config-epub2.yml", File.join(dir, "config.yml")
  else
    FileUtils.cp @review_dir + "/test/sample-book/src/config.yml", dir
  end
end
generate_cover_image(dir) click to toggle source
# File ../../../../../bin/review-init, line 113
def generate_cover_image(dir)
  FileUtils.cp @review_dir + "/test/sample-book/src/images/cover.jpg", dir + '/images/'
end
generate_dir(dir) { |dir| ... } click to toggle source
# File ../../../../../bin/review-init, line 67
def generate_dir(dir)
  if File.exist?(dir) && !@force
    puts "#{dir} already exists."
    exit
  end
  FileUtils.mkdir_p dir
  yield dir
end
generate_images_dir(dir) click to toggle source
# File ../../../../../bin/review-init, line 109
def generate_images_dir(dir)
  FileUtils.mkdir_p dir + '/images'
end
generate_layout(dir) click to toggle source
# File ../../../../../bin/review-init, line 84
def generate_layout(dir)
  FileUtils.mkdir_p dir + '/layouts'
  if @epub_version.to_i == 2
    FileUtils.cp @review_dir + "/templates/html/layout-xhtml1.html.erb", dir + '/layouts/layout.html.erb'
  else
    FileUtils.cp @review_dir + "/templates/html/layout-html5.html.erb", dir + '/layouts/layout.html.erb'
  end
end
generate_locale(dir) click to toggle source
# File ../../../../../bin/review-init, line 139
def generate_locale(dir)
  FileUtils.cp @review_dir + '/lib/review/i18n.yml', dir + '/locale.yml'
end
generate_rakefile(dir) click to toggle source
# File ../../../../../bin/review-init, line 135
def generate_rakefile(dir)
  FileUtils.cp @review_dir + "/test/sample-book/src/Rakefile", dir
end
generate_sample(dir) click to toggle source
# File ../../../../../bin/review-init, line 76
def generate_sample(dir)
  if !@force
    File.open("#{dir}/#{File.basename(dir)}.re", "w") do |file|
      file.write("= ")
    end
  end
end
generate_style(dir) click to toggle source
# File ../../../../../bin/review-init, line 125
def generate_style(dir)
  FileUtils.cp @review_dir + "/test/sample-book/src/style.css", dir
end
generate_texmacro(dir) click to toggle source
# File ../../../../../bin/review-init, line 129
def generate_texmacro(dir)
  texmacrodir = dir + '/sty'
  FileUtils.mkdir_p texmacrodir
  FileUtils.cp @review_dir + "/test/sample-book/src/sty/reviewmacro.sty", texmacrodir
end
getFigId(filename) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 806
def getFigId(filename)
  figid = filename.sub(/\.(png|gif|jpg|jpeg|svg)$/, '')
  "fig-#{figid}"
end
getTitle(filename) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 811
def getTitle(filename)
  File.open(filename) {|f|
    return REXML::Document.new(f).elements["//html/head/title"].text
  }
end
getanchors(filename) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 817
def getanchors(filename)
  File.open(filename) {|f|
    file = filename.sub(/.+\//, '')
    f.each_line {|l|
      if l =~ /\A<h(\d)[^>]*><a id=\"(.+?)\"><\/a>(.+?)<\/h/
        # level, ID, content
        @tocdesc << [$1.to_i, file, $2, $3]
      end
    }
  }
end
include_mathml?(filename) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 795
def include_mathml?(filename)
  File.open(filename) {|f|
    REXML::Document.new(f).each_element("//math"){
      return true
    }
    return false
  }
rescue
  false
end
join_names(param) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 829
def join_names(param)
  if param.respond_to?(:join)
    param.join(ReVIEW::I18n.t("names_splitter"))
  else
    param
  end
end
load_strategy_class(target, strict) click to toggle source
# File ../../../../../bin/review-compile, line 191
def load_strategy_class(target, strict)
  require "review/#{target}builder"
  ReVIEW.const_get("#{target.upcase}Builder").new(strict)
end
location() click to toggle source
# File ../../../../../bin/review-checkdep, line 59
def location
  "#{ARGF.filename}:#{ARGF.file.lineno}"
end
main() click to toggle source
# File ../../../../../bin/review-catalog-converter, line 19
def main
  opts = OptionParser.new
  opts.version = ReVIEW::VERSION
  opts.banner = "Usage: #{File.basename($0)} dirname"
  opts.on('-h', '--help', 'print this message and quit.') do
    puts opts.help
    exit 0
  end

  begin
    opts.parse!
  rescue OptionParser::ParseError => err
    $stderr.puts err.message
    $stderr.puts opts.help
    exit 1
  end

  dir = Dir.pwd

  # confirmation
  if File.exist?("#{dir}/catalog.yml")
    while true
      print "The catalog.yml already exists. Do you want to overwrite it? [y/n]"
      case gets
      when /^[yY]/
        puts "Start writing..."
        break
      when /^[nN]/, /^$/
        puts "bye."
        exit
      end
    end
  end

  File.open("#{dir}/catalog.yml", "w") do |catalog|
    # predef
    if File.exist?("#{dir}/PREDEF")
      catalog << parse_predef(File.open("#{dir}/PREDEF").read)
    end
    # chaps and parts
    if File.exist?("#{dir}/CHAPS")
      if File.exist?("#{dir}/PART")
        catalog << parse_parts(File.open("#{dir}/PART").read,
                               File.open("#{dir}/CHAPS").read)
      else
        catalog << parse_chaps(File.open("#{dir}/CHAPS").read)
      end
    end
    # postdef
    if File.exist?("#{dir}/POSTDEF")
      postdef = File.open("#{dir}/POSTDEF").read
      while true
        print "Do you want to convert POSTDEF into APPENDIX? [y/n]"
        case gets
        when /^[yY]/
          catalog << parse_postdef(postdef, true)
          break
        when /^[nN]/, /^$/
          catalog << parse_postdef(postdef)
          break
        end
      end
    end
  end

  puts File.open("#{dir}/catalog.yml").read
end
make_backcover_image(bookname, values) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 968
def make_backcover_image(bookname, values)
  backcoverfile = values["backcoverfile"]
  File.open("#{@bookdir}/OEBPS/#{backcoverfile}", "w") {|f|
    f.puts <<EOT
<?xml version="1.0" encoding="UTF-8"?>
EOT
    doctype = make_doctype()
    f.puts doctype
    f.puts <<EOT
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="ja">
<head>
EOT
  if @htmlversion == 4
    f.puts <<EOT
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
  <meta http-equiv="Content-Style-Type" content="text/css"/>
  <link rel="stylesheet" type="text/css" href="#{values["stylesheet"]}"/>
  <meta name="generator" content="Re:VIEW EPUB Maker"/>
EOT
  else
    f.puts <<EOT
  <meta charset="UTF-8" />
  <link rel="stylesheet" type="text/css" href="#{values["stylesheet"]}"/>
  <meta name="generator" content="Re:VIEW EPUB Maker"/>
EOT
  end
    f.puts <<EOT
  <title>#{values["booktitle"]}</title>
</head>
<body>
EOT
    if File.exist?(backcoverfile)
      File.open(backcoverfile) {|f2|
        f2.each_line {|l|
          f.puts l
        }
      }
    else
      f.puts <<EOT
<div id="back-cover-image" class="full">
  <img src="images/#{backcoverfile}" alt="back-cover"/>
</div>
EOT
    end

    f.puts <<EOT
</body>
</html>
EOT
  }
end
make_colophon_page(tmp,bookname,values) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 837
def make_colophon_page(tmp,bookname,values)

  header = <<EOT
<?xml version="1.0" encoding="UTF-8"?>
EOT
    header += make_doctype()
    header += <<EOT
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="ja">
<head>
EOT
  if @htmlversion == 4
    header += <<EOT
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
  <meta http-equiv="Content-Style-Type" content="text/css"/>
  <link rel="stylesheet" type="text/css" href="#{values["stylesheet"]}"/>
  <meta name="generator" content="Re:VIEW EPUB Maker"/>
EOT
  else
    header += <<EOT
  <meta charset="UTF-8" />
  <link rel="stylesheet" type="text/css" href="#{values["stylesheet"]}"/>
  <meta name="generator" content="Re:VIEW EPUB Maker"/>
EOT
  end
    header += <<EOT
  <title>#{values["booktitle"]}</title>
</head>
<body>
EOT

  footer = <<EOT
</body>
</html>
EOT

  colophon_path = "#{@bookdir}/OEBPS/colophon.html"
  colophon = values["colophon"]
  if colophon.kind_of?(String) && File.exist?(colophon)
    File.open(colophon_path, "w") {|f|
      f.puts header
      File.open(values["colophon"]) {|f2|
        f2.each_line {|l|
          f.puts l
        }
      }
      f.puts footer
    }
  else
    File.open(colophon_path, "w") {|f|
      f.puts header
      f.puts <<EOT
<div class="colophon">
  <p class="title">#{values["booktitle"]}</p>
EOT
      if values["pubhistory"]
        f.puts %Q[<div class="pubhistory">\n<p>#{values["pubhistory"].gsub(/\n/,"<br />")}</p>\n</div>]
      end

      f.puts <<EOT
  <table>
EOT
      f.puts %Q[<tr>\n <th>著 者</th><td>#{join_names(values["aut"]) + ReVIEW::I18n.t("author_postfix")}</td>\n</tr>] if values["aut"]
      f.puts %Q[<tr>\n <th>監 修</th><td>#{join_names(values["csl"]) + ReVIEW::I18n.t("supervisor_postfix")}</td>\n</tr>] if values["csl"]
      f.puts %Q[<tr>\n <th>翻 訳</th><td>#{join_names(values["trl"]) + ReVIEW::I18n.t("translator_postfix")}</td>\n</tr>] if values["trl"]
      f.puts %Q[<tr>\n <th>デザイン</th><td>#{join_names(values["dsr"])}</td>\n</tr>] if values["dsr"]
      f.puts %Q[<tr>\n <th>イラスト</th><td>#{join_names(values["ill"])}</td>\n</tr>] if values["ill"]
      f.puts %Q[<tr>\n <th>表 紙</th><td>#{join_names(values["cov"])}</td>\n</tr>] if values["cov"]
      f.puts %Q[<tr>\n <th>編 集</th><td>#{join_names(values["edt"])}</td>\n</tr>] if values["edt"]
      f.puts %Q[<tr>\n <th>発行所</th><td>#{values["prt"]}</td>\n</tr>] if values["prt"]
      f.puts <<EOT
   </table>
EOT
      if values["rights"]
        f.puts %Q[<p class="copyright">#{values["rights"]}</p>]
      end

      f.puts "</div>"
      f.puts footer
    }
  end
end
make_doctype() click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 514
def make_doctype
  if @htmlversion == 5
    %q(<!DOCTYPE html>)
  else
    %q(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">)
  end
end
make_opf_file(values, bookname) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 523
def make_opf_file(values, bookname)
  File.open("#{@bookdir}/OEBPS/#{bookname}.opf", "w") {|f|
    f.puts <<EOT
<?xml version="1.0" encoding="UTF-8"?>
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
 <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
   <dc:title>#{values["booktitle"]}</dc:title>
EOT

   f.puts %Q(<dc:creator opf:role="aut">#{values["aut"]}</dc:creator>) unless values["aut"].nil? # FIXME: support multiple members

   f.puts %Q(<dc:publisher>#{values["prt"]}</dc:publisher>) unless values["prt"].nil?

   f.puts %Q(<dc:date>#{values["date"]}</dc:date>) unless values["date"].nil?
   f.puts %Q(<dc:rights>#{values["rights"]}</dc:rights>) unless values["rights"].nil?

   f.puts %Q(<dc:contributor opf:role="asn">#{values["asn"]}</dc:contributor>) unless values["asn"].nil?
   f.puts %Q(<dc:contributor opf:role="ant">#{values["ant"]}</dc:contributor>) unless values["ant"].nil?
   f.puts %Q(<dc:contributor opf:role="clb">#{values["clb"]}</dc:contributor>) unless values["clb"].nil?
   f.puts %Q(<dc:contributor opf:role="edt">#{values["edt"]}</dc:contributor>) unless values["edt"].nil?
   f.puts %Q(<dc:contributor opf:role="dsr">#{values["dsr"]}</dc:contributor>) unless values["dsr"].nil?
   f.puts %Q(<dc:contributor opf:role="ill">#{values["ill"]}</dc:contributor>) unless values["ill"].nil?
   f.puts %Q(<dc:contributor opf:role="pht">#{values["pht"]}</dc:contributor>) unless values["pht"].nil?
   f.puts %Q(<dc:contributor opf:role="trl">#{values["trl"]}</dc:contributor>) unless values["trl"].nil?

   f.puts %Q(<dc:description>#{values["description"]}</dc:description>) unless values["description"].nil?

    if values["coverimage"]
      f.puts %Q(<meta name="cover" content="#{getFigId("images-"+values["coverimage"])}"/>)
    end
    f.puts <<EOT
   <dc:language>ja</dc:language>
   <dc:identifier id="BookId">#{@identifier}</dc:identifier>
 </metadata>
 <manifest>
EOT

    if values["toc"]
      f.puts <<EOT
  <item id="ncx" href="#{bookname}.ncx" media-type="application/x-dtbncx+xml" />
EOT
    end

    f.puts <<EOT
  <item id="style" href="#{values["stylesheet"]}" media-type="text/css" />
  <item id="#{bookname}" href="#{bookname}.html" media-type="application/xhtml+xml" />
  <item id="top" href="top.html" media-type="application/xhtml+xml" />
EOT

    if values["toc"] && values["mytoc"]
      f.puts <<EOT
  <item id="toc" href="toc.html" media-type="application/xhtml+xml" />
EOT
    end

    f.puts @manifeststr
    if values["colophon"]
      f.puts <<EOT
  <item id="colophon" href="colophon.html" media-type="application/xhtml+xml" />
EOT
    end
    if values["backcoverfile"]
      f.puts <<EOT
  <item id="backcover" href="#{values["backcoverfile"]}" media-type="application/xhtml+xml" />
EOT
    end

    if values["cover_linear"] && values["cover_linear"] != "no"
      cover_linear = "yes"
    else
      cover_linear = "no"
    end

    f.puts <<EOT
 </manifest>
 <spine toc="ncx">
  <itemref idref="#{bookname}" linear="#{cover_linear}" />
  <itemref idref="top" />
EOT

    if values["toc"] && values["mytoc"]
      f.puts <<EOT
  <itemref idref="toc" />
EOT
    end

    f.puts @ncxstr
    if values["colophon"]
      f.puts <<EOT
  <itemref idref="colophon" />
EOT
    end
    if values["backcoverfile"]
      f.puts <<EOT
  <itemref idref="backcover" />
EOT
    end
    f.puts <<EOT
 </spine>
 <guide>
EOT

    if values["titlepage"]
      f.puts <<EOT
  <reference type="cover" title="表紙" href="#{bookname}.html"/>
  <reference type="title-page" title="Title Page" href="top.html"/>
EOT
    end

    if values["toc"] && values["mytoc"]
      f.puts <<EOT
  <reference type="toc" title="目次" href="toc.html"/>
EOT
    end
    f.puts <<EOT
 </guide>
</package>
EOT
  }
end
make_opf_filev3(values, bookname) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 644
def make_opf_filev3(values, bookname)
  File.open("#{@bookdir}/OEBPS/#{bookname}.opf", "w") {|f|
    f.puts <<EOT
<?xml version="1.0" encoding="UTF-8"?>
<package version="3.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
 <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
   <dc:title>#{values["booktitle"]}</dc:title>
EOT
    unless values["aut"].nil? # FIXME: support multiple members
      f.puts %Q(<dc:creator id="author">#{values["aut"]}</dc:creator>)
      f.puts %Q(<meta refines="#author" property="role" scheme="marc:relators" id="role">aut</meta>)
    end
    f.puts %Q(<dc:publisher id="publisher">#{values["prt"]}</dc:publisher>) unless values["prt"].nil?

    f.puts %Q(<dc:date>#{values["date"]}</dc:date>) unless values["date"].nil?
    f.puts %Q(<dc:rights>#{values["rights"]}</dc:rights>) unless values["rights"].nil?

    %w(asn ant clb edt dsr ill pht trl).each do |attr|
      unless values[attr].nil?
        f.puts %Q(<dc:contributor id="#{attr}">#{values[attr]}</dc:contributor>)
        f.puts %Q(<meta refines='##{attr}' property='role' scheme='marc:relators'>#{attr}</meta>)
      end
    end
   f.puts %Q(<dc:description>#{values["description"]}</dc:description>) unless values["description"].nil?
    f.puts %Q(<meta property="dcterms:modified">#{Time.now.utc.iso8601(0)}</meta>)
    if values["coverimage"]
      f.puts %Q(<meta name="cover" content="#{getFigId("images-"+values["coverimage"])}"/>)
    end
    f.puts <<EOT
   <dc:language>ja</dc:language>
   <dc:identifier id="BookId">#{@identifier}</dc:identifier>
 </metadata>
 <manifest>
EOT

    if values["toc"]
      f.puts <<EOT
  <item id="ncx" href="#{bookname}.ncx" media-type="application/x-dtbncx+xml" />
EOT
    end

    f.puts <<EOT
  <item id="style" href="#{values["stylesheet"]}" media-type="text/css" />
  <item id="#{bookname}" href="#{bookname}.html" media-type="application/xhtml+xml" />
  <item id="top" href="top.html" media-type="application/xhtml+xml" />
EOT

    if values["toc"] && values["mytoc"]
      f.puts <<EOT
  <item id="toc" href="toc.html" properties="nav" media-type="application/xhtml+xml" />
EOT
    end

    f.puts @manifeststr
    if values["colophon"]
      f.puts <<EOT
  <item id="colophon" href="colophon.html" media-type="application/xhtml+xml" />
EOT
    end

    if values["backcoverfile"]
      f.puts <<EOT
  <item id="backcover" href="#{values["backcoverfile"]}" media-type="application/xhtml+xml" />
EOT
    end

    if values["cover_linear"] && values["cover_linear"] != "no"
      cover_linear = "yes"
    else
      cover_linear = "no"
    end

    f.puts <<EOT
 </manifest>
 <spine toc="ncx">
  <itemref idref="#{bookname}" linear="#{cover_linear}" />
  <itemref idref="top" />
EOT

    if values["toc"] && values["mytoc"]
      f.puts <<EOT
  <itemref idref="toc" />
EOT
    end

    f.puts @ncxstr
    if values["colophon"]
      f.puts <<EOT
  <itemref idref="colophon" />
EOT
    end
    if values["backcoverfile"]
      f.puts <<EOT
  <itemref idref="backcover" />
EOT
    end
    f.puts <<EOT
 </spine>
 <guide>
EOT

    if values["titlepage"]
      f.puts <<EOT
  <reference type="cover" title="表紙" href="#{bookname}.html"/>
  <reference type="title-page" title="Title Page" href="top.html"/>
EOT
    end

    if values["toc"] && values["mytoc"]
      f.puts <<EOT
  <reference type="toc" title="目次" href="toc.html"/>
EOT
    end
    f.puts <<EOT
 </guide>
</package>
EOT
  }
end
make_part_page(part, filename, values) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 919
def make_part_page(part, filename, values)
  File.open("#{@bookdir}/OEBPS/#{filename}", "w") {|f|
    f.puts <<-EOT
<?xml version="1.0" encoding="UTF-8"?>
    EOT
    doctype = make_doctype()
    f.puts doctype
  if @htmlversion == 4
    header = <<-EOT
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="ja">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
  <meta http-equiv="Content-Style-Type" content="text/css"/>
  <link rel="stylesheet" type="text/css" href="#{values["stylesheet"]}"/>
  <meta name="generator" content="Re:VIEW EPUB Maker"/>
  <title>#{values["booktitle"]}</title>
</head>
    EOT
  else
    header = <<-EOT
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="ja">
<head>
  <meta charset="UTF-8" />
  <link rel="stylesheet" type="text/css" href="#{values["stylesheet"]}"/>
  <meta name="generator" content="Re:VIEW EPUB Maker"/>
  <title>#{values["booktitle"]}</title>
</head>
    EOT
  end
    f.puts header

    f.puts <<-EOT
<body>
<h1 class="part-number">#{ReVIEW::I18n.t("part", part.number)}</h1>
    EOT

    if part.name.strip.present?
      f.puts <<-EOT
<h2 class="part-title">#{part.name.strip}</h2>
      EOT
    end

    f.puts <<-EOT
</body>
</html>
    EOT
  }
end
output_chaps(chapsfile, values) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 765
def output_chaps(chapsfile, values)
  File.open(chapsfile) {|chaps|
    chaps.each_line {|l|
      next if l =~ /^#/
      output_chaps_by_file(l, values)
    }
  }
end
output_chaps_by_file(l, values) click to toggle source
# File ../../../../../bin/review-epubmaker-legacy, line 774
def output_chaps_by_file(l, values)
  file_id = File.basename(l.chomp.strip,".*")
  if (idx = @essential_files.index(file_id))
    if idx == @essential_files.size - 1
      STDERR.puts "#{file_id} is book name. Please rename #{l.chomp.strip}."
    else
      STDERR.puts "#{file_id} is special name. Please rename #{l.chomp.strip}."
    end
    exit 1
  end
  filename = "#{file_id}.html"
  system("#{ReVIEW::MakerHelper.bindir}/review-compile --target=html --level=#{values["secnolevel"]} --htmlversion=#{values["htmlversion"]} --epubversion=#{values["epubversion"]} #{values["params"]} #{l} > #{@bookdir}/OEBPS/#{filename}")
  getanchors("#{@bookdir}/OEBPS/#{filename}")
  if @epubversion == 3 && include_mathml?("#{@bookdir}/OEBPS/#{filename}")
    @manifeststr << %Q(<item id="rv-#{file_id}" href="#{filename}" properties="mathml" media-type="application/xhtml+xml" />\n)
  else
    @manifeststr << %Q(<item id="rv-#{file_id}" href="#{filename}" media-type="application/xhtml+xml" />\n)
  end
  @ncxstr << %Q(<itemref idref="rv-#{file_id}" />\n)
end
parse_chaps(str) click to toggle source
# File ../../../../../bin/review-catalog-converter, line 100
def parse_chaps(str)
  header = "CHAPS:\n"
  _parse(str, header) + "\n"
end
parse_parts(parts_str, chaps_str) click to toggle source
# File ../../../../../bin/review-catalog-converter, line 114
def parse_parts(parts_str, chaps_str)
  if parts_str.blank? or chaps_str.blank?
    return "CHAPS:\n\n"
  end

  parts = parts_str.split("\n")
  chaps = chaps_str.split("\n\n")
  "CHAPS:\n" + parts.zip(chaps).map{|k, vs|
    "  - #{k}:\n" + vs.split("\n").map{|i| "    - #{i}\n"}.join
  }.join + "\n"
end
parse_postdef(str, to_appendix = false) click to toggle source
# File ../../../../../bin/review-catalog-converter, line 105
def parse_postdef(str, to_appendix = false)
  if to_appendix
    header = "APPENDIX:\n"
  else
    header = "POSTDEF:\n"
  end
  _parse(str, header) + "\n"
end
parse_predef(str) click to toggle source
# File ../../../../../bin/review-catalog-converter, line 95
def parse_predef(str)
  header = "PREDEF:\n"
  _parse(str, header) + "\n"
end
parse_predefined() click to toggle source
# File ../../../../../bin/review-checkdep, line 49
def parse_predefined
  result = {}
  File.foreach(PREDEF_FILE) do |line|
    result[line.strip] = '(predefined)'
  end
  result
rescue Errno::ENOENT
  return {}
end
prepare_samplebook(srcdir) click to toggle source
# File ../../../../../test/test_helper.rb, line 13
def prepare_samplebook(srcdir)
  samplebook_dir = File.expand_path("sample-book/src/", File.dirname(__FILE__))
  FileUtils.cp_r(Dir.glob(samplebook_dir + "/*"), srcdir)
  YAML.load(File.open(srcdir + "/config.yml"))
end
preproc(pp, path) click to toggle source
# File ../../../../../bin/review-preproc, line 117
def preproc(pp, path)
  buf = StringIO.new
  File.open(path) {|f|
    pp.process f, buf
  }
  buf.string
end
present?() click to toggle source
# File ../../../../../lib/review/extentions/object.rb, line 6
def present?
  !blank?
end
print_chapter_volume(chap) click to toggle source
print_volume(vol) click to toggle source
provide(kw) click to toggle source
# File ../../../../../bin/review-checkdep, line 41
def provide(kw)
  @provided[kw] ||= location()
  if @unprovided[kw]
    reqpos = @unprovided.delete(kw)
    puts "#{location()}: provided now: #{kw} (#{reqpos})"
  end
end
sigmain() click to toggle source
# File ../../../../../bin/review-check, line 23
def sigmain
  Signal.trap(:INT) { exit 1 }
  if RUBY_PLATFORM !~ /mswin(?!ce)|mingw|cygwin|bccwin/
    Signal.trap(:PIPE, 'IGNORE')
  end
  main
rescue Errno::EPIPE
  exit 0
end
touch_file(path) click to toggle source
# File ../../../../../test/test_helper.rb, line 4
def touch_file(path)
  File.open(path, "w").close
  path
end
words_re(rc) click to toggle source
# File ../../../../../bin/review-check, line 115
def words_re(rc)
  words = []
  nega = []
  File.foreach(rc) do |line|
    next if line[0,1] == '#'
    if / !/ =~ line
      line, n = *line.split(/!/, 2)
      nega.push n.strip
    end
    words.push line.strip
  end
  return Regexp.compile(words.join('|')),
         nega.empty?() ? nil : Regexp.compile(nega.join('|'))
end
write(path, str) click to toggle source
# File ../../../../../bin/review-compile, line 196
def write(path, str)
  File.open(path, 'w') {|f|
    f.puts str
  }
end