58 lines
1.1 KiB
Ruby
Executable file
58 lines
1.1 KiB
Ruby
Executable file
#!/usr/bin/ruby
|
|
|
|
def replaceAll(line, subst)
|
|
subst.each do |sub,rep|
|
|
line = line.gsub('{' + sub + '}', rep)
|
|
end
|
|
|
|
return line
|
|
end
|
|
|
|
def degenerateCaps(text)
|
|
text = text.gsub(/[A-Z]+[a-z]+/) do |s|
|
|
s.downcase + '_'
|
|
end
|
|
|
|
return text[0..-2]
|
|
end
|
|
|
|
subst = {}
|
|
name = ARGV[0]
|
|
parent = ARGV[1]
|
|
|
|
if (name == nil) then
|
|
print "Class name (capitalized): "
|
|
name = gets[0..-2]
|
|
end
|
|
|
|
subst['template_'] = degenerateCaps(name)
|
|
subst['template-'] = subst['template_'].sub('_', '-')
|
|
subst['TEMPLATE'] = subst['template_'].upcase
|
|
subst['Template'] = name
|
|
|
|
if (parent == nil) then
|
|
print "Parent name (capitalized): "
|
|
parent = gets[0..-2]
|
|
end
|
|
|
|
subst['parent_'] = degenerateCaps(parent)
|
|
subst['parent-'] = subst['parent_'].sub('_', '-')
|
|
subst['PARENT'] = subst['parent_'].upcase
|
|
subst['Parent'] = parent
|
|
|
|
tc = IO.readlines("gtktemplate.c")
|
|
th = IO.readlines("gtktemplate.h")
|
|
|
|
f = File.open('gm-' + subst['template-'] + '.c', 'w')
|
|
tc.each do |line|
|
|
f.write(replaceAll(line, subst))
|
|
end
|
|
f.close
|
|
|
|
f = File.open('gm-' + subst['template-'] + '.h', 'w')
|
|
th.each do |line|
|
|
f.write(replaceAll(line, subst))
|
|
end
|
|
f.close
|
|
|
|
print "Done ...\n"
|