2018-07-05 01:12:07 +00:00
|
|
|
module OpenSCAD
|
|
|
|
def self.expand(filename)
|
|
|
|
lines = File.readlines(filename)
|
|
|
|
old_dir = Dir.getwd
|
|
|
|
|
|
|
|
Dir.chdir File.dirname(filename)
|
|
|
|
lines = lines.flat_map do |line|
|
2020-04-24 23:51:43 +00:00
|
|
|
# please note we do not implement `use` at all
|
2018-07-05 01:12:07 +00:00
|
|
|
if line =~ /(include|use)\s*<(.*)>/
|
|
|
|
# File.readlines("./#{$2}")
|
|
|
|
expand("./#{$2}")
|
|
|
|
else
|
|
|
|
line
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Dir.chdir old_dir
|
|
|
|
|
|
|
|
lines
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.expand_openSCAD_file(source, destination)
|
|
|
|
lines = OpenSCAD::expand(source)
|
|
|
|
|
|
|
|
f = File.open(destination, 'w')
|
|
|
|
f.write lines.join
|
|
|
|
end
|
|
|
|
end
|