Commit 28acba71 authored by Alex Theg's avatar Alex Theg
Browse files

Merge branch '3-next-steps-for-track-changes-with-amnet' into 'master'

Resolve "Next steps for track changes with Amnet"

Closes #3

See merge request !4
parents 096ab2d2 7c715b66
require 'fileutils'
require 'os'
# dir = '/Users/atheg/Desktop/crawler/to_convert'
convertDir = Dir.getwd + "/to_convert"
......@@ -14,23 +15,21 @@ book_list.each do |book|
if docx != no_space
FileUtils.mv(docx, no_space)
end
zip_name_no_ext = no_space.slice(0...-5)
zip_name_ext = zip_name_no_ext + ".zip"
FileUtils.cp(no_space, zip_name_ext)
sleep(1)
# %x`open #{zip_name_ext}`
%x`unzip #{zip_name_ext} -d #{zip_name_no_ext}`
if OS.windows?
#support for in powershell
%x`powershell.exe Expand-Archive #{zip_name_ext} -DestinationPath #{zip_name_no_ext}`
else
%x`unzip #{zip_name_ext} -d #{zip_name_no_ext}`
end
end
sleep(8)
zip_list = Dir["#{book}/*.zip"]
zip_list.each do |zip|
FileUtils.rm zip
end
end
......@@ -6,33 +6,43 @@ new_file_xsweet = File.join(Dir.pwd, "xsweet.zip")
new_file_typescript = File.join(Dir.pwd, "typescript.zip")
new_file_htmlevator = File.join(Dir.pwd, "htmlevator.zip")
downloaded_file = File.new(new_file_xsweet, "w")
#changed the file mode 'w' to 'wb', windows only supports wb
downloaded_file = File.new(new_file_xsweet, "wb")
downloaded_file.write(HTTParty.get("https://gitlab.coko.foundation/XSweet/XSweet/repository/archive.zip?ref=master").body)
downloaded_file.close
downloaded_file = File.new(new_file_typescript, "w")
downloaded_file = File.new(new_file_typescript, "wb")
downloaded_file.write(HTTParty.get("https://gitlab.coko.foundation/XSweet/editoria_typescript/repository/archive.zip?ref=master").body)
downloaded_file.close
downloaded_file = File.new(new_file_htmlevator, "w")
downloaded_file = File.new(new_file_htmlevator, "wb")
downloaded_file.write(HTTParty.get("https://gitlab.coko.foundation/XSweet/HTMLevator/repository/archive.zip?ref=master").body)
downloaded_file.close
if OS.mac?
# on linux change open to xdg-open
%x`open #{new_file_xsweet}`
sleep(1)
%x`open #{new_file_typescript}`
sleep(1)
%x`open #{new_file_htmlevator}`
sleep(1)
%x`open #{new_file_xsweet}`
sleep(1)
%x`open #{new_file_typescript}`
sleep(1)
%x`open #{new_file_htmlevator}`
sleep(1)
elsif OS.windows?
# Windows powershell command to extract files
%x`powershell.exe Expand-Archive #{new_file_xsweet} -DestinationPath (Get-Location).Path`
sleep(1)
%x`powershell.exe Expand-Archive #{new_file_typescript} -DestinationPath (Get-Location).Path`
sleep(1)
%x`powershell.exe Expand-Archive #{new_file_htmlevator} -DestinationPath (Get-Location).Path`
sleep(1)
else
%x`xdg-open #{new_file_xsweet}`
sleep(1)
%x`xdg-open #{new_file_typescript}`
sleep(1)
%x`xdg-open #{new_file_htmlevator}`
sleep(1)
puts new_file_xsweet
%x`xdg-open #{new_file_xsweet}`
sleep(1)
%x`xdg-open #{new_file_typescript}`
sleep(1)
%x`xdg-open #{new_file_htmlevator}`
sleep(1)
end
typescript_name = Dir.glob("editoria_typescript*").pop
......@@ -46,13 +56,17 @@ puts xsweet_name
puts "htmlevator_name"
puts htmlevator_name
%x`mv #{typescript_name} #{xsweet_name}/applications/typescript`
%x`mv #{htmlevator_name} #{xsweet_name}/applications/htmlevator`
%x`mkdir #{xsweet_name}/scripts`
#Instead of using '%x syntax' used the FileUtils to keep it simple
%x`mv ./execute_chain.sh #{xsweet_name}/scripts`
%x`mv ./execute_chain_production.sh #{xsweet_name}/scripts`
FileUtils.mv(typescript_name, "#{xsweet_name}/applications/typescript")
FileUtils.mv(htmlevator_name, "#{xsweet_name}/applications/htmlevator")
FileUtils.mkdir("#{xsweet_name}/scripts")
FileUtils.mv("./execute_chain.sh", "#{xsweet_name}/scripts")
FileUtils.mv("./execute_chain_production.sh", "#{xsweet_name}/scripts")
FileUtils.rm "xsweet.zip"
FileUtils.rm "typescript.zip"
FileUtils.rm "htmlevator.zip"
require 'os'
def execute_chain(rootPath, actualBookName, bookChapter)
commandname = "" #For Mac/Linux
if OS.windows?
#For windows environment
commandname = "powershell.exe"
end
# Note Saxon is included with this distribution, qv for license.
saxonHE="java -jar ../lib/SaxonHE9-9-1-1J/saxon9he.jar" # SaxonHE (XSLT 3.0 processor)
# INITIAL EXTRACTION
extract="../applications/docx-extract/docx-html-extract.xsl"
# RUNS `docx-table-extract.xsl`
notes="../applications/docx-extract/handle-notes.xsl"
scrub="../applications/docx-extract/scrub.xsl"
join="../applications/docx-extract/join-elements.xsl"
collapsepara="../applications/docx-extract/collapse-paragraphs.xsl"
# TAG PLAIN TEXT STRINGS THAT APPEAR TO BE URLS AS LINKS
links="../applications/htmlevator/applications/hyperlink-inferencer/hyperlink-inferencer.xsl"
# REBUILDS LISTS FROM WORD AS HTML
promotelists="../applications/list-promote/PROMOTE-lists.xsl"
# RUNS `mark-lists.xsl`, THEN `itemize-lists.xsl`
# DETECTS PLAIN-TEXT NUMBERED LISTS
detectlists="../applications/htmlevator/applications/list-detect/DETECT-ITEMIZE-LISTS.xsl"
# RUNS `detect-numbered-lists.xsl`, THEN `itemize-detected-lists.xsl`, THEN `scrub-literal-numbering-lists.xsl`
# HEADER PROMOTION BY OUTLINE LEVEL OR DISPLAY ATTRIBUTES
headerchooseandpromote="../applications/htmlevator/applications/header-promote/header-promotion-CHOOSE.xsl"
# MATH (OMML TO MML)
math="../applications/math/xsweet_tei_omml2mml.xsl"
# FINAL HTML CLEANUPS
finalrinse="../applications/html-polish/final-rinse.xsl"
# UNIVERSITY OF CALIFORNIA PRESS COPYEDITING CLEANUPS
ucptext="../applications/htmlevator/applications/ucp-cleanup/ucp-text-macros.xsl"
# UCP-SPECIFIC SPECIFIC ELEMENT MAPPING
ucpmap="../applications/htmlevator/applications/ucp-cleanup/ucp-mappings.xsl"
# EDITORIA TYPESCRIPT
splitonbr="../applications/typescript/p-split-around-br.xsl"
editoriabasic="../applications/typescript/editoria-basic.xsl"
editoriareduce="../applications/typescript/editoria-reduce.xsl"
# SERIALIZE TO HTML5
xmltohtml5="../applications/html-polish/html5-serialize.xsl"
%x`#{commandname} #{saxonHE} -xsl:#{extract} -s:#{rootPath}/#{bookChapter}/word/document.xml -o:../outputs/#{actualBookName}/#{bookChapter}-1EXTRACTED.xhtml`
puts "Made #{bookChapter}-1EXTRACTED.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{notes} -s:../outputs/#{actualBookName}/#{bookChapter}-1EXTRACTED.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-2NOTES.xhtml`
puts "Made #{bookChapter}-2NOTES.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{scrub} -s:../outputs/#{actualBookName}/#{bookChapter}-2NOTES.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-3SCRUBBED.xhtml`
puts "Made #{bookChapter}-3SCRUBBED.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{join} -s:../outputs/#{actualBookName}/#{bookChapter}-3SCRUBBED.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-4JOINED.xhtml`
puts "Made #{bookChapter}-4JOINED.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{collapsepara} -s:../outputs/#{actualBookName}/#{bookChapter}-4JOINED.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-5COLLAPSED.xhtml`
puts "Made #{bookChapter}-5COLLAPSED.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{links} -s:../outputs/#{actualBookName}/#{bookChapter}-5COLLAPSED.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-6LINKS.xhtml`
puts "Made #{bookChapter}-6LINKS.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{promotelists} -s:../outputs/#{actualBookName}/#{bookChapter}-6LINKS.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-7PROMOTELISTS.xhtml`
puts "Made #{bookChapter}-7PROMOTELISTS.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{detectlists} -s:../outputs/#{actualBookName}/#{bookChapter}-7PROMOTELISTS.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-8DETECTLISTS.xhtml`
puts "Made #{bookChapter}-8DETECTLISTS.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{headerchooseandpromote} -s:../outputs/#{actualBookName}/#{bookChapter}-8DETECTLISTS.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-9HEADERSPROMOTED.xhtml`
puts "Made #{bookChapter}-9HEADERSPROMOTED.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{math} -s:../outputs/#{actualBookName}/#{bookChapter}-9HEADERSPROMOTED.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-10MATH.xhtml`
puts "Made #{bookChapter}-10MATH.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{finalrinse} -s:../outputs/#{actualBookName}/#{bookChapter}-10MATH.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-11RINSED.xhtml`
puts "Made #{bookChapter}-11RINSED.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{ucptext} -s:../outputs/#{actualBookName}/#{bookChapter}-11RINSED.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-12UCPTEXTED.xhtml`
puts "Made #{bookChapter}-12UCPTEXTED.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{ucpmap} -s:../outputs/#{actualBookName}/#{bookChapter}-12UCPTEXTED.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-13UCPMAPPED.xhtml`
puts "Made #{bookChapter}-13UCPMAPPED.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{splitonbr} -s:../outputs/#{actualBookName}/#{bookChapter}-13UCPMAPPED.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-14SPLITONBR.xhtml`
puts "Made #{bookChapter}-14SPLITONBR.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{editoriabasic} -s:../outputs/#{actualBookName}/#{bookChapter}-14SPLITONBR.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-15EDITORIABASIC.xhtml`
puts "Made #{bookChapter}-15EDITORIABASIC.xhtml"
%x`#{commandname} #{saxonHE} -xsl:#{editoriareduce} -s:../outputs/#{actualBookName}/#{bookChapter}-15EDITORIABASIC.xhtml -o:../outputs/#{actualBookName}/#{bookChapter}-16EDITORIAREDUCE.html`
puts "Made #{bookChapter}-16EDITORIAREDUCE.html"
%x`#{commandname} #{saxonHE} -xsl:#{xmltohtml5} -s:../outputs/#{actualBookName}/#{bookChapter}-16EDITORIAREDUCE.html -o:../outputs/#{actualBookName}/#{bookChapter}-17HTML5.html`
puts "Made #{bookChapter}-17HTML5.html"
end
# starting = Time.now
xsweet_script_path = Dir.glob("XSweet-*").pop
......@@ -33,11 +140,12 @@ book_list.each do |book|
file_list.each do |chapter|
puts "converting: #{chapter}"
%x`sh execute_chain.sh #{convertDir}/#{book} #{book} #{chapter}`
execute_chain("#{convertDir}/#{book}", book, chapter)
#%x`sh execute_chain.sh #{convertDir}/#{book} #{book} #{chapter}`
end
puts "done with #{book}"
end
# ending = Time.now
# elapsed = ending - starting
# puts elapsed
\ No newline at end of file
# puts elapsedls
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment