Class: ReVIEW::EPUBMaker::EPUBv2
- Inherits:
-
EPUBCommon
- Object
- EPUBCommon
- ReVIEW::EPUBMaker::EPUBv2
- Includes:
- CallHook
- Defined in:
- lib/review/epubmaker/epubv2.rb
Overview
EPUBv2 is EPUB version 2 producer.
Constant Summary collapse
- DC_ITEMS =
%w[title language date type format source description relation coverage subject rights]
- CREATOR_ATTRIBUTES =
%w[aut a-adp a-ann a-arr a-art a-asn a-aqt a-aft a-aui a-ant a-bkp a-clb a-cmm a-dsr a-edt a-ill a-lyr a-mdc a-mus a-nrt a-oth a-pht a-prt a-red a-rev a-spn a-ths a-trc a-trl]
- CONTRIBUTER_ATTRIBUTES =
%w[adp ann arr art asn aqt aft aui ant bkp clb cmm dsr edt ill lyr mdc mus nrt oth pht prt red rev spn ths trc trl]
Instance Attribute Summary
Attributes inherited from EPUBCommon
Instance Method Summary collapse
-
#initialize(producer) ⇒ EPUBv2
constructor
Construct object with parameter hash
config
and message resource hashres
. -
#ncx(indentarray) ⇒ Object
Return ncx content.
- #ncx_doctitle ⇒ Object
- #ncx_isbn ⇒ Object
- #ncx_navmap(indentarray) ⇒ Object
-
#opf ⇒ Object
Return opf file content.
- #opf_manifest ⇒ Object
- #opf_metainfo ⇒ Object
- #opf_tocx ⇒ Object
-
#produce(epubfile, work_dir, tmpdir, base_dir:) ⇒ Object
Produce EPUB file
epubfile
.
Methods included from CallHook
Methods inherited from EPUBCommon
#call_hook, #colophon, #colophon_history, #container, #cover, #coverimage, #date_to_s, #flat_ncx, #h, #hierarchy_ncx, #isbn_hyphen, #join_with_separator, #legacy_cover_and_title_file, #mimetype, #mytoc, #opf_coverimage, #opf_path, #produce_write_common, #template_name, #titlepage
Constructor Details
#initialize(producer) ⇒ EPUBv2
Construct object with parameter hash config
and message resource hash res
.
26 27 28 |
# File 'lib/review/epubmaker/epubv2.rb', line 26 def initialize(producer) # rubocop:disable Lint/UselessMethodDefinition super end |
Instance Method Details
#ncx(indentarray) ⇒ Object
Return ncx content. indentarray
has prefix marks for each level.
86 87 88 89 90 91 92 |
# File 'lib/review/epubmaker/epubv2.rb', line 86 def ncx(indentarray) @ncx_isbn = ncx_isbn @ncx_doctitle = ncx_doctitle @ncx_navmap = ncx_navmap(indentarray) ReVIEW::Template.generate(path: './ncx/epubv2.ncx.erb', binding: binding) end |
#ncx_doctitle ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/review/epubmaker/epubv2.rb', line 99 def ncx_doctitle <<-EOT <docTitle> <text>#{h(config['title'])}</text> </docTitle> <docAuthor> <text>#{config['aut'].nil? ? '' : h(join_with_separator(config['aut'], ReVIEW::I18n.t('names_splitter')))}</text> </docAuthor> EOT end |
#ncx_isbn ⇒ Object
94 95 96 97 |
# File 'lib/review/epubmaker/epubv2.rb', line 94 def ncx_isbn uid = config['isbn'] || config['urnid'] %Q( <meta name="dtb:uid" content="#{uid}"/>\n) end |
#ncx_navmap(indentarray) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/review/epubmaker/epubv2.rb', line 110 def ncx_navmap(indentarray) s = <<EOT <navMap> <navPoint id="top" playOrder="1"> <navLabel> <text>#{h(config['title'])}</text> </navLabel> <content src="#{config['cover']}"/> </navPoint> EOT nav_count = 2 unless config['mytoc'].nil? s << <<EOT <navPoint id="toc" playOrder="#{nav_count}"> <navLabel> <text>#{h(ReVIEW::I18n.t('toctitle'))}</text> </navLabel> <content src="#{config['bookname']}-toc.#{config['htmlext']}"/> </navPoint> EOT nav_count += 1 end contents.each do |item| next if item.title.nil? indent = indentarray.nil? ? [''] : indentarray level = item.level.nil? ? 0 : (item.level - 1) level = indent.size - 1 if level >= indent.size s << <<EOT <navPoint id="nav-#{nav_count}" playOrder="#{nav_count}"> <navLabel> <text>#{indent[level]}#{h(item.title)}</text> </navLabel> <content src="#{item.file}"/> </navPoint> EOT nav_count += 1 end s << <<EOT </navMap> EOT s end |
#opf ⇒ Object
Return opf file content.
31 32 33 34 35 36 37 38 |
# File 'lib/review/epubmaker/epubv2.rb', line 31 def opf @opf_metainfo = @opf_coverimage = opf_coverimage @opf_manifest = opf_manifest @opf_toc = opf_tocx ReVIEW::Template.generate(path: './opf/epubv2.opf.erb', binding: binding) end |
#opf_manifest ⇒ Object
68 69 70 71 72 |
# File 'lib/review/epubmaker/epubv2.rb', line 68 def opf_manifest @items = contents.find_all { |item| item.file !~ /#/ } # skip subgroup ReVIEW::Template.generate(path: './opf/opf_manifest_epubv2.opf.erb', binding: binding) end |
#opf_metainfo ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/review/epubmaker/epubv2.rb', line 40 def @dc_items = DC_ITEMS.map do |item| if config[item] if config[item].is_a?(Array) config.names_of(item).map { |_v| { tag: "dc:#{item}", val: item_sub } } else { tag: "dc:#{item}", val: config.name_of(item).to_s } end end end.flatten.compact # creator (should be array) @creators = CREATOR_ATTRIBUTES.map do |role| if config[role] config.names_of(role).map { |v| { role: role, val: v } } end end.flatten.compact # contributor (should be array) @contributers = CONTRIBUTER_ATTRIBUTES.map do |role| if config[role] config.names_of(role).map { |v| { role: role, val: v } } end end.flatten.compact ReVIEW::Template.generate(path: './opf/opf_metainfo_epubv2.opf.erb', binding: binding) end |
#opf_tocx ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/review/epubmaker/epubv2.rb', line 74 def opf_tocx @cover_linear = if config['epubmaker']['cover_linear'] && config['epubmaker']['cover_linear'] != 'no' 'yes' else 'no' end @ncx_contents = contents.find_all { |content| content.media =~ /xhtml\+xml/ } # skip non XHTML ReVIEW::Template.generate(path: './opf/opf_tocx_epubv2.opf.erb', binding: binding) end |
#produce(epubfile, work_dir, tmpdir, base_dir:) ⇒ Object
Produce EPUB file epubfile
. basedir
points the directory has contents. tmpdir
defines temporary directory.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/review/epubmaker/epubv2.rb', line 161 def produce(epubfile, work_dir, tmpdir, base_dir:) @workdir = base_dir produce_write_common(work_dir, tmpdir) ncx_file = "#{tmpdir}/OEBPS/#{config['bookname']}.ncx" File.write(ncx_file, ncx(config['epubmaker']['ncxindent'])) if config['mytoc'] toc_file = "#{tmpdir}/OEBPS/#{config['bookname']}-toc.#{config['htmlext']}" File.write(toc_file, mytoc) end call_hook('hook_prepack', tmpdir, base_dir: base_dir) expoter = ReVIEW::EPUBMaker::ZipExporter.new(tmpdir, config) expoter.export_zip(epubfile) end |