Class: IB::Generator
- Inherits:
-
Object
- Object
- IB::Generator
- Defined in:
- lib/ib/generator.rb
Instance Method Summary collapse
- #generate_action(action) ⇒ Object
- #generate_objc(files) ⇒ Object
- #generate_objc_impl(files) ⇒ Object
- #generate_type(type) ⇒ Object
- #write(files, dest) ⇒ Object
Instance Method Details
#generate_action(action) ⇒ Object
73 74 75 |
# File 'lib/ib/generator.rb', line 73 def generate_action action action[1] ? "#{action[0]}:(#{action[2] ? "#{action[2]}*" : 'id'}) #{action[1]}" : "#{action[0]}" end |
#generate_objc(files) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ib/generator.rb', line 33 def generate_objc files output = "" files.map do |path, infos| infos.each do |info| output << "@interface \#{info[:class][0][0]}\#{info[:class][0][1] ? \": \#{info[:class][0][1]}\" : \"\"}\n\n\#{info[:outlets].map {|name, type| \"@property IBOutlet \#{generate_type(type)} \#{name};\" }.join(\"\\n\")}\n\n\#{info[:outlet_collections].map {|name, type| \"@property IBOutletCollection(\#{type}) NSArray * \#{name};\" }.join(\"\\n\")}\n\n\#{info[:actions].map {|action| \"-(IBAction) \#{generate_action(action)};\" }.join(\"\\n\")}\n\n@end\n" output << "\n\n" end end output end |
#generate_objc_impl(files) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ib/generator.rb', line 54 def generate_objc_impl files output = "" files.map do |path, infos| infos.each do |info| output << "@implementation \#{info[:class][0][0]}\n\n@end\n" output << "\n\n" end end output end |
#generate_type(type) ⇒ Object
69 70 71 |
# File 'lib/ib/generator.rb', line 69 def generate_type type type == "id" ? type : "#{type} *" end |
#write(files, dest) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ib/generator.rb', line 2 def write files, dest files = IB::Parser.new.find_all(files) FileUtils.mkpath dest File.open("#{dest}/Stubs.h", 'w') do |f| f.write "// Generated by IB v\#{IB::VERSION} gem. Do not edit it manually\n// Run `rake ib:open` to refresh\n\n#import <Foundation/Foundation.h>\n#import <CoreData/CoreData.h>\n#import <UIKit/UIKit.h>\n\n\#{generate_objc(files)}\n" end File.open("#{dest}/Stubs.m", 'w') do |f| f.write "// Generated by IB v\#{IB::VERSION} gem. Do not edit it manually\n// Run `rake ib:open` to refresh\n\n#import \"Stubs.h\"\n\n\#{generate_objc_impl(files)}\n" end end |