30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/maigo.rb', line 30
def self.find_missing_outlets(dir)
storyboard_outlet_hash = {}
Dir.glob("#{dir}/**/*.storyboard") do |file|
xml = Nokogiri::XML(open(file))
xml.xpath('//viewController').each do |node|
storyboard_outlet_hash[node["customClass"]] = []
node.xpath("connections/outlet").each do |outlet|
storyboard_outlet_hash[node["customClass"]] << outlet["property"]
end
end
end
source_outlet_hash = {}
Dir.glob("#{dir}/**/*.swift") do |file|
class_name = nil
open(file).each do |line|
if line =~ /class\s+(\w+)/
class_name = $1
if line =~ /class\s+var/ or line =~ /class\s+func/
class_name = nil
next
end
end
end
next if class_name.nil?
source_outlet_hash[class_name] = []
open(file).each do |line|
if line =~ /@IBOutlet\s.*var\s(\w+)/
outlet_name = $1
next if line =~ /\/\/.*@IBOutlet/
source_outlet_hash[class_name] << outlet_name
end
end
end
missing_controllers = []
missing_outlets = []
storyboard_outlet_hash.each do |controller, outlets|
if source_outlet_hash[controller].nil?
missing_controllers << controller
next
end
outlets.each do |outlet|
if !source_outlet_hash[controller].include?(outlet)
missing_outlets << [controller, outlet]
end
end
end
return missing_controllers, missing_outlets
end
|