lanekit 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  ## LaneKit
2
2
 
3
- LaneKit is an iOS Objective-C code generator of models and resource providers for integration with RestKit. It includes support
4
- for unit testing with SenTestingKit including fixtures and tests. LaneKit is a command line app written
5
- in Ruby and packaged as a Ruby Gem.
3
+ LaneKit is an iOS Objective-C code generator for integration with RestKit. It generates
4
+ models, resource providers, and full iOS apps with mimimal effort. There is support for unit testing with SenTestingKit
5
+ including fixtures and tests. LaneKit is a command line app written in Ruby and packaged as a Ruby Gem.
6
6
 
7
7
  - [Source code for LaneKit](https://github.com/LarryAasen/LaneKit/zipball/master) from [GitHub](http://github.com).
8
8
  - Questions? [Stack Overflow](http://stackoverflow.com/questions/tagged/lanekit) is the best place to find answers.
@@ -13,6 +13,7 @@ in Ruby and packaged as a Ruby Gem.
13
13
  * consistent Objective-C code
14
14
  * unit tests
15
15
  * test fixtures in JSON and Objective-C
16
+ * iOS app creation fully integrated with CocoaPods and RestKit
16
17
  * tested code
17
18
  * rapid development
18
19
  * enhanced productivity of junior developers
@@ -33,19 +34,19 @@ in Ruby and packaged as a Ruby Gem.
33
34
 
34
35
  $ lanekit generate model Video duration:string headline:string id:integer image:string location:string
35
36
 
36
- create Classes/Models
37
- create Classes/Tests/Fixtures
38
- create Classes/Tests/Models
39
- create Classes/Models/Contents.h
40
- create Classes/Models/Contents.m
41
- create Classes/Tests/Fixtures/ContentsFixtures.h
42
- create Classes/Tests/Fixtures/ContentsFixtures.m
43
- create Classes/Tests/Fixtures/ContentsFixtures.one.json
44
- create Classes/Tests/Fixtures/ContentsFixtures.two.json
45
- create Classes/Tests/Models/ContentsTest.h
46
- create Classes/Tests/Models/ContentsTest.m
47
- create Classes/Models/LKModel.h
48
- create Classes/Models/LKModel.m
37
+ create Classes/Models
38
+ create Classes/Tests/Fixtures
39
+ create Classes/Tests/Models
40
+ create Classes/Models/Video.h
41
+ create Classes/Models/Video.m
42
+ create Classes/Tests/Fixtures/VideoFixtures.h
43
+ create Classes/Tests/Fixtures/VideoFixtures.m
44
+ create Classes/Tests/Fixtures/VideoFixtures.one.json
45
+ create Classes/Tests/Fixtures/VideoFixtures.two.json
46
+ create Classes/Tests/Models/VideoTest.h
47
+ create Classes/Tests/Models/VideoTest.m
48
+ create Classes/Models/LKModel.h
49
+ create Classes/Models/LKModel.m
49
50
 
50
51
  and here is the Objective-C header file that was generated by LaneKit:
51
52
 
@@ -53,17 +54,15 @@ and here is the Objective-C header file that was generated by LaneKit:
53
54
  //
54
55
  // Video.h
55
56
  //
56
- // This model was created on 2013-08-10 by LaneKit v0.1.7.
57
+ // This model was created on 2013-10-20 by LaneKit v0.3.0.
57
58
  //
58
- // The following LaneKit command was used to generate this model:
59
+ // The following LaneKit command was used to generate this file:
59
60
  // lanekit generate model Video duration:string headline:string id:integer image:string location:string
60
61
  //
61
62
 
62
- #import <Foundation/Foundation.h>
63
+ #import "LKModel.h"
63
64
 
64
- @class RKObjectMapping;
65
-
66
- @interface Video : NSObject
65
+ @interface Video : LKModel
67
66
 
68
67
  @property (nonatomic,strong) NSString *duration;
69
68
  @property (nonatomic,strong) NSString *headline;
@@ -71,9 +70,6 @@ and here is the Objective-C header file that was generated by LaneKit:
71
70
  @property (nonatomic,strong) NSString *image;
72
71
  @property (nonatomic,strong) NSString *location;
73
72
 
74
- + (RKObjectMapping *)requestMapping;
75
- + (RKObjectMapping *)responseMapping;
76
-
77
73
  @end
78
74
  ```
79
75
 
@@ -83,46 +79,45 @@ and here is the Objective-C .m file that was generated by LaneKit:
83
79
  //
84
80
  // Video.m
85
81
  //
86
- // This model was created on 2013-08-10 by LaneKit v0.1.7.
82
+ // This model was created on 2013-10-20 by LaneKit v0.3.0.
83
+ //
84
+ // The following LaneKit command was used to generate this file:
85
+ // lanekit generate model Video duration:string headline:string id:integer image:string location:string
87
86
  //
88
87
 
89
88
  #import "Video.h"
90
- #import "RestKit.h"
91
89
 
92
90
  @implementation Video
93
91
 
94
- + (void)initialize
95
- {
96
- if (self == [Video class])
97
- {
98
- }
99
- }
100
-
101
- + (NSDictionary *)dictionaryForMappings
92
+ // Dictionary to convert self to JSON
93
+ + (NSDictionary *)dictionaryForRequestMappings
102
94
  {
103
95
  return @{
104
- @"duration": @"duration",
105
- @"headline": @"headline",
106
- @"id": @"id",
107
- @"image": @"image",
108
- @"location": @"location"
96
+ // source key path : destination attribute name
97
+ @"duration": @"duration",
98
+ @"headline": @"headline",
99
+ @"id": @"id",
100
+ @"image": @"image",
101
+ @"location": @"location"
109
102
  };
110
103
  }
111
104
 
112
- // Returns the request RKObjectMapping
113
- + (RKObjectMapping *)requestMapping
105
+ // Dictionary to convert JSON to self
106
+ + (NSDictionary *)dictionaryForResponseMappings
114
107
  {
115
- RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
116
- [requestMapping addAttributeMappingsFromDictionary:[self dictionaryForMappings]];
117
- return requestMapping;
108
+ return @{
109
+ // source key path : destination attribute name
110
+ @"duration": @"duration",
111
+ @"headline": @"headline",
112
+ @"id": @"id",
113
+ @"image": @"image",
114
+ @"location": @"location"
115
+ };
118
116
  }
119
117
 
120
- // Returns the response RKObjectMapping
121
- + (RKObjectMapping *)responseMapping
118
+ + (NSString *)keyPath
122
119
  {
123
- RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Video class]];
124
- [mapping addAttributeMappingsFromDictionary:[self dictionaryForMappings]];
125
- return mapping;
120
+ return @"video";
126
121
  }
127
122
 
128
123
  @end
@@ -218,6 +213,10 @@ and here is a unit test that was generated in Models/VideoTest.m by LaneKit:
218
213
  create Classes/Controllers/LKResourceProvider.m
219
214
  create Classes/Controllers/ContentsProvider.h
220
215
  create Classes/Controllers/ContentsProvider.m
216
+
217
+ ### Create a new iOS app fully integrated with CocoaPods and RestKit.
218
+
219
+ $ lanekit new SportsFrames
221
220
 
222
221
  ### Sample App
223
222
  The SportsFrames app is a fully functional sample app using RestKit created to demonstrate the use of LaneKit in a real world app. It
@@ -67,7 +67,7 @@ module LaneKit
67
67
  end
68
68
 
69
69
  def source_paths
70
- [@@template_folder]
70
+ LaneKit.template_folders
71
71
  end
72
72
 
73
73
  def create_model_folders
@@ -47,7 +47,7 @@ module LaneKit
47
47
  end
48
48
 
49
49
  def source_paths
50
- [@@template_folder]
50
+ LaneKit.template_folders
51
51
  end
52
52
 
53
53
  def create_provider_folders
@@ -1,7 +1,6 @@
1
1
  class LaneKit::Generate < Thor
2
2
 
3
3
  @@lanekit_version = LaneKit::VERSION;
4
- @@template_folder = File.expand_path('../../template', __FILE__)
5
4
  @@generate_date = Date.today.to_s
6
5
 
7
6
  no_tasks do
@@ -0,0 +1,135 @@
1
+ require 'xcodeproj'
2
+
3
+ module LaneKit
4
+ class CLI < Thor
5
+
6
+ include Thor::Actions
7
+
8
+ desc "new APP_PATH [BUNDLE_ID]", "Create a new iOS app"
9
+ def new(app_path, bundle_id=nil)
10
+ app_path = app_path.strip
11
+ @app_path = app_path
12
+ @bundle_id = bundle_id
13
+
14
+ @app_name = LaneKit::derive_app_name(app_path)
15
+ validate_message = LaneKit.validate_app_name(@app_name)
16
+ if validate_message
17
+ puts "***error: #{validate_message}"
18
+ return
19
+ end
20
+
21
+ @app_path_full = File.expand_path app_path
22
+ if File.exists?(@app_path_full)
23
+ puts "Can't create a new LaneKit app in an existing folder: #{@app_path_full}"
24
+ return
25
+ end
26
+
27
+ if @bundle_id != nil
28
+ validate_message = LaneKit.validate_bundle_id(@bundle_id)
29
+ if validate_message
30
+ puts "***error: #{validate_message}"
31
+ return
32
+ end
33
+ end
34
+
35
+ if !LaneKit.gem_available?('cocoapods')
36
+ puts "The Ruby gem cocoapods is not installed. This gem is required by LaneKit.\nInstall command: gem install cocoapods"
37
+ return
38
+ end
39
+
40
+ @project_path = File.join @app_path_full, @app_name
41
+ @ios_template_name = "lanekit-ios-project"
42
+ @ios_version = '6.0'
43
+ @original_wd = Dir.pwd
44
+
45
+ self.create_project
46
+ self.change_filenames(@app_path_full, @app_name, @ios_template_name)
47
+ self.change_bundle_id(@bundle_id) if @bundle_id != nil
48
+ self.add_cocoapods
49
+ self.clean_workspace
50
+ end
51
+
52
+ no_tasks {
53
+ #def create_xcodeproj_project
54
+ # proj = Xcodeproj::Project.new(File.join(@app_path, "#{@app_name}.xcodeproj"))
55
+ # app_target = proj.new_target(:application, @app_name, :ios, proj.products_group)
56
+ # proj.save
57
+ #end
58
+
59
+ def clean_workspace
60
+ # Remove the extra project that CocoaPods added to the workspace
61
+ workspace_path = File.join(@app_path_full, "#{@app_name}.xcworkspace")
62
+ say_status :clean, workspace_path, :yellow
63
+ workspace = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
64
+ container = "container:#{@app_name}/#{@app_name}.xcodeproj"
65
+ if workspace.include?(container)
66
+ workspace.projpaths.delete(container)
67
+ workspace.save_as(workspace_path)
68
+ end
69
+ end
70
+
71
+ def change_bundle_id(bundle_id)
72
+ plistbuddy_path = '/usr/libexec/PlistBuddy'
73
+ plist_file = "#{@app_name}-Info.plist"
74
+ info_plist_path = File.join(@project_path, File.join("#{@app_name}", plist_file))
75
+ system("#{plistbuddy_path} -c \"Set :CFBundleIdentifier #{bundle_id}\" #{info_plist_path}")
76
+ end
77
+
78
+ def add_cocoapods
79
+ Dir.chdir(@project_path) do
80
+ puts "Installing CocoaPods for RestKit"
81
+ system "pod install"
82
+ end
83
+ end
84
+
85
+ def create_project
86
+ source = @ios_template_name
87
+ destination = @app_path
88
+ directory(source, destination)
89
+ end
90
+
91
+ def source_paths
92
+ LaneKit.template_folders
93
+ end
94
+
95
+ def change_filenames path, app_name, template_name
96
+
97
+ Dir.foreach(path) do |file|
98
+ if file == '..' || file == '.'
99
+ next
100
+ end
101
+
102
+ old_path = File.join path, file
103
+ new_path = old_path
104
+
105
+ if file.start_with?(template_name)
106
+ new_name = file.sub template_name, app_name
107
+
108
+ new_path = File.join path, new_name
109
+ FileUtils.mv old_path, new_path
110
+ say_status :rename, new_path, :yellow
111
+ end
112
+
113
+ if File.directory?(new_path)
114
+ change_filenames new_path, app_name, template_name
115
+ else
116
+
117
+ begin
118
+ string = IO.read(new_path)
119
+ string = string.gsub!(template_name, app_name)
120
+ if string != nil
121
+ IO.write(new_path, string)
122
+ say_status :update, new_path, :yellow
123
+ end
124
+
125
+ rescue
126
+ end
127
+ end
128
+
129
+ end
130
+ end
131
+
132
+
133
+ }
134
+ end
135
+ end
@@ -1,3 +1,3 @@
1
1
  module LaneKit
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/lanekit.rb CHANGED
@@ -9,6 +9,17 @@ module LaneKit
9
9
  @@objc_types = {
10
10
  "array" => "NSArray *"
11
11
  }
12
+ @template_folder = File.expand_path('../template', __FILE__)
13
+
14
+ def self.template_folders
15
+ [@template_folder]
16
+ end
17
+
18
+ # Returns an app name from a folder path. App names are lower case
19
+ # "Tracker" => "tracker", "~/Projects/Runner" => "runner"
20
+ def self.derive_app_name(app_path)
21
+ app_name = File.basename(app_path).to_s.downcase
22
+ end
12
23
 
13
24
  # Model names are lower case
14
25
  # "Car" => "car", "Bigbird" => "bigbird"
@@ -100,12 +111,37 @@ module LaneKit
100
111
  end
101
112
  assert
102
113
  end
114
+
115
+ def self.validate_app_name(app_name)
116
+ if app_name.length < 2
117
+ return "app name must be at least two characters long"
118
+ elsif app_name.include? " "
119
+ return "app name cannot include spaces"
120
+ end
121
+ return nil
122
+ end
123
+
124
+ def self.validate_bundle_id(bundle_id)
125
+ if bundle_id.length < 2
126
+ return "bundle id must be at least two characters long"
127
+ elsif bundle_id.include? " "
128
+ return "bundle id cannot include spaces"
129
+ end
130
+ return nil
131
+ end
132
+
133
+ def self.gem_available?(gemname)
134
+ if Gem::Specification.methods.include?(:find_all_by_name)
135
+ not Gem::Specification.find_all_by_name(gemname).empty?
136
+ else
137
+ Gem.available?(gemname)
138
+ end
139
+ end
103
140
 
104
141
  end
105
142
 
106
143
  module LaneKit
107
144
  class CLI < Thor
108
-
109
145
  script_name = File.basename($0)
110
146
  script_args = ARGV.join(' ')
111
147
 
@@ -119,15 +155,16 @@ module LaneKit
119
155
 
120
156
  map ["-v", "--version"] => :version
121
157
 
158
+ require 'lanekit/generate'
122
159
  desc "generate", "Invoke a code generator"
123
160
  long_desc <<-LONGDESC
124
161
  Invoke a code generator:\n
125
162
  -'model' that generates Objective-C code compatible with RestKit that includes unit tests\n
126
163
  -'provider' that generates Objective-C code compatible with RestKit
127
164
  LONGDESC
128
-
129
- require 'lanekit/generate'
130
165
  subcommand "generate", LaneKit::Generate
166
+
167
+ require 'lanekit/new'
131
168
 
132
169
  desc "version", "Display the LaneKit version"
133
170
  def version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lanekit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-13 00:00:00.000000000 Z
12
+ date: 2013-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cocoapods
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.24.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.24.0
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: thor
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +50,7 @@ dependencies:
34
50
  requirements:
35
51
  - - ~>
36
52
  - !ruby/object:Gem::Version
37
- version: 0.5.5
53
+ version: 0.10.0
38
54
  type: :runtime
39
55
  prerelease: false
40
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,9 +58,8 @@ dependencies:
42
58
  requirements:
43
59
  - - ~>
44
60
  - !ruby/object:Gem::Version
45
- version: 0.5.5
46
- description: an iOS Objective-C code generator for models and resource providers for
47
- integration with RestKit.
61
+ version: 0.10.0
62
+ description: an iOS Objective-C code generator for integration with RestKit.
48
63
  email:
49
64
  - larryaasen@gmail.com
50
65
  executables:
@@ -55,6 +70,7 @@ files:
55
70
  - lib/lanekit/generate/model.rb
56
71
  - lib/lanekit/generate/provider.rb
57
72
  - lib/lanekit/generate.rb
73
+ - lib/lanekit/new.rb
58
74
  - lib/lanekit/version.rb
59
75
  - lib/lanekit.rb
60
76
  - lib/template/model.h.erb
@@ -97,8 +113,8 @@ rubyforge_project:
97
113
  rubygems_version: 1.8.23
98
114
  signing_key:
99
115
  specification_version: 3
100
- summary: LaneKit is an iOS Objective-C code generator of models and resource providers
101
- for integration with RestKit. It includes support for unit testing with SenTestingKit
102
- including fixtures and tests. LaneKit is a command line app written in Ruby and
103
- packaged as a Ruby Gem.
116
+ summary: LaneKit is an iOS Objective-C code generator for integration with RestKit.
117
+ It generates models, resource providers, and full iOS apps with mimimal effort.
118
+ There is support for unit testing with SenTestingKit including fixtures and tests.
119
+ LaneKit is a command line app written in Ruby and packaged as a Ruby Gem.
104
120
  test_files: []