appjam 0.1.8.7 → 0.1.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/README.md +9 -1
  2. data/lib/appjam/generators/help.rb +1 -1
  3. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.pbxproj +356 -0
  4. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  5. data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.h.tt +3 -3
  6. data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.m.tt +5 -5
  7. data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Info.plist +1 -1
  8. data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Prefix.pch.tt +1 -1
  9. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/Toast/Toast+UIView.h +51 -0
  10. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/Toast/Toast+UIView.m +315 -0
  11. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/RaptureXML/RXMLElement.h +97 -0
  12. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/RaptureXML/RXMLElement.m +450 -0
  13. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Objective-C-HMTL-Parser/HTMLNode.h +111 -0
  14. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Objective-C-HMTL-Parser/HTMLNode.m +412 -0
  15. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Objective-C-HMTL-Parser/HTMLParser.h +37 -0
  16. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Objective-C-HMTL-Parser/HTMLParser.m +130 -0
  17. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSArray+ObjectiveSugar.h +39 -0
  18. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSArray+ObjectiveSugar.m +145 -0
  19. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSDictionary+ObjectiveSugar.h +18 -0
  20. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSDictionary+ObjectiveSugar.m +42 -0
  21. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSMutableArray+ObjectiveSugar.h +18 -0
  22. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSMutableArray+ObjectiveSugar.m +37 -0
  23. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSNumber+ObjectiveSugar.h +45 -0
  24. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSNumber+ObjectiveSugar.m +117 -0
  25. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSSet+ObjectiveSugar.h +21 -0
  26. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSSet+ObjectiveSugar.m +50 -0
  27. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSString+ObjectiveSugar.h +17 -0
  28. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/NSString+ObjectiveSugar.m +43 -0
  29. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveSugar/ObjectiveSugar.h +10 -0
  30. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SSKeychain/SSKeychain.h +160 -0
  31. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SSKeychain/SSKeychain.m +79 -0
  32. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SSKeychain/SSKeychainQuery.h +80 -0
  33. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SSKeychain/SSKeychainQuery.m +228 -0
  34. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SecureUDID/SecureUDID.h +75 -0
  35. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SecureUDID/SecureUDID.m +679 -0
  36. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Helpers/NSString+Versioning.h +41 -0
  37. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Helpers/NSString+Versioning.m +71 -0
  38. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Helpers/SS+Functions.h +38 -0
  39. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Helpers/SS+Functions.m +122 -0
  40. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Helpers/SS+System.h +41 -0
  41. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Helpers/SS+System.m +132 -0
  42. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Helpers/SSArguments.h +156 -0
  43. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSArray+JavaScript.h +46 -0
  44. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSArray+JavaScript.m +135 -0
  45. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSDate+JavaScript.h +42 -0
  46. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSDate+JavaScript.m +90 -0
  47. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSDictionary+JavaScript.h +38 -0
  48. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSDictionary+JavaScript.m +38 -0
  49. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSMutableArray+JavaScript.h +46 -0
  50. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSMutableArray+JavaScript.m +131 -0
  51. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSMutableDictionary+JavaScript.h +36 -0
  52. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSMutableDictionary+JavaScript.m +42 -0
  53. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSMutableString+JavaScript.h +36 -0
  54. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSMutableString+JavaScript.m +42 -0
  55. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSNumber+JavaScript.h +36 -0
  56. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSNumber+JavaScript.m +44 -0
  57. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSObject+JavaScript.h +50 -0
  58. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSObject+JavaScript.m +114 -0
  59. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSString+JavaScript.h +43 -0
  60. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/NSString+JavaScript.m +94 -0
  61. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/SS+JavaScript.h +52 -0
  62. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/SS+JavaScript.m +168 -0
  63. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/SS+Types.h +42 -0
  64. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/JavaScript/SS+Types.m +42 -0
  65. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/NSDictionary+NamedProperties.h +41 -0
  66. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/NSDictionary+NamedProperties.m +271 -0
  67. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/SS.h +36 -0
  68. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/SS.m +38 -0
  69. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/SubjectiveScript.h +67 -0
  70. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/SubjectiveScript.m +30 -0
  71. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSArray+SS.h +58 -0
  72. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSArray+SS.m +152 -0
  73. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSDate+SS.h +37 -0
  74. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSDate+SS.m +47 -0
  75. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSDictionary+SS.h +45 -0
  76. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSDictionary+SS.m +61 -0
  77. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSMutableArray+SS.h +43 -0
  78. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSMutableArray+SS.m +83 -0
  79. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSMutableDictionary+SS.h +47 -0
  80. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSMutableDictionary+SS.m +100 -0
  81. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSMutableString+SS.h +42 -0
  82. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSMutableString+SS.m +70 -0
  83. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSNumber+SS.h +51 -0
  84. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSNumber+SS.m +86 -0
  85. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSObject+SS.h +54 -0
  86. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSObject+SS.m +153 -0
  87. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSString+SS.h +46 -0
  88. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/NSString+SS.m +91 -0
  89. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/SubjectiveScript/Types/SSTypes.h +67 -0
  90. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests-Info.plist +1 -1
  91. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.h.tt +5 -5
  92. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.m.tt +7 -7
  93. data/lib/appjam/version.rb +1 -1
  94. metadata +84 -3
@@ -0,0 +1,44 @@
1
+ //
2
+ // NSNumber+JavaScript.m
3
+ // SubjectiveScript.m
4
+ //
5
+ // Created by Kevin Malakoff on 7/29/12.
6
+ // Copyright (c) 2012 Kevin Malakoff. All rights reserved.
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person
9
+ // obtaining a copy of this software and associated documentation
10
+ // files (the "Software"), to deal in the Software without
11
+ // restriction, including without limitation the rights to use,
12
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the
14
+ // Software is furnished to do so, subject to the following
15
+ // conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be
18
+ // included in all copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
+ // OTHER DEALINGS IN THE SOFTWARE.
28
+ //
29
+
30
+ #import "NSNumber+JavaScript.h"
31
+ #import "NSNumber+SS.h"
32
+
33
+ @implementation NSNumber (JavaScript)
34
+
35
+ - (NSS*(^)())toString {
36
+ return ^{
37
+ if (self.isBoolean())
38
+ return self.boolValue ? @"true" : @"false";
39
+ else
40
+ return self.description;
41
+ };
42
+ }
43
+
44
+ @end
@@ -0,0 +1,50 @@
1
+ //
2
+ // NSObject+JavaScript.h
3
+ // SubjectiveScript.m
4
+ //
5
+ // Created by Kevin Malakoff on 7/29/12.
6
+ // Copyright (c) 2012 Kevin Malakoff. All rights reserved.
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person
9
+ // obtaining a copy of this software and associated documentation
10
+ // files (the "Software"), to deal in the Software without
11
+ // restriction, including without limitation the rights to use,
12
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the
14
+ // Software is furnished to do so, subject to the following
15
+ // conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be
18
+ // included in all copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
+ // OTHER DEALINGS IN THE SOFTWARE.
28
+ //
29
+
30
+ #import "SSTypes.h"
31
+
32
+ @interface NSObject (JavaScript)
33
+
34
+ - (B(^)(Class class))instanceof;
35
+ - (NSS*(^)())toString;
36
+
37
+ // array
38
+ - (UI)length;
39
+ - (S*(^)(NSS* separator))join;
40
+ - (A*(^)(id value))push;
41
+
42
+ // object
43
+ - (B(^)(id key))hasOwnProperty;
44
+ - (B(^)(NSO* obj))in;
45
+
46
+ // string
47
+ - (NSS*(^)(NSS* string))add;
48
+ - (S*(^)(NSS* string))append;
49
+
50
+ @end
@@ -0,0 +1,114 @@
1
+ //
2
+ // NSObject+JavaScript.m
3
+ // SubjectiveScript.m
4
+ //
5
+ // Created by Kevin Malakoff on 7/29/12.
6
+ // Copyright (c) 2012 Kevin Malakoff. All rights reserved.
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person
9
+ // obtaining a copy of this software and associated documentation
10
+ // files (the "Software"), to deal in the Software without
11
+ // restriction, including without limitation the rights to use,
12
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the
14
+ // Software is furnished to do so, subject to the following
15
+ // conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be
18
+ // included in all copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
+ // OTHER DEALINGS IN THE SOFTWARE.
28
+ //
29
+
30
+ #import "NSObject+JavaScript.h"
31
+ #import "NSObject+SS.h"
32
+ #import "SS+Types.h"
33
+
34
+ @implementation NSObject (JavaScript)
35
+
36
+ - (B(^)(Class class))instanceof {
37
+ return ^(Class class) {
38
+ return [self isKindOfClass:class];
39
+ };
40
+ }
41
+ - (NSS*(^)())toString
42
+ {
43
+ return ^{
44
+ if (SS.isNull(self)) return @"";
45
+ return self.description;
46
+ };
47
+ }
48
+
49
+ // array
50
+ - (UI)length
51
+ {
52
+ // base class can be triggered by KeyValueCoding
53
+ if (SS.isArray(self)) return ((NSA*)self).count;
54
+ if (SS.isString(self)) return ((NSS*)self).length;
55
+ return 0;
56
+ }
57
+ - (S*(^)(NSS* separator))join
58
+ {
59
+ #ifdef DEBUG
60
+ NSAssert(nil, @"join not implemented for this type");
61
+ #endif
62
+
63
+ return nil;
64
+ }
65
+ - (A*(^)(id value))push
66
+ {
67
+ return ^(NSO* obj) {
68
+ #ifdef DEBUG
69
+ NSAssert(nil, @"push not implemented for this type");
70
+ #endif
71
+ return A.new;
72
+ };
73
+ }
74
+
75
+ // object
76
+ - (B(^)(id key))hasOwnProperty
77
+ {
78
+ return ^B(id key) {
79
+ #ifdef DEBUG
80
+ NSAssert(nil, @"hasOwnProperty not implemented for this type");
81
+ #endif
82
+ return false;
83
+ };
84
+ }
85
+
86
+ - (B(^)(NSO* obj))in
87
+ {
88
+ return ^B(NSO* obj) {
89
+ return obj.get(self) != nil;
90
+ };
91
+ }
92
+
93
+ // string
94
+ - (NSS*(^)(NSS* string))add
95
+ {
96
+ return ^(NSS* string) {
97
+ #ifdef DEBUG
98
+ NSAssert(nil, @"add not implemented for this type");
99
+ #endif
100
+ return string;
101
+ };
102
+ }
103
+
104
+ - (S*(^)(NSS* string))append
105
+ {
106
+ return ^(NSS* string) {
107
+ #ifdef DEBUG
108
+ NSAssert(nil, @"append not implemented for this type");
109
+ #endif
110
+ return string.mutableCopy;
111
+ };
112
+ }
113
+
114
+ @end
@@ -0,0 +1,43 @@
1
+ //
2
+ // NSString+JavaScript.h
3
+ // SubjectiveScript.m
4
+ //
5
+ // Created by Kevin Malakoff on 7/29/12.
6
+ // Copyright (c) 2012 Kevin Malakoff. All rights reserved.
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person
9
+ // obtaining a copy of this software and associated documentation
10
+ // files (the "Software"), to deal in the Software without
11
+ // restriction, including without limitation the rights to use,
12
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the
14
+ // Software is furnished to do so, subject to the following
15
+ // conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be
18
+ // included in all copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
+ // OTHER DEALINGS IN THE SOFTWARE.
28
+ //
29
+
30
+ #import "SSTypes.h"
31
+
32
+ @interface NSString (JavaScript)
33
+
34
+ - (NSS*(^)())toString;
35
+
36
+ - (NSA*(^)(NSS* separator))split;
37
+ - (S*(^)(NSS* value))add;
38
+
39
+ // function calling of form @"functionName".call(object, arg1, nil) and @"functionName".apply(object, arguments)
40
+ - (id(^)(id target, id arg1, ... /* NIL_TERMINATED*/))call;
41
+ - (id(^)(id target, NSA* arguments))apply;
42
+
43
+ @end
@@ -0,0 +1,94 @@
1
+ //
2
+ // NSString+JavaScript.m
3
+ // SubjectiveScript.m
4
+ //
5
+ // Created by Kevin Malakoff on 7/29/12.
6
+ // Copyright (c) 2012 Kevin Malakoff. All rights reserved.
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person
9
+ // obtaining a copy of this software and associated documentation
10
+ // files (the "Software"), to deal in the Software without
11
+ // restriction, including without limitation the rights to use,
12
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the
14
+ // Software is furnished to do so, subject to the following
15
+ // conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be
18
+ // included in all copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
+ // OTHER DEALINGS IN THE SOFTWARE.
28
+ //
29
+
30
+ #import "NSString+JavaScript.h"
31
+ #import "NSMutableArray+JavaScript.h"
32
+ #import "SSArguments.h"
33
+ #import "SS+Functions.h"
34
+
35
+ @implementation NSString (JavaScript)
36
+
37
+ - (NSS*(^)())toString { return ^{ return self; }; }
38
+
39
+ - (NSA*(^)(NSS* separator))split
40
+ {
41
+ return ^NSA*(NSS* separator) {
42
+ // split on nothing means get the characters
43
+ if (!separator || !separator.length)
44
+ {
45
+ UI count = self.length;
46
+ A *characters = A.newC(count);
47
+ for (I index=0; index<count; index++) {
48
+ unichar character = [self characterAtIndex:index];
49
+ characters.push([NSString stringWithCharacters:&character length:1]);
50
+ }
51
+ return characters;
52
+ }
53
+ else
54
+ return [self componentsSeparatedByString:separator];
55
+ };
56
+ }
57
+ - (S*(^)(NSS* value))add
58
+ {
59
+ return ^(NSS* value) {
60
+ S* result = self.mutableCopy;
61
+ [result appendString:value];
62
+ return result;
63
+ };
64
+ }
65
+
66
+ - (id(^)(id target, id arg1, ... /* NIL_TERMINATED*/))call
67
+ {
68
+ return ^id(id target, id arg1, ... /* NIL_TERMINATED*/) {
69
+ ARGS_AO(arguments, arg1);
70
+
71
+ id scriptFunction = SS.resolveFunction(target, self);
72
+ if (!scriptFunction) {
73
+ NSLog(@"function '%@' did not exist for call", self);
74
+ return nil;
75
+ }
76
+
77
+ return SS.callFunction(scriptFunction, arguments);
78
+ };
79
+ }
80
+
81
+ - (id(^)(id target, NSA* arguments))apply
82
+ {
83
+ return ^id(id target, NSA* arguments) {
84
+ id scriptFunction = SS.resolveFunction(target, self);
85
+ if (!scriptFunction) {
86
+ NSLog(@"function '%@' did not exist for apply", self);
87
+ return nil;
88
+ }
89
+
90
+ return SS.callFunction(scriptFunction, arguments);
91
+ };
92
+ }
93
+
94
+ @end
@@ -0,0 +1,52 @@
1
+ //
2
+ // SS+JavaScript.h
3
+ // SubjectiveScript.m
4
+ //
5
+ // Created by Kevin Malakoff on 7/22/12.
6
+ // Copyright (c) 2012 Kevin Malakoff. All rights reserved.
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person
9
+ // obtaining a copy of this software and associated documentation
10
+ // files (the "Software"), to deal in the Software without
11
+ // restriction, including without limitation the rights to use,
12
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the
14
+ // Software is furnished to do so, subject to the following
15
+ // conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be
18
+ // included in all copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
+ // OTHER DEALINGS IN THE SOFTWARE.
28
+ //
29
+
30
+ #import "SS.h"
31
+ #import "SS+System.h"
32
+
33
+ @interface SS (JavaScript)
34
+
35
+ // JSON
36
+ + (NSS*(^)(NSO* obj))stringify;
37
+
38
+ // functions
39
+ + (id(^)(id function, id arg1, ... /* NIL_TERMINATED*/))call;
40
+ + (id(^)(id function, NSA* arguments))apply;
41
+
42
+ // global functions
43
+ + (N*(^)(NSS* string))parseInt;
44
+ + (const NSS*(^)(id obj))typeof_;
45
+ + (void(^)(NSO* message))alert;
46
+
47
+ // timeouts
48
+ + (SSTimeout*(^)(SSTaskIdBlock block, I waitNS))setTimeout;
49
+ + (SSTimeout*(^)(SSTaskIdBlock block, I waitNS))setTimeoutBackground;
50
+ + (void(^)(SSTimeout* timeout))clearTimeout;
51
+
52
+ @end
@@ -0,0 +1,168 @@
1
+ //
2
+ // SS+JavaScript.m
3
+ // SubjectiveScript.m
4
+ //
5
+ // Created by Kevin Malakoff on 7/22/12.
6
+ // Copyright (c) 2012 Kevin Malakoff. All rights reserved.
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person
9
+ // obtaining a copy of this software and associated documentation
10
+ // files (the "Software"), to deal in the Software without
11
+ // restriction, including without limitation the rights to use,
12
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the
14
+ // Software is furnished to do so, subject to the following
15
+ // conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be
18
+ // included in all copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
+ // OTHER DEALINGS IN THE SOFTWARE.
28
+ //
29
+
30
+ #import "SS+JavaScript.h"
31
+ #import "NSObject+JavaScript.h"
32
+ #import "NSNumber+SS.h"
33
+ #import "NSMutableString+SS.h"
34
+ #import "SS+Functions.h"
35
+ #import "SS+Types.h"
36
+ #import "SSArguments.h"
37
+
38
+ #import "TargetConditionals.h"
39
+ #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
40
+ #import <UIKit/UIKit.h>
41
+ #elif TARGET_OS_MAC
42
+ #import <Cocoa/Cocoa.h>
43
+ #endif
44
+
45
+ const NSS* SSJSTypeOfObject = @"object";
46
+ const NSS* SSJSTypeOfString = @"string";
47
+ const NSS* SSJSTypeOfNumber = @"number";
48
+ const NSS* SSJSTypeOfBoolean = @"boolean";
49
+
50
+ @implementation SS (JavaScript)
51
+
52
+ // JSON
53
+ + (NSS*(^)(NSO* obj))stringify
54
+ {
55
+ return ^NSS*(NSO* obj) {
56
+ if (SS.isNull(obj))
57
+ return @"null";
58
+ if (SS.isString(obj))
59
+ return [NSString stringWithFormat:@"\"%@\"", obj];
60
+ if (SS.isObject(obj)) {
61
+ NSD* dictionary = (NSD*)obj;
62
+ __block S* result = S.newS(@"{");
63
+
64
+ [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
65
+ [result appendString:self.stringify(key)];
66
+ [result appendString:@":"];
67
+ [result appendString:self.stringify(obj)];
68
+ }];
69
+
70
+ [result appendString:@"}"];
71
+ return result;
72
+ }
73
+ if (SS.isArray(obj)) {
74
+ NSA* array = (NSA*)obj;
75
+ __block S* result = S.newS(@"[");
76
+ BOOL writeSeparator = NO;
77
+
78
+ for(NSO* item in array) {
79
+ if (writeSeparator)
80
+ [result appendString:@","];
81
+ [result appendString:self.stringify(item)];
82
+ writeSeparator = YES;
83
+ };
84
+
85
+ [result appendString:@"]"];
86
+ return result;
87
+ }
88
+
89
+ return obj.toString();
90
+ };
91
+ }
92
+
93
+ // functions
94
+ + (id(^)(id function, id arg1, ... /* NIL_TERMINATED*/))call
95
+ {
96
+ return ^id(id function, id arg1, ... /* NIL_TERMINATED*/) {
97
+ ARGS_AO(arguments, arg1);
98
+ return SS.callFunction(function, arguments);
99
+ };
100
+ }
101
+
102
+ + (id(^)(id function, NSA* arguments))apply
103
+ {
104
+ return ^id(id function, NSA* arguments) {
105
+ return SS.callFunction(function, arguments);
106
+ };
107
+ }
108
+
109
+
110
+ // global functions
111
+ + (N*(^)(NSS* string))parseInt
112
+ {
113
+ return ^N*(NSS* string) {
114
+ NSScanner* scan = [NSScanner scannerWithString:string];
115
+ I result;
116
+ if([scan scanInteger:&result] && [scan isAtEnd])
117
+ return N.I(result);
118
+ return nil;
119
+ };
120
+ }
121
+
122
+ + (const NSS*(^)(id obj))typeof_
123
+ {
124
+ return ^const NSS*(id obj) {
125
+ if (SS.isArray(obj) || SS.isObject(obj) || SS.isDate(obj)) return SSJSTypeOfObject;
126
+ if (SS.isString(obj)) return SSJSTypeOfString;
127
+ if (SS.isNumber(obj)) return ((N*)obj).isBoolean() ? SSJSTypeOfBoolean : SSJSTypeOfNumber;
128
+ if (SS.isNumber(obj)) return ((N*)obj).isBoolean() ? SSJSTypeOfBoolean : SSJSTypeOfNumber;
129
+
130
+ NSLog(@"unrecognized type for typeof_");
131
+ return @"unknown type";
132
+ };
133
+ }
134
+
135
+ + (void(^)(NSO* message))alert
136
+ {
137
+ return ^(NSO* message) {
138
+ #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
139
+ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"alert" message:message.toString() delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
140
+ [alertView show];
141
+ #elif TARGET_OS_MAC
142
+ NSAlert *alert = [NSAlert alertWithMessageText:@"alert" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", message.toString()];
143
+ [alert beginSheetModalForWindow:NSApplication.sharedApplication.mainWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
144
+ #endif
145
+ };
146
+ }
147
+
148
+ // timeouts
149
+ + (SSTimeout*(^)(SSTaskIdBlock block, I waitNS))setTimeout
150
+ {
151
+ return ^(SSTaskIdBlock block, I waitNS) {
152
+ return SS.addTask(block, waitNS, false);
153
+ };
154
+ }
155
+ + (SSTimeout*(^)(SSTaskIdBlock block, I waitNS))setTimeoutBackground
156
+ {
157
+ return ^(SSTaskIdBlock block, I waitNS) {
158
+ return SS.addTask(block, waitNS, true);
159
+ };
160
+ }
161
+
162
+ + (void(^)(SSTimeout* timeout))clearTimeout
163
+ {
164
+ return ^(SSTimeout* timeout) {
165
+ return SS.stopTask(timeout);
166
+ };
167
+ }
168
+ @end