From 13ec4b540e0d46c97fd7b089e0b7413da81e0a9f Mon Sep 17 00:00:00 2001 From: Marius Date: Sun, 19 May 2013 20:40:34 +0300 Subject: beta 2013.05.19 19:27 --- tex/context/base/lxml-dir.lua | 228 +++++++++++++++++++++--------------------- 1 file changed, 114 insertions(+), 114 deletions(-) (limited to 'tex/context/base/lxml-dir.lua') diff --git a/tex/context/base/lxml-dir.lua b/tex/context/base/lxml-dir.lua index 3c68664ae..4f0f61b71 100644 --- a/tex/context/base/lxml-dir.lua +++ b/tex/context/base/lxml-dir.lua @@ -1,114 +1,114 @@ -if not modules then modules = { } end modules ['lxml-dir'] = { - version = 1.001, - comment = "this module is the basis for the lxml-* ones", - author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", - copyright = "PRAGMA ADE / ConTeXt Development Team", - license = "see context related readme files" -} - -local gsub = string.gsub -local formatters = string.formatters - --- --- --- --- --- --- --- - -local lxml, context = lxml, context - -local getid = lxml.getid - -lxml.directives = lxml.directives or { } -local directives = lxml.directives - -local report_lxml = logs.reporter("xml","tex") - -local data = { - setup = { }, - before = { }, - after = { } -} - -local function load_setup(filename) - local fullname = resolvers.findtexfile(filename) or "" - if fullname ~= "" then - filename = fullname - end - local collection = xml.applylpath({ getid(xml.load(filename)) },"directive") -- is { } needed ? - if collection then - local valid = 0 - for i=1,#collection do - local at = collection[i].at - local attribute, value, element = at.attribute or "", at.value or "", at.element or '*' - local setup, before, after = at.setup or "", at.before or "", at.after or "" - if attribute ~= "" and value ~= "" then - local key = formatters["%s::%s::%s"](element,attribute,value) - local t = data[key] or { } - if setup ~= "" then t.setup = setup end - if before ~= "" then t.before = before end - if after ~= "" then t.after = after end - data[key] = t - valid = valid + 1 - end - end - report_lxml("%s directives found in %a, valid %s",#collection,filename,valid) - else - report_lxml("no directives found in %a",filename) - end -end - -local function handle_setup(category,root,attribute,element) - root = getid(root) - if attribute then - local value = root.at[attribute] - if value then - if not element then - local ns, tg = root.rn or root.ns, root.tg - if ns == "" then - element = tg - else - element = ns .. ':' .. tg - end - end - local setup = data[formatters["%s::%s::%s"](element,attribute,value)] - if setup then - setup = setup[category] - end - if setup then - context.directsetup(setup) - else - setup = data[formatters["%s::%s::*"](element,attribute)] - if setup then - setup = setup[category] - end - if setup then - setup = gsub(setup,'%*',value) - context.directsetup(setup) - end - end - end - end -end - -directives.load = load_setup -directives.handle = handle_setup - -function directives.setup(root,attribute,element) - handle_setup('setup',root,attribute,element) -end -function directives.before(root,attribute,element) - handle_setup('before',root,attribute,element) -end -function directives.after(root,attribute,element) - handle_setup('after',root,attribute,element) -end +if not modules then modules = { } end modules ['lxml-dir'] = { + version = 1.001, + comment = "this module is the basis for the lxml-* ones", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local gsub = string.gsub +local formatters = string.formatters + +-- +-- +-- +-- +-- +-- +-- + +local lxml, context = lxml, context + +local getid = lxml.getid + +lxml.directives = lxml.directives or { } +local directives = lxml.directives + +local report_lxml = logs.reporter("xml","tex") + +local data = { + setup = { }, + before = { }, + after = { } +} + +local function load_setup(filename) + local fullname = resolvers.findtexfile(filename) or "" + if fullname ~= "" then + filename = fullname + end + local collection = xml.applylpath({ getid(xml.load(filename)) },"directive") -- is { } needed ? + if collection then + local valid = 0 + for i=1,#collection do + local at = collection[i].at + local attribute, value, element = at.attribute or "", at.value or "", at.element or '*' + local setup, before, after = at.setup or "", at.before or "", at.after or "" + if attribute ~= "" and value ~= "" then + local key = formatters["%s::%s::%s"](element,attribute,value) + local t = data[key] or { } + if setup ~= "" then t.setup = setup end + if before ~= "" then t.before = before end + if after ~= "" then t.after = after end + data[key] = t + valid = valid + 1 + end + end + report_lxml("%s directives found in %a, valid %s",#collection,filename,valid) + else + report_lxml("no directives found in %a",filename) + end +end + +local function handle_setup(category,root,attribute,element) + root = getid(root) + if attribute then + local value = root.at[attribute] + if value then + if not element then + local ns, tg = root.rn or root.ns, root.tg + if ns == "" then + element = tg + else + element = ns .. ':' .. tg + end + end + local setup = data[formatters["%s::%s::%s"](element,attribute,value)] + if setup then + setup = setup[category] + end + if setup then + context.directsetup(setup) + else + setup = data[formatters["%s::%s::*"](element,attribute)] + if setup then + setup = setup[category] + end + if setup then + setup = gsub(setup,'%*',value) + context.directsetup(setup) + end + end + end + end +end + +directives.load = load_setup +directives.handle = handle_setup + +function directives.setup(root,attribute,element) + handle_setup('setup',root,attribute,element) +end +function directives.before(root,attribute,element) + handle_setup('before',root,attribute,element) +end +function directives.after(root,attribute,element) + handle_setup('after',root,attribute,element) +end -- cgit v1.2.3