Files can now be queried for configuration properties.
This commit is contained in:
parent
96848b28f1
commit
32885d1673
@ -98,6 +98,21 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Merges the list of terms from an existing context.
|
||||||
|
--
|
||||||
|
-- @param ctx
|
||||||
|
-- The context to receive the copied terms.
|
||||||
|
-- @param src
|
||||||
|
-- The context containing the terms to copy.
|
||||||
|
--
|
||||||
|
|
||||||
|
function context.mergeFilters(ctx, src)
|
||||||
|
ctx.terms = table.merge(ctx.terms, table.deepcopy(src.terms))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Sets the base directory for path token expansion in non-path fields; such
|
-- Sets the base directory for path token expansion in non-path fields; such
|
||||||
-- values will be made relative to this path.
|
-- values will be made relative to this path.
|
||||||
|
@ -43,11 +43,24 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
function fileconfig.new(fname, prj)
|
function fileconfig.new(fname, prj)
|
||||||
local fcfg = {}
|
local environ = { }
|
||||||
|
local fcfg = context.new(prj, environ)
|
||||||
|
context.copyFilters(fcfg, prj)
|
||||||
|
context.addFilter(fcfg, "files", fname:lower())
|
||||||
|
|
||||||
|
for key, value in pairs(prj.environ) do
|
||||||
|
environ[key] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
environ.file = fcfg
|
||||||
|
context.compile(fcfg)
|
||||||
|
|
||||||
fcfg.project = prj
|
fcfg.project = prj
|
||||||
fcfg.configs = {}
|
fcfg.configs = {}
|
||||||
fcfg.abspath = fname
|
fcfg.abspath = fname
|
||||||
|
|
||||||
|
context.basedir(fcfg, prj.location)
|
||||||
|
|
||||||
-- Most of the other path properties are computed on demand
|
-- Most of the other path properties are computed on demand
|
||||||
-- from the file's absolute path.
|
-- from the file's absolute path.
|
||||||
|
|
||||||
@ -86,7 +99,7 @@
|
|||||||
local environ = {}
|
local environ = {}
|
||||||
local fsub = context.new(prj, environ)
|
local fsub = context.new(prj, environ)
|
||||||
context.copyFilters(fsub, cfg)
|
context.copyFilters(fsub, cfg)
|
||||||
context.addFilter(fsub, "files", fcfg.abspath:lower())
|
context.mergeFilters(fsub, fcfg)
|
||||||
|
|
||||||
fcfg.configs[cfg] = fsub
|
fcfg.configs[cfg] = fsub
|
||||||
|
|
||||||
@ -98,9 +111,9 @@
|
|||||||
environ[key] = value
|
environ[key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Make the context being built here accessible to tokens
|
for key, value in pairs(fcfg.environ) do
|
||||||
|
environ[key] = value
|
||||||
environ.file = fsub
|
end
|
||||||
|
|
||||||
-- finish the setup
|
-- finish the setup
|
||||||
|
|
||||||
@ -204,15 +217,16 @@
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- The indexer for the file configurations. If I have a path building function
|
-- The indexer for the file configurations. If I have a path building function
|
||||||
-- to fulfill the request, call it. Else this is a missing index so return nil.
|
-- to fulfill the request, call it. Else fall back to the context's own value lookups.
|
||||||
--
|
--
|
||||||
|
|
||||||
local fcfg_mt = fileconfig.fcfg_mt
|
local fcfg_mt = fileconfig.fcfg_mt
|
||||||
|
|
||||||
fcfg_mt.__index = function(file, key)
|
fcfg_mt.__index = function(fcfg, key)
|
||||||
if type(fcfg_mt[key]) == "function" then
|
if type(fcfg_mt[key]) == "function" then
|
||||||
return fcfg_mt[key](file)
|
return fcfg_mt[key](fcfg)
|
||||||
end
|
end
|
||||||
|
return context.__mt.__index(fcfg, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -222,8 +236,11 @@
|
|||||||
-- TODO: Would be great if this didn't require inside knowledge of context.
|
-- TODO: Would be great if this didn't require inside knowledge of context.
|
||||||
--
|
--
|
||||||
|
|
||||||
fileconfig.fsub_mt.__index = function(fcfg, key)
|
fileconfig.fsub_mt.__index = function(fsub, key)
|
||||||
return fcfg_mt.__index(fcfg, key) or context.__mt.__index(fcfg, key)
|
if type(fcfg_mt[key]) == "function" then
|
||||||
|
return fcfg_mt[key](fsub)
|
||||||
|
end
|
||||||
|
return context.__mt.__index(fsub, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user