├── moo_iphone.png ├── moo_sketch.png ├── moo_storyboard.png ├── pathExporter.sketchplugin └── Contents │ └── Sketch │ ├── manifest.json │ ├── library.cocoascript │ └── script.cocoascript ├── LICENSE ├── README.md └── moo.swift /moo_iphone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Charimon/iosViews/HEAD/moo_iphone.png -------------------------------------------------------------------------------- /moo_sketch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Charimon/iosViews/HEAD/moo_sketch.png -------------------------------------------------------------------------------- /moo_storyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Charimon/iosViews/HEAD/moo_storyboard.png -------------------------------------------------------------------------------- /pathExporter.sketchplugin/Contents/Sketch/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "author" : "Charimon", 3 | "commands" : [ 4 | { 5 | "script" : "script.cocoascript", 6 | "handler" : "onRun", 7 | "shortcut" : "ctrl shift c", 8 | "name" : "Copy to UIView", 9 | "identifier" : "pathExporter" 10 | }, 11 | { 12 | "script" : "script.cocoascript", 13 | "handler" : "onSave", 14 | "shortcut" : "ctrl shift s", 15 | "name" : "Save to UIView", 16 | "identifier" : "pathSaver" 17 | } 18 | ], 19 | "menu": { 20 | "items": [ 21 | "pathExporter", 22 | "pathSaver" 23 | ] 24 | }, 25 | "identifier" : "com.charimon.sketch.pathExporter", 26 | "version" : "2", 27 | "description" : "A way to export ios Shapes to swift Path code", 28 | "authorEmail" : "", 29 | "name" : "iOS Path Exporter" 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Charimon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /pathExporter.sketchplugin/Contents/Sketch/library.cocoascript: -------------------------------------------------------------------------------- 1 | String.prototype.repeat = function( num ) { 2 | return new Array( num + 1 ).join( this ); 3 | } 4 | String.prototype.replaceAll = function(search, replace){ 5 | if(!search || !replace){return this;} 6 | return this.replace(new RegExp('[' + search + ']', 'g'), replace); 7 | }; 8 | 9 | var Lib = { 10 | alert: function(message) { 11 | var app = [NSApplication sharedApplication]; 12 | 13 | [app displayDialog:message]; 14 | }, 15 | 16 | isArray: function(anything) { 17 | if( Object.prototype.toString.call( anything ) === '[object Array]' ) { 18 | return true 19 | } 20 | return false 21 | }, 22 | //rectangle, circle, vector, etc 23 | isShape: function(item) {return [item isMemberOfClass:[MSShapeGroup class]]; }, 24 | 25 | //normal sketch group 26 | isGroup: function(item) {return [item isMemberOfClass:[MSLayerGroup class]]; }, 27 | 28 | isArtboard: function(item) { return [item isMemberOfClass:[MSArtboardGroup class]]; }, 29 | 30 | paste: function(value) { 31 | var pasteBoard = [NSPasteboard generalPasteboard]; 32 | [pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; 33 | [pasteBoard setString:value forType: NSStringPboardType]; 34 | }, 35 | 36 | save: function(name, value) { 37 | var panel = [NSSavePanel savePanel]; 38 | 39 | [panel setMessage:"Where do you want to place the class?"]; 40 | [panel setRequiredFileType: "swift"]; 41 | [panel setCanCreateDirectories: true]; 42 | if (name != null) { 43 | [panel setNameFieldStringValue: name]; 44 | } 45 | 46 | if ([panel runModal] == NSOKButton) { 47 | var filePath = [panel filename]; 48 | var stringValue = [NSString stringWithFormat: @"%@", value]; 49 | 50 | [stringValue writeToFile: filePath atomically: true encoding: NSUTF8StringEncoding error: null]; 51 | } 52 | }, 53 | 54 | toFixed: function(number, precision) { 55 | var power = Math.pow(10, precision || 0); 56 | return String(Math.round(number * power)/power); 57 | } 58 | } 59 | 60 | var Swift = { 61 | safeName: function(name) { return name.replaceAll(" ", "_") }, 62 | 63 | wrapInFrameMethod: function(array, methodName) { 64 | return ["\tfunc " + methodName + "(bounds: CGRect) -> CGPath {", array, "\t}\n"] 65 | }, 66 | 67 | wrapInFrameMethodNoReturn: function(array, methodName) { 68 | return ["\tfunc " + methodName + "(bounds: CGRect) {", array, "\t}"] 69 | }, 70 | 71 | wrapInLazyVariable: function(name, array, type) { 72 | if(type == null) type = "CAShapeLayer" 73 | return ["\tlazy var "+name+": " + type + " = {", array, "\t}()"] 74 | }, 75 | 76 | _flattenArray: function(acc, value, index) { 77 | if(Lib.isArray(value)) { 78 | for(var i=0; i