mirror of
https://github.com/rsheldiii/KeyV2.git
synced 2025-02-16 14:27:01 +00:00
28 lines
580 B
Ruby
28 lines
580 B
Ruby
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|
|
|
# please note we do not implement `use` at all
|
|
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
|