-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates_xml.lua
120 lines (93 loc) · 4.21 KB
/
templates_xml.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--[[ Copyright (C) 2015 Roberto Azevedo
This file is part of ncls3d.
ncls3d is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ncls3d is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ncls3d. If not, see <http://www.gnu.org/licenses/>.
--]]
local inspect = require "inspect"
local util = require "util"
local slaxml = require "slaxdom_ext"
local luatpl = require "luatpl/luatpl"
function get_file_content(path)
local f = assert(io.open(path, "r"))
local xml_content = f:read("*all")
f:close()
return xml_content
end
function get_root_element (xml_content)
-- Parse XML and print results
local doc = slaxml:dom(xml_content,{ simple=true })
if (doc) then
return doc.kids[1]
else
return nil
end
end
local TEMPLATES =
{
depth_control_media_start_content = get_file_content("tpl/depth_control_media_start.xml"),
depth_control_content = get_file_content("tpl/depth_control_media.xml"),
link_update_left_content = get_file_content("tpl/link_update_left.xml"),
link_update_right_content = get_file_content("tpl/link_update_right.xml"),
link_stop_depth_control = get_file_content("tpl/link_stop_depth_control.xml"),
link_set_depth_defaults = get_file_content("tpl/link_set_depth_defaults.xml")
}
function TEMPLATES:get_depth_control_media_start (str_id)
assert(str_id)
-- media_id is expected by the depth_control_media.xml template
local template_input = "local media_id = \""..str_id.."\"\n"
local solved = luatpl:solve(TEMPLATES.depth_control_media_start_content, template_input)
local root = get_root_element (solved)
return table.deepcopy(root)
end
function TEMPLATES:get_depth_control_media (str_id)
assert(str_id)
-- media_id is expected by the depth_control_media.xml template
local template_input = "local media_id = \""..str_id.."\"\n"
local solved = luatpl:solve(TEMPLATES.depth_control_content, template_input)
local root = get_root_element (solved)
return table.deepcopy(root)
end
function TEMPLATES:get_link_update_left (str_id)
assert(str_id)
local template_input = "local id_depth_control = \"".. str_id .. "_depth_control\"\n"
template_input = template_input .. "local id_left_media = \"".. str_id .. "\"\n"
local solved = luatpl:solve(TEMPLATES.link_update_left_content, template_input)
local root = get_root_element (solved)
return table.deepcopy(root)
end
function TEMPLATES:get_link_update_right (str_id)
assert(str_id)
local template_input = "local id_depth_control = \"".. str_id .. "_depth_control\"\n"
template_input = template_input .. "local id_right_media = \"".. str_id .. "_right\"\n"
template_input = template_input .. "local id_left_media = \"".. str_id .. "\"\n"
local solved = luatpl:solve(TEMPLATES.link_update_right_content, template_input)
local root = get_root_element (solved)
return table.deepcopy(root)
end
function TEMPLATES:get_link_stop_depth_control (str_id)
assert(str_id)
local template_input = "local id_depth_control = \"".. str_id .. "_depth_control\"\n"
template_input = template_input .. "local id_right_media = \"".. str_id .. "_right\"\n"
template_input = template_input .. "local id_left_media = \"".. str_id .. "\"\n"
local solved = luatpl:solve(TEMPLATES.link_stop_depth_control, template_input)
local root = get_root_element (solved)
return table.deepcopy(root)
end
function TEMPLATES:get_link_set_depth_defaults (str_id, orig_depth, orig_bounds)
assert(str_id)
local template_input = "local id_depth_control = \"".. str_id .. "_depth_control\"\n"
template_input = template_input .. "local orig_depth = \"".. orig_depth .. "\"\n"
template_input = template_input .. "local orig_bounds = \"".. orig_bounds .. "\"\n"
local solved = luatpl:solve(TEMPLATES.link_set_depth_defaults, template_input)
local root = get_root_element (solved)
return table.deepcopy(root)
end
return TEMPLATES