Module: LaneKit
- Defined in:
- lib/lanekit.rb,
lib/lanekit.rb,
lib/lanekit/new.rb,
lib/lanekit/version.rb,
lib/lanekit/lanefile.rb,
lib/lanekit/generate/model.rb,
lib/lanekit/generate/provider.rb,
lib/lanekit/generate/urbanairship.rb,
lib/lanekit/generate/tableviewcontroller.rb
Defined Under Namespace
Classes: CLI, Generate, Lanefile
Constant Summary
collapse
- VERSION =
"0.4.3"
- @@objc_types =
{
"array" => "NSArray *"
}
Class Method Summary
collapse
-
.add_file_to_project(file_name, group_name, project_path, target_name = nil) ⇒ Object
Adds a file to a group in an Xcode project For example: LaneKit.add_file_to_project(‘Models/Video.m’, ‘SportsFrames/Models’, ‘SportsFrames’, ‘SportsFrames’).
-
.add_pod_to_podfile(pod_name) ⇒ Object
Adds a pod file line to a CocoaPods Podfile.
-
.controllers_folder(lanefile) ⇒ Object
-
.controllers_group(lanefile) ⇒ Object
-
.derive_app_name(app_path) ⇒ Object
Returns an app name from a folder path.
-
.derive_class_name(name) ⇒ Object
Objective-C class names are capitalized “car” => “Car”, “bigbird” => “Bigbird”.
-
.derive_file_name(name) ⇒ Object
File names are the same as class names.
-
.derive_model_name(name) ⇒ Object
Model names are lower case “Car” => “car”, “Bigbird” => “bigbird”.
-
.does_text_exist_in_file?(file_path, text) ⇒ Boolean
-
.gem_available?(gemname) ⇒ Boolean
-
.objective_c_type(type_name) ⇒ Object
-
.objective_c_type_fixture_json(type_name) ⇒ Object
-
.objective_c_type_fixture_value(type_name) ⇒ Object
-
.objective_c_type_unit_test_assert(model_name, name, type_name) ⇒ Object
-
.template_folders ⇒ Object
-
.validate_app_name(app_name) ⇒ Object
-
.validate_bundle_id(bundle_id) ⇒ Object
-
.validate_lanefile(lanefile) ⇒ Object
-
.validate_pod_name(pod_name) ⇒ Object
-
.views_folder(lanefile) ⇒ Object
-
.views_group(lanefile) ⇒ Object
Class Method Details
.add_file_to_project(file_name, group_name, project_path, target_name = nil) ⇒ Object
Adds a file to a group in an Xcode project For example: LaneKit.add_file_to_project(‘Models/Video.m’, ‘SportsFrames/Models’, ‘SportsFrames’, ‘SportsFrames’)
21
22
23
24
25
26
27
28
29
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
|
# File 'lib/lanekit.rb', line 21
def self.add_file_to_project(file_name, group_name, project_path, target_name=nil)
project = Xcodeproj::Project.open(project_path)
group = project[group_name]
ref = group.find_file_by_path(file_name)
return if ref
file = group.new_reference(file_name)
if target_name == "@all"
project.targets.each do |target|
target.add_file_references([file])
end
elsif target_name
unless target = project.targets.find { |target| target.name == target_name }
raise ArgumentError, "Target by name `#{target_name}' not found in the project."
end
target.add_file_references([file])
end
project.save
end
|
.add_pod_to_podfile(pod_name) ⇒ Object
Adds a pod file line to a CocoaPods Podfile
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/lanekit.rb', line 59
def self.add_pod_to_podfile(pod_name)
podfile_path = File.expand_path('Podfile')
if !File.exists?(podfile_path)
puts "Can't find Podfile #{podfile_path}"
return
end
if !self.does_text_exist_in_file?(podfile_path, pod_name)
open(podfile_path, 'a') do |file|
file.puts "pod '#{pod_name}'"
end
system "pod install"
else
puts "The pod '#{pod_name}' already exists in Podfile"
end
end
|
.controllers_folder(lanefile) ⇒ Object
237
238
239
|
# File 'lib/lanekit.rb', line 237
def self.controllers_folder(lanefile)
"#{lanefile.app_project_name}/#{lanefile.app_project_name}/Controllers"
end
|
.controllers_group(lanefile) ⇒ Object
241
242
243
|
# File 'lib/lanekit.rb', line 241
def self.controllers_group(lanefile)
"#{lanefile.app_project_name}/Controllers"
end
|
.derive_app_name(app_path) ⇒ Object
Returns an app name from a folder path. “Tracker” => “Tracker”, “~/Projects/Runner” => “Runner”
79
80
81
|
# File 'lib/lanekit.rb', line 79
def self.derive_app_name(app_path)
app_name = File.basename(app_path).to_s
end
|
.derive_class_name(name) ⇒ Object
Objective-C class names are capitalized “car” => “Car”, “bigbird” => “Bigbird”
92
93
94
95
|
# File 'lib/lanekit.rb', line 92
def self.derive_class_name(name)
class_name = name.to_s.capitalize
class_name
end
|
.derive_file_name(name) ⇒ Object
File names are the same as class names
98
99
100
101
|
# File 'lib/lanekit.rb', line 98
def self.derive_file_name(name)
file_name = name.to_s.capitalize
file_name
end
|
.derive_model_name(name) ⇒ Object
Model names are lower case “Car” => “car”, “Bigbird” => “bigbird”
85
86
87
88
|
# File 'lib/lanekit.rb', line 85
def self.derive_model_name(name)
model_name = name.to_s.downcase
model_name
end
|
.does_text_exist_in_file?(file_path, text) ⇒ Boolean
103
104
105
106
|
# File 'lib/lanekit.rb', line 103
def self.does_text_exist_in_file?(file_path, text)
found_text = open(file_path) { |f| f.grep(/#{text}/) }
exists = found_text && found_text.count > 0
end
|
.gem_available?(gemname) ⇒ Boolean
206
207
208
209
210
211
212
|
# File 'lib/lanekit.rb', line 206
def self.gem_available?(gemname)
if Gem::Specification.methods.include?(:find_all_by_name)
not Gem::Specification.find_all_by_name(gemname).empty?
else
Gem.available?(gemname)
end
end
|
.objective_c_type(type_name) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/lanekit.rb', line 108
def self.objective_c_type(type_name)
type = @@objc_types[type_name]
return type if type
if type_name == "array"
type = "NSArray *"
elsif type_name == "date"
type = "NSDate *"
elsif type_name == "integer"
type = "NSNumber *"
elsif type_name == "string"
type = "NSString *"
elsif type_name
type = type_name + " *"
else
type = "id "
end
type
end
|
.objective_c_type_fixture_json(type_name) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/lanekit.rb', line 128
def self.objective_c_type_fixture_json(type_name)
if type_name == "array"
value = "[]"
elsif type_name == "date"
value = "03/01/2012"
elsif type_name == "integer"
value = "1"
elsif type_name == "string"
value = "MyString"
elsif type_name
value = ""
else
value = ""
end
value
end
|
.objective_c_type_fixture_value(type_name) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/lanekit.rb', line 145
def self.objective_c_type_fixture_value(type_name)
if type_name == "array"
value = "@[]"
elsif type_name == "date"
value = "NSDate.new"
elsif type_name == "integer"
value = "[NSNumber numberWithInteger:1]"
elsif type_name == "string"
value = "@\"MyString\""
elsif type_name
value = "nil"
else
value = "nil"
end
value
end
|
.objective_c_type_unit_test_assert(model_name, name, type_name) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/lanekit.rb', line 162
def self.objective_c_type_unit_test_assert(model_name, name, type_name)
if type_name == "array"
assert = "STAssertNotNil(#{model_name}.#{name}, @\"#{name} is nil\")"
elsif type_name == "date"
assert = "STAssertNotNil(#{model_name}.#{name}, @\"#{name} is nil\")"
elsif type_name == "integer"
assert = "STAssertTrue(#{model_name}.#{name}.integerValue == #{self.objective_c_type_fixture_value(type_name)}.integerValue, @\"#{name} not #{self.objective_c_type_fixture_value(type_name)}\")"
elsif type_name == "string"
assert = "STAssertTrue([#{model_name}.#{name} isEqualToString:#{self.objective_c_type_fixture_value(type_name)}], @\"#{name} not correct value\")"
elsif type_name
assert = "STAssertNotNil(#{model_name}.#{name}, @\"#{name} is nil\")"
else
assert = "STAssertNotNil(#{model_name}.#{name}, @\"#{name} is nil\")"
end
assert
end
|
.template_folders ⇒ Object
15
16
17
|
# File 'lib/lanekit.rb', line 15
def self.template_folders
[@template_folder]
end
|
.validate_app_name(app_name) ⇒ Object
179
180
181
182
183
184
185
186
|
# File 'lib/lanekit.rb', line 179
def self.validate_app_name(app_name)
if app_name.length < 2
return "app name must be at least two characters long"
elsif app_name.include? " "
return "app name cannot include spaces"
end
return nil
end
|
.validate_bundle_id(bundle_id) ⇒ Object
197
198
199
200
201
202
203
204
|
# File 'lib/lanekit.rb', line 197
def self.validate_bundle_id(bundle_id)
if bundle_id.length < 2
return "bundle id must be at least two characters long"
elsif bundle_id.include? " "
return "bundle id cannot include spaces"
end
return nil
end
|
.validate_lanefile(lanefile) ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/lanekit.rb', line 214
def self.validate_lanefile(lanefile)
if !lanefile.exists?
return "Error: Cannot find 'Lanefile' in the current folder. Is this a LaneKit generated app folder?"
end
app_project_path = lanefile.app_project_path
if !File.exists?(app_project_path)
return "Lanefile Error: cannot find project: #{app_project_path}"
end
if !lanefile.app_project_name || !lanefile.app_project_name.length
return "Lanefile Error: missing app_project_name"
end
if !lanefile.app_target_name || !lanefile.app_target_name.length
return "Lanefile Error: missing app_target_name"
end
if !lanefile.app_target_tests_name || !lanefile.app_target_tests_name.length
return "Lanefile Error: missing app_target_tests_name"
end
end
|
.validate_pod_name(pod_name) ⇒ Object
188
189
190
191
192
193
194
195
|
# File 'lib/lanekit.rb', line 188
def self.validate_pod_name(pod_name)
if pod_name.length < 2
return "pod name must be at least two characters long"
elsif pod_name.include? " "
return "pod name cannot include spaces"
end
return nil
end
|
.views_folder(lanefile) ⇒ Object
245
246
247
|
# File 'lib/lanekit.rb', line 245
def self.views_folder(lanefile)
"#{lanefile.app_project_name}/#{lanefile.app_project_name}/Views"
end
|
.views_group(lanefile) ⇒ Object
249
250
251
|
# File 'lib/lanekit.rb', line 249
def self.views_group(lanefile)
"#{lanefile.app_project_name}/Views"
end
|