Sha256: 38c42cdc5cb2dbd6791863eb83a5b3355ee4e5b3d2a1a225b226b06f68d33b00
Contents?: true
Size: 1.2 KB
Versions: 3
Compression:
Stored size: 1.2 KB
Contents
class IB::Generator def write src, dest files = IB::Parser.new.find_all(src) FileUtils.mkpath dest File.open("#{dest}/Stubs.h", 'w') do |f| f.write <<-OBJC // Generated by IB v#{IB::VERSION} gem. Do not edit it manually // Run `rake design` to refresh #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> #import <UIKit/UIKit.h> #{generate_objc(files)} OBJC end File.open("#{dest}/Stubs.m", 'w') do |f| f.write <<-OBJC // Generated by IB v#{IB::VERSION} gem. Do not edit it manually // Run `rake design` to refresh #import "Stubs.h" #{generate_objc_impl(files)} OBJC end end def generate_objc files src = files.map do |path, info| <<-OBJC @interface #{info[:class][0][0]} : #{info[:class][0][1]} #{info[:outlets].map {|name, type| "@property IBOutlet #{generate_type(type)} #{name};" }.join("\n")} #{info[:actions].map {|action| "-(IBAction) #{action[0]}:(id) sender;" }.join("\n")} @end OBJC end.join("\n" * 2) end def generate_objc_impl files src = files.map do |path, info| <<-OBJC @implementation #{info[:class][0][0]} @end OBJC end.join("\n" * 2) end def generate_type type type == "id" ? type : "#{type} *" end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ib-0.1.3 | lib/ib/generator.rb |
ib-0.1.2 | lib/ib/generator.rb |
ib-0.1.1 | lib/ib/generator.rb |