Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- AutoExpand Category_fr / SubCategory_fr
- -- Will look up Category_fr-SubCategory_fr in the the csv list and assign all metadayta if matches
- -- Modified by Theo Serror June 3,2020
- -- Based on Justin Drury's built-in "AutoExpand from Category SubCategory.lua"
- allowUndo=true
- -- [[ ================= HELPER FUNCTIONS ================= ]]--
- function table_print (tt, indent, done)
- done = done or {}
- indent = indent or 0
- if type(tt) == "table" then
- for key, value in pairs (tt) do
- io.write(string.rep (" ", indent)) -- indent it
- if type (value) == "table" and not done [value] then
- done [value] = true
- io.write(string.format("[%s] => table\n", tostring (key)));
- io.write(string.rep (" ", indent+4)) -- indent it
- io.write("(\n");
- table_print (value, indent + 7, done)
- io.write(string.rep (" ", indent+4)) -- indent it
- io.write(")\n");
- else
- io.write(string.format("[%s] => %s\n",
- tostring (key), tostring(value)))
- end
- end
- else
- io.write(tt .. "\n")
- end
- end
- --[[ ========================================================== ]]--
- -- This uses a Lua capability called closure.
- function setup()
- -- put the cat entries in a list I can quickly lookup
- local lookupTable={}
- _.each(cat_entries,function(entry)
- local key=entry['Category_fr']
- if key ~='' and entry['SubCategory_fr'] ~='' then
- key=key..'-'..entry['SubCategory_fr']
- end
- print(key)
- if key ~='' then
- lookupTable[key]=entry
- end
- end)
- return function(fileMetadata)
- local changedMetadata={}
- local key=fileMetadata['Category_fr']
- if key ~='' and fileMetadata['SubCategory_fr'] or '' ~='' then
- key=key..'-'..fileMetadata['SubCategory_fr']
- end
- if key ~='' then
- local csvData=lookupTable[key]
- if csvData then
- return csvData
- end
- end
- return changedMetadata
- end
- end
- --[[ ========================================================== ]]--
- processMetadata=setup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement