mirror of
https://github.com/rsheldiii/KeyV2.git
synced 2024-11-22 05:03:40 +00:00
45940e8059
also add git post-commit hook to generate it, so I don't have to do this again
29 lines
580 B
Ruby
29 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
|