Module: Metanorma::Standoc::Attachment
Instance Method Summary collapse
- #attachment_cleanup(xmldoc) ⇒ Object
- #attachment_location(path) ⇒ Object
- #attachment_uri(path, bib) ⇒ Object
- #datauri_attachment(path, doc) ⇒ Object
- #init_attachments ⇒ Object
- #save_attachment(path, bib) ⇒ Object
- #valid_attachment?(path, bib) ⇒ Boolean
Instance Method Details
#attachment_cleanup(xmldoc) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/metanorma/cleanup/attachment.rb', line 4 def (xmldoc) xmldoc.xpath("//bibitem[uri/@type = 'attachment']").each do |b| b["hidden"] = "true" b.at("./docidentifier[@type = 'title']")&.remove u = b.at("./uri[@type = 'attachment']") c = b.at("./uri[@type = 'citation']") || u.after("<uri type='citation'/>") uri = (u.text, b) u.children = uri c.children = uri end end |
#attachment_location(path) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/metanorma/cleanup/attachment.rb', line 35 def (path) f = path @datauriattachment and f = File.join(@attachmentsdir, File.basename(path)) Pathname.new(File.(f)) .relative_path_from(Pathname.new(File.(@output_dir))).to_s end |
#attachment_uri(path, bib) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/metanorma/cleanup/attachment.rb', line 17 def (path, bib) path = File.join(@localdir, path) (path, bib) or return "" @datauriattachment or return (path) (path, bib) end |
#datauri_attachment(path, doc) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/metanorma/cleanup/attachment.rb', line 43 def (path, doc) @datauriattachment or return m = add_misc_container(doc) f = (path) e = (m << "<attachment name='#{f}'/>").last_element_child Vectory::Utils::datauri(path, @output_dir).scan(/.{1,60}/) .each { |dd| e << "#{dd}\n" } f end |
#init_attachments ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/metanorma/cleanup/attachment.rb', line 60 def @datauriattachment or return @attachmentsdir and return @attachmentsfld = "_#{@filename}_attachments" @attachmentsdir = File.join(@output_dir, @attachmentsfld) FileUtils.rm_rf(@attachmentsdir) FileUtils.mkdir_p(@attachmentsdir) end |
#save_attachment(path, bib) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/metanorma/cleanup/attachment.rb', line 25 def (path, bib) f = File.basename(path) File.exist?(File.join(@attachmentsdir, f)) and f += "_#{UUIDTools::UUID.random_create}" out_fld = File.join(@attachmentsdir, f) FileUtils.cp(path, out_fld) (out_fld, bib.document) end |
#valid_attachment?(path, bib) ⇒ Boolean
53 54 55 56 57 58 |
# File 'lib/metanorma/cleanup/attachment.rb', line 53 def (path, bib) File.exist?(path) and return true p = Pathname.new(path).cleanpath @log.add("STANDOC_9", bib, params: [p]) false end |