motion-objc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ .repl_history
3
+ build
4
+ resources/*.nib
5
+ resources/*.momd
6
+ resources/*.storyboardc
7
+ Gemfile.lock
8
+ pkg
9
+ *.gem
10
+ vendor/MotionObjC/MotionObjC.xcodeproj/project.pbxproj
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # RubyMotion Objective-C (motion-objc)
2
+
3
+ Include simple Objective-C files in your motion project, without the need of manually
4
+ create project file.
5
+
6
+ ## Installation
7
+
8
+ ```
9
+ gem install motion-objc
10
+ ```
11
+
12
+ ## Setup
13
+
14
+ Add following lines to your project ```Rakefile```
15
+
16
+ ```ruby
17
+ require 'rubygems'
18
+ require 'motion-objc'
19
+ ```
20
+
21
+ Add Objective-C files to your project. e.g. Create a objc folder and add *.h/*.m
22
+ files there.
23
+
24
+ Tell motion-objc where your Objective-C files located using ```app.objc_files```
25
+
26
+ ```ruby
27
+ Motion::Project::App.setup do |app|
28
+ app.name = 'MotionObjCTest'
29
+ app.identifier = 'hk.ignition.objc'
30
+ app.version = '1.0.0'
31
+ app.objc_files = Dir.glob("objc/**/*.*")
32
+ end
33
+ ```
34
+
35
+ ## How it works?
36
+
37
+ It generate a XCode project with static library target with all your specified
38
+ Objective-C files, and include it in your RubyMotion project.
39
+
40
+ motion-objc is designed for adding small snippets written in Objective-C to RubyMotion
41
+ project. If you need to include more complex code base, you should create a
42
+ [CocoaPods Spec](https://github.com/CocoaPods/CocoaPods) instead.
43
+
44
+ ## License
45
+
46
+ Copyright 2012, Francis Chong, Ignition Soft.
47
+
48
+ This project is released in MIT license.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ $:.unshift("/Library/RubyMotion/lib")
3
+ require 'motion/project'
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+ require 'xcodeproj'
7
+ require 'motion-objc'
8
+
9
+ Motion::Project::App.setup do |app|
10
+ app.name = 'MotionObjCTest'
11
+ app.identifier = 'hk.ignition.objc'
12
+ app.version = '1.0.0'
13
+ app.objc_files = Dir.glob("objc/**/*.*")
14
+ end
@@ -0,0 +1,5 @@
1
+ class AppDelegate
2
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
3
+ true
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Motion
2
+ module Project
3
+ module ObjC
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,88 @@
1
+ require "motion/project/objc/version"
2
+ require "fileutils"
3
+
4
+ unless defined?(Motion::Project::Config)
5
+ raise "This file must be required within a RubyMotion project Rakefile."
6
+ end
7
+
8
+ module Motion::Project
9
+ class Config
10
+ # variables :objc_files should work, but it isnt
11
+ attr_accessor :objc_files
12
+ VARS << 'objc_files'
13
+ end
14
+
15
+ class << App
16
+ def setup_with_motion_objc
17
+ setup_without_motion_objc do |app|
18
+ yield app
19
+
20
+ if app.objc_files && app.objc_files != []
21
+ generator = LibGenerator.new(app.objc_files)
22
+ generator.vendor(app)
23
+ end
24
+ end
25
+ end
26
+
27
+ alias setup_without_motion_objc setup
28
+ alias setup setup_with_motion_objc
29
+ end
30
+
31
+ class LibGenerator
32
+ attr_accessor :project_path
33
+ attr_accessor :files
34
+
35
+ def initialize(files=[])
36
+ @files = files
37
+ end
38
+
39
+ def vendor(app)
40
+ generate(app)
41
+ app.vendor_project @project_path, :xcode,
42
+ :target => 'MotionObjC',
43
+ :products => ['libMotionObjC.a']
44
+ end
45
+
46
+ private
47
+
48
+ def headers_path
49
+ @files.select {|f| f =~ /\.h$/}.collect{|f| File.dirname(f) }.uniq
50
+ end
51
+
52
+ # OTHER_LDFLAGS for the library
53
+ def ld_flags(app)
54
+ flags = []
55
+ flags << '-ObjC'
56
+ flags += app.frameworks.collect{|f| "-framework #{f}"}
57
+ flags.join(" ")
58
+ end
59
+
60
+ # Generate project file
61
+ def generate(app)
62
+ @project_path = Pathname.new(File.expand_path(app.project_dir + '/vendor/MotionObjC'))
63
+ FileUtils.mkdir_p(@project_path)
64
+
65
+ # basic build config
66
+ @config = {
67
+ 'SDKROOT' => 'iphoneos',
68
+ 'ARCHS' => "$(ARCHS_STANDARD_32_BIT)",
69
+ 'PUBLIC_HEADERS_FOLDER_PATH' => "$(TARGET_NAME)",
70
+ 'IPHONEOS_DEPLOYMENT_TARGET' => app.deployment_target || "5.1",
71
+ 'HEADER_SEARCH_PATHS' => headers_path,
72
+ 'OTHER_LDFLAGS' => ld_flags(app)
73
+ }
74
+
75
+ @project = Xcodeproj::Project.new
76
+ @target = @project.targets.new_static_library('MotionObjC')
77
+ @target.buildConfigurations.each do |config|
78
+ config.buildSettings.merge!(@config)
79
+ end
80
+ @files.each do |file|
81
+ full_path = File.expand_path(app.project_dir + '/' + file)
82
+ @target.add_source_file(Pathname.new(full_path).relative_path_from(@project_path))
83
+ end
84
+
85
+ @project.save_as(File.join(@project_path, 'MotionObjC.xcodeproj'))
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../lib/motion/project/objc/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Francis Chong"]
5
+ gem.email = ["francis@ignition.hk"]
6
+ gem.description = "Simply include Objective-C files in your RubyMotion projects"
7
+ gem.summary = "Simply include Objective-C files in your RubyMotion projects"
8
+ gem.homepage = "https://github.com/siuying/moiton-objc"
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ gem.name = "motion-objc"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = Motion::Project::ObjC::VERSION
15
+ gem.add_dependency 'xcodeproj'
16
+ end
@@ -0,0 +1,18 @@
1
+ //
2
+ // NSData+MD5Digest.h
3
+ // NSData+MD5Digest
4
+ //
5
+ // Created by Francis Chong on 12年6月5日.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+
10
+ @interface NSData (MD5Digest)
11
+
12
+ +(NSData *)MD5Digest:(NSData *)input;
13
+ -(NSData *)MD5Digest;
14
+
15
+ +(NSString *)MD5HexDigest:(NSData *)input;
16
+ -(NSString *)MD5HexDigest;
17
+
18
+ @end
@@ -0,0 +1,39 @@
1
+ //
2
+ // NSData+MD5Digest.m
3
+ // NSData+MD5Digest
4
+ //
5
+ // Created by Francis Chong on 12年6月5日.
6
+ //
7
+
8
+ #import "NSData+MD5Digest.h"
9
+ #import <CommonCrypto/CommonDigest.h>
10
+
11
+ @implementation NSData (MD5)
12
+
13
+ +(NSData *)MD5Digest:(NSData *)input {
14
+ unsigned char result[CC_MD5_DIGEST_LENGTH];
15
+
16
+ CC_MD5(input.bytes, input.length, result);
17
+ return [[NSData alloc] initWithBytes:result length:CC_MD5_DIGEST_LENGTH];
18
+ }
19
+
20
+ -(NSData *)MD5Digest {
21
+ return [NSData MD5Digest:self];
22
+ }
23
+
24
+ +(NSString *)MD5HexDigest:(NSData *)input {
25
+ unsigned char result[CC_MD5_DIGEST_LENGTH];
26
+
27
+ CC_MD5(input.bytes, input.length, result);
28
+ NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
29
+ for (int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
30
+ [ret appendFormat:@"%02x",result[i]];
31
+ }
32
+ return ret;
33
+ }
34
+
35
+ -(NSString *)MD5HexDigest {
36
+ return [NSData MD5HexDigest:self];
37
+ }
38
+
39
+ @end
data/spec/lib_spec.rb ADDED
@@ -0,0 +1,5 @@
1
+ describe "Using library with motion-objc" do
2
+ it "include obj-c class" do
3
+ "Hello World".to_data.MD5HexDigest.should == "b10a8db164e0754105b7a99be72e3fe5"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-objc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Francis Chong
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: xcodeproj
16
+ requirement: &2153979520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2153979520
25
+ description: Simply include Objective-C files in your RubyMotion projects
26
+ email:
27
+ - francis@ignition.hk
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - app/app_delegate.rb
37
+ - lib/motion-objc.rb
38
+ - lib/motion/project/objc/version.rb
39
+ - motion-objc.gemspec
40
+ - objc/NSData+MD5Digest.h
41
+ - objc/NSData+MD5Digest.m
42
+ - spec/lib_spec.rb
43
+ - vendor/MotionObjC/build-iPhoneSimulator/libMotionObjC.a
44
+ homepage: https://github.com/siuying/moiton-objc
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ segments:
57
+ - 0
58
+ hash: -1849511930686443899
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ segments:
66
+ - 0
67
+ hash: -1849511930686443899
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.10
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Simply include Objective-C files in your RubyMotion projects
74
+ test_files:
75
+ - spec/lib_spec.rb