From ae6e6d9d13c2d7f452fdf2253ed1ab3002e15777 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 9 May 2011 17:40:16 +0300 Subject: beta 2011.05.09 16:28 --- scripts/context/lua/mtx-epub.lua | 149 +++++++++++++++++++++++++++++++++++++++ scripts/context/lua/mtx-flac.lua | 4 +- 2 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 scripts/context/lua/mtx-epub.lua (limited to 'scripts') diff --git a/scripts/context/lua/mtx-epub.lua b/scripts/context/lua/mtx-epub.lua new file mode 100644 index 000000000..5239028ba --- /dev/null +++ b/scripts/context/lua/mtx-epub.lua @@ -0,0 +1,149 @@ +if not modules then modules = { } end modules ['mtx-epub'] = { + version = 1.001, + comment = "companion to mtxrun.lua", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local format = string.format +local concat = table.concat + +local helpinfo = [[ +--make create epub zip file + +example: + +mtxrun --script epub --make mydocument +]] + +local application = logs.application { + name = "mtx-epub", + banner = "ConTeXt EPUB Helpers 0.10", + helpinfo = helpinfo, +} + +-- script code + +scripts = scripts or { } +scripts.epub = scripts.epub or { } + +local mimetype = "application/epub+zip" + +local container = [[ + + + + + + + +]] + +local package = [[ + + + + + + My Title + en + + MySelf + + + + %s + + + + + + + +]] + +local mimetypes = { + xhtml = "application/xhtml+xml", + css = "text/css", +} + +-- specification = { +-- name = "document", +-- identifier = "123", +-- root = "a.xhtml", +-- files = { +-- "a.xhtml", +-- "b.css", +-- "c.png", +-- } +-- } + +function scripts.epub.make() + + local filename = environment.files[1] + + if filename and filename ~= "" then + + filename = file.basename(filename) + local specfile = file.replacesuffix(filename,"specification") + local specification = lfs.isfile(specfile) and dofile(specfile) or { } + + inspect(specification) + + local name = specification.name or file.removesuffix(filename) + local identifier = specification.identifier or os.uuid() + local files = specification.files or { file.addsuffix(filename,"xhtml") } + local root = specification.root or files[1] + + local epubname = name + local epubpath = file.replacesuffix(name,"tree") + local epubfile = file.replacesuffix(name,"epub") + local epubroot = file.replacesuffix(name,"opf") + + local used = { } + + for i=1,#files do + local filename = files[i] + local suffix = file.suffix(filename) + local mime = mimetypes[suffix] + if mime then + file.copy(filename,file.join(epubpath,"OPS",filename)) + used[#used+1] = format("",i,filename,mime) + end + end + + container = format(container,epubroot) + package = format(package,identifier,identifier,concat(used,"\n"),root) + + lfs.mkdir(epubpath) + lfs.mkdir(file.join(epubpath,"META-INF")) + lfs.mkdir(file.join(epubpath,"OPS")) + + io.savedata(file.join(epubpath,"mimetype"),mimetype) + io.savedata(file.join(epubpath,"META-INF","container.xml"),container) + io.savedata(file.join(epubpath,"OPS",epubroot),package) + + lfs.chdir(epubpath) + + os.remove(epubfile) + + os.execute(format("zip %s -0 %s",epubfile,"mimetype")) + os.execute(format("zip %s -r %s",epubfile,"META-INF")) + os.execute(format("zip %s -r %s",epubfile,"OPS")) + + lfs.chdir("..") + + application.report("epub archive: %s",file.join(epubpath,epubfile)) + + end + +end + +-- + +if environment.argument("make") then + scripts.epub.make() +else + application.help() +end diff --git a/scripts/context/lua/mtx-flac.lua b/scripts/context/lua/mtx-flac.lua index 0f517f3d4..37f985654 100644 --- a/scripts/context/lua/mtx-flac.lua +++ b/scripts/context/lua/mtx-flac.lua @@ -170,8 +170,8 @@ local helpinfo = [[ example: -mtxrun --collect somename.flac -mtxrun --collect --pattern="m:/music/**") +mtxrun --script flac --collect somename.flac +mtxrun --script flac --collect --pattern="m:/music/**") ]] local application = logs.application { -- cgit v1.2.3