diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 349913facf..4f74c86d72 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -6,6 +6,8 @@ class ExportController < ApplicationController # no layout if xhr request layout Proc.new { |controller| controller.request.xhr? ? false : nil } #, :only => [:update, :update_profile] + README = [] + def index @collection = Collection.friendly.find(params[:collection_id]) #check if there are any translated works in the collection @@ -25,6 +27,21 @@ def show render :layout => false end + def text + @work = Work.includes(pages: [:notes, {page_versions: :user}]).find_by(id: params[:work_id]) + render :layout => false + end + + def transcript + @work = Work.includes(pages: [:notes, {page_versions: :user}]).find_by(id: params[:work_id]) + render :layout => false + end + + def translation + @work = Work.includes(pages: [:notes, {page_versions: :user}]).find_by(id: params[:work_id]) + render :layout => false + end + def tei params[:format] = 'xml'# if params[:format].blank? @@ -77,27 +94,180 @@ def table_csv end + def desc_to_file(text:, dirname:, out:) + README << text + + path = File.join dirname, 'README.txt' + out.put_next_entry path + + README.each do |desc| + out.write desc + end + end + + def export_plaintext_transcript(name:, dirname:, out:) + path = File.join dirname, 'plaintext', "#{name}_transcript.txt" + + out.put_next_entry path + + case name + when "verbatim" + out.write @work.verbatim_transcription_plaintext + desc_to_file(text: "plaintext/verbatim_transcript.txt - file containing the per-document verbatim plaintext export of the transcript.\n", dirname: dirname, out: out) + when "emended" + out.write @work.emended_transcription_plaintext + desc_to_file(text: "plaintext/emended_transcript.txt - file containing the per-document emended plaintext export of the transcript.\n", dirname: dirname, out: out) + when "searchable" + out.write @work.searchable_plaintext + desc_to_file(text: "plaintext/searchable_transcript.txt - file containing the per-document searchable plaintext export of the transcript.\n", dirname: dirname, out: out) + end + end + + def export_plaintext_translation(name:, dirname:, out:) + path = File.join dirname, 'plaintext', "#{name}_translation.txt" + + out.put_next_entry path + + out.write @work.public_send "#{name}_translation_plaintext" + desc_to_file(text: "plaintext/#{name}_translation.txt - file containing the per-document #{name} plaintext export of the translation if it is present.\n", dirname: dirname, out: out) + end + + def export_plaintext_transcript_pages(name:, dirname:, out:, page:) + path = File.join dirname, 'plaintext', "#{name}_transcript_pages", "#{page.title}.txt" + + out.put_next_entry path + + out.write page.public_send "#{name}_transcription_plaintext" + desc_to_file(text: "plaintext/#{name}_transcript_pages/#{page.title}.txt - files containing per-page #{name} plaintext export.\n", dirname: dirname, out: out) + end + + def export_plaintext_translation_pages(name:, dirname:, out:, page:) + path = File.join dirname, 'plaintext', "#{name}_translation_pages", "#{page.title}.txt" + + out.put_next_entry path + + out.write page.public_send "#{name}_translation_plaintext" + desc_to_file(text: "plaintext/#{name}_translation_pages/#{page.title}.txt - files containing per-page #{name} plaintext export.\n", dirname: dirname, out: out) + end + + def export_view(name:, dirname:, out:) + path = File.join dirname, 'html', "#{name}.html" + out.put_next_entry path + + case name + when "full" + full_view = render_to_string(:action => 'show', :formats => [:html], :work_id => @work.id, :layout => false, :encoding => 'utf-8') + out.write full_view + when "text" + text_view = render_to_string(:action => 'text', :formats => [:html], :work_id => @work.id, :layout => false, :encoding => 'utf-8') + out.write text_view + when "transcript" + transcript_view = render_to_string(:action => 'transcript', :formats => [:html], :work_id => @work.id, :layout => false, :encoding => 'utf-8') + out.write transcript_view + when "translation" + translation_view = render_to_string(:action => 'translation', :formats => [:html], :work_id => @work.id, :layout => false, :encoding => 'utf-8') + out.write translation_view + end + end + + def export_html_full_pages(dirname:, out:, page:) + path = File.join dirname, 'html', 'full_pages', "#{page.title}.html" + + out.put_next_entry path + + page_view = render_to_string('display/display_page.html.slim', :locals => {:@work => @work, :@page => page}, :layout => false) + out.write page_view + end + + def export_work + dirname = @work.slug.truncate(200, omission: "") + + respond_to do |format| + format.zip do + buffer = Zip::OutputStream.write_buffer do |out| + %w(verbatim emended searchable).each do |format| + export_plaintext_transcript(name: format, dirname: dirname, out: out) + end + + %w(verbatim emended).each do |format| + export_plaintext_translation(name: format, dirname: dirname, out: out) + end + + @work.pages.each do |page| + %w(verbatim emended).each do |format| + export_plaintext_transcript_pages(name: format, dirname: dirname, out: out, page: page) + end + + %w(verbatim emended).each do |format| + export_plaintext_translation_pages(name: format, dirname: dirname, out: out, page: page) + end + end + + %w(full text transcript translation).each do |format| + export_view(name: format, dirname: dirname, out: out) + end + + @work.pages.each do |page| + export_html_full_pages(dirname: dirname, out: out, page: page) + end + end + + buffer.rewind + send_data buffer.read, filename: "#{@collection.title}-#{@work.title}.zip" + end + end + end + def export_all_works unless @collection.subjects_disabled @works = Work.includes(pages: [:notes, {page_versions: :user}]).where(collection_id: @collection.id) else @works = Work.includes(pages: [:notes, {page_versions: :user}]).where(collection_id: @collection.id) - end + end -#create a zip file which is automatically downloaded to the user's machine + # create a zip file which is automatically downloaded to the user's machine respond_to do |format| format.html format.zip do - compressed_filestream = Zip::OutputStream.write_buffer do |zos| - @works.each do |work| - @work = work - export_view = render_to_string(:action => 'show', :formats => [:html], :work_id => work.id, :layout => false, :encoding => 'utf-8') - zos.put_next_entry "#{work.slug.truncate(200, omission: "")}.xhtml" - zos.print export_view + buffer = Zip::OutputStream.write_buffer do |out| + @works.each do |work| + @work = work + dirname = work.slug.truncate(200, omission: "") + + export_view = render_to_string(:action => 'show', :formats => [:html], :work_id => work.id, :layout => false, :encoding => 'utf-8') + out.put_next_entry "#{dirname}/#{work.slug.truncate(200, omission: "")}.xhtml" + out.print export_view + + %w(verbatim emended searchable).each do |format| + export_plaintext_transcript(name: format, dirname: dirname, out: out) + end + + %w(verbatim emended).each do |format| + export_plaintext_translation(name: format, dirname: dirname, out: out) + end + + @work.pages.each do |page| + %w(verbatim emended).each do |format| + export_plaintext_transcript_pages(name: format, dirname: dirname, out: out, page: page) + end + + %w(verbatim emended).each do |format| + export_plaintext_translation_pages(name: format, dirname: dirname, out: out, page: page) + end + end + + %w(full text transcript translation).each do |format| + export_view(name: format, dirname: dirname, out: out) + end + + @work.pages.each do |page| + export_html_full_pages(dirname: dirname, out: out, page: page) + end + end end - end - compressed_filestream.rewind - send_data compressed_filestream.read, filename: "#{@collection.title}.zip" + + buffer.rewind + send_data buffer.read, filename: "#{@collection.title}.zip" end end cookies['download_finished'] = 'true' diff --git a/app/views/export/index.html.slim b/app/views/export/index.html.slim index d970fee727..add317c849 100644 --- a/app/views/export/index.html.slim +++ b/app/views/export/index.html.slim @@ -30,7 +30,7 @@ table.datagrid th #{@header} th Review th.w100 Progress - th(colspan="4") Export As + th(colspan="6") Export As -for work in @works -work_stats(work) @@ -69,11 +69,15 @@ table.datagrid =link_to iiif_manifest_path(work.id) =svg_symbol '#icon-export', class: 'icon' span IIIF - td.nowrap - -unless work.table_cells.blank? + -unless work.table_cells.blank? + td.nowrap =link_to({ :controller => 'export', :action => 'table_csv', :work_id => work.id }, class: 'btnCsvTblExport btnExport') =svg_symbol '#icon-export', class: 'icon' span Table CSV + td.nowrap + =link_to(:controller => 'export', :action => 'export_work', :work_id => work.id, format: :zip) + =svg_symbol '#icon-export', class: 'icon' + span ZIP =render(:partial => 'shared/pagination', :locals => { :model => @works, :entries_info => true }) diff --git a/app/views/export/text.html.erb b/app/views/export/text.html.erb new file mode 100644 index 0000000000..e53943bca4 --- /dev/null +++ b/app/views/export/text.html.erb @@ -0,0 +1,120 @@ + + + + + <%= @work.title %> + + + +

<%= @work.title %>

+
FromThePage export of <%= @work.title %> from <%= @collection.title %> made on <%= Time.now %>. + <% unless @work.identifier.blank? %> +

Identifier: <%=@work.identifier%>

+ <% end %> +

+ FromThePage version: <%= fromthepage_version %> +

+
+ +
+

Page Transcripts

+ +
+ <% @work.pages.each do |page| %> +
+

<%= page.title %>

+
+ <%= raw(xml_to_html(page.xml_text, true, true)) %> +
+ <% if page.notes.present? %> +
+ Notes: + <% page.notes.each do |note| %> +
+

<%=note.user.display_name%>

+

<%= sanitize(note.body, tags: %w(strong b em i a), attributes: %w(href))%>

+ +
+ <% end %> +
+ <% end %> +
+
+ <% end %> +
+ + <% if @work.supports_translation %> +
+

Page Translations

+ +
+ <% @work.pages.each do |page| %> +
+

<%= page.title %>

+
+ <%= raw(xml_to_html(page.xml_translation, true, true)) %> +
+
+
+ <% if page.notes.present? %> +
+ Notes: + <% page.notes.each do |note| %> +
+

<%=note.user.display_name%>

+

<%= sanitize(note.body, tags: %w(strong b em i a), attributes: %w(href))%>

+ +
+ <% end %> +
+ <% end %> + <% end %> +
+ <% end %> + +
+ <% unless @work.collection.subjects_disabled %> +

Subjects and Indices

+ +
+ <% @work.articles.sort{ |x,y| x.title.upcase <=> y.title.upcase }.each do |article| %> +
+

<%=article.title %>

+
+ <%= raw(xml_to_html(article.xml_text, true, true)) %> +
+ <% if article.categories.present? %> +
+ Categories: +
    + <% article.categories.each do |cat| %> +
  • <%= raw((cat.ancestors.reverse.push(cat).map { |c| c.title }).join(" → ")) %>
  • + <% end %> +
+
+ <% end %> +
+ Pages: +
    + <% article.show_links(@collection).each do |link| %> +
  • + + <% if link.text_type == 'translation' %> + <%= link_to(link.page.title, "#page-#{link.page_id}") %> + <% else %> + <%= link_to(link.page.title, "#translation-#{link.page_id}") %> (translation) + <% end %> + +
  • + <% end %> +
+
+ + +
+
+ <% end %> +
+ <% end %> + + diff --git a/app/views/export/transcript.html.erb b/app/views/export/transcript.html.erb new file mode 100644 index 0000000000..e3cdbf202f --- /dev/null +++ b/app/views/export/transcript.html.erb @@ -0,0 +1,75 @@ + + + + + <%= @work.title %> + + + +

<%= @work.title %>

+
FromThePage export of <%= @work.title %> from <%= @collection.title %> made on <%= Time.now %>. + <% unless @work.identifier.blank? %> +

Identifier: <%=@work.identifier%>

+ <% end %> +

+ FromThePage version: <%= fromthepage_version %> +

+
+ +
+

Page Transcripts

+ +
+ <% @work.pages.each do |page| %> +
+

<%= page.title %>

+
+ <%= raw(xml_to_html(page.xml_text, true, true)) %> +
+ <% if page.notes.present? %> +
+ Notes: + <% page.notes.each do |note| %> +
+

<%=note.user.display_name%>

+

<%= sanitize(note.body, tags: %w(strong b em i a), attributes: %w(href))%>

+ +
+ <% end %> +
+ <% end %> +
+
+ <% end %> +
+ + <% if @work.supports_translation %> +
+

Page Translations

+ +
+ <% @work.pages.each do |page| %> +
+

<%= page.title %>

+
+ <%= raw(xml_to_html(page.xml_translation, true, true)) %> +
+
+
+ <% if page.notes.present? %> +
+ Notes: + <% page.notes.each do |note| %> +
+

<%=note.user.display_name%>

+

<%= sanitize(note.body, tags: %w(strong b em i a), attributes: %w(href))%>

+ +
+ <% end %> +
+ <% end %> + <% end %> +
+ <% end %> + + diff --git a/app/views/export/translation.html.erb b/app/views/export/translation.html.erb new file mode 100644 index 0000000000..4ac1066539 --- /dev/null +++ b/app/views/export/translation.html.erb @@ -0,0 +1,49 @@ + + + + + <%= @work.title %> + + + +

<%= @work.title %>

+
FromThePage export of <%= @work.title %> from <%= @collection.title %> made on <%= Time.now %>. + <% unless @work.identifier.blank? %> +

Identifier: <%=@work.identifier%>

+ <% end %> +

+ FromThePage version: <%= fromthepage_version %> +

+
+ +
+ <% if @work.supports_translation %> +
+

Page Translations

+ +
+ <% @work.pages.each do |page| %> +
+

<%= page.title %>

+
+ <%= raw(xml_to_html(page.xml_translation, true, true)) %> +
+
+
+ <% if page.notes.present? %> +
+ Notes: + <% page.notes.each do |note| %> +
+

<%=note.user.display_name%>

+

<%= sanitize(note.body, tags: %w(strong b em i a), attributes: %w(href))%>

+ +
+ <% end %> +
+ <% end %> + <% end %> +
+ <% end %> + +